{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.arkz.ai/protocol/v0/record.schema.json",
  "title": "ARK Record v0",
  "description": "One piece of a person in an ARK. Authored by DotWin. The same shape is read from an ARK and proposed into one. Fields marked readOnly are assigned by ARKZ and ignored on a proposal.",
  "type": "object",
  "required": [
    "arp",
    "ark",
    "facet",
    "kind",
    "authorship",
    "content"
  ],
  "properties": {
    "arp": {
      "description": "Protocol version.",
      "const": "0"
    },
    "id": {
      "description": "Record id, assigned by ARKZ. Absent on a proposal.",
      "type": "string",
      "pattern": "^rec_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
      "readOnly": true
    },
    "ref": {
      "description": "Record reference, assigned by ARKZ: <table>:<uuid>, or <table>:<uuid>:<kind> when one row gives several kinds. Either id or ref names a record.",
      "type": "string",
      "pattern": "^[a-z0-9_]+:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(:[a-z_]+)?$",
      "readOnly": true
    },
    "ark": {
      "description": "The ARK this record belongs to.",
      "type": "string",
      "pattern": "^ark:arkz:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    },
    "facet": {
      "description": "A region of the person.",
      "enum": [
        "identity",
        "belief_value",
        "knowledge",
        "framework",
        "position_decision",
        "experience_story",
        "preference_boundary",
        "voice",
        "likeness",
        "behavior_execution",
        "relationship",
        "provenance_consent",
        "disposition",
        "humor",
        "mannerism",
        "body_of_work"
      ]
    },
    "kind": {
      "description": "A record type inside its facet. The pairing of facet and kind is checked below.",
      "enum": [
        "name",
        "bio",
        "expertise",
        "mastery",
        "role",
        "belief",
        "value",
        "opinion",
        "identity",
        "knowledge",
        "skill",
        "document",
        "passage",
        "raw",
        "process",
        "pattern",
        "definition",
        "correction",
        "decision",
        "position",
        "experience",
        "story",
        "journal",
        "preference",
        "boundary",
        "utterance",
        "marker",
        "profile_version",
        "audio_profile",
        "likeness_asset",
        "face_reference",
        "voiceprint",
        "motion_reference",
        "laugh_sample",
        "consent_scope",
        "likeness_model",
        "habit",
        "task",
        "project",
        "trade",
        "person",
        "interaction",
        "certificate",
        "grant",
        "attestation",
        "baseline",
        "state",
        "expression",
        "trigger",
        "coping",
        "profile",
        "sarcasm_index",
        "laugh",
        "bit",
        "never",
        "verbal",
        "physical",
        "ritual",
        "rhythm",
        "appearance",
        "work",
        "collection",
        "credit",
        "style_profile"
      ]
    },
    "authorship": {
      "description": "Who said it and how. Only self_verbatim can ever feed voice; derived never stands as canon alone.",
      "enum": [
        "self_verbatim",
        "self_paraphrase",
        "self_structured",
        "about_subject",
        "derived"
      ]
    },
    "trust_tier": {
      "description": "Assigned by ARKZ from the credential, the grant and the authorship. Never set by a client; a proposal that sends it has it ignored.",
      "enum": [
        "T0",
        "T1",
        "T2",
        "T3",
        "T4"
      ],
      "readOnly": true
    },
    "privacy": {
      "description": "Most restrictive first. A vault record is never served by the protocol. On a proposal the tighter of the grant default and this value wins.",
      "enum": [
        "vault",
        "training",
        "licensable"
      ]
    },
    "subject": {
      "description": "Who the record is about.",
      "type": "object",
      "required": [
        "ref"
      ],
      "properties": {
        "ref": {
          "type": "string",
          "pattern": "^(self|entity|person:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$"
        },
        "name": {
          "type": "string"
        }
      }
    },
    "content": {
      "description": "Text for insight kinds; structured for decisions, habits, tasks, projects, people and trades. A proposal carries at least one; a derived or metadata-only record read back may carry neither.",
      "type": "object",
      "properties": {
        "text": {
          "type": "string"
        },
        "structured": {
          "type": "object"
        }
      }
    },
    "domains": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "topics": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "time": {
      "type": "object",
      "properties": {
        "captured_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "valid_from": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "valid_until": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    },
    "provenance": {
      "description": "Where the record came from.",
      "type": "object",
      "properties": {
        "source_kind": {
          "description": "Free text, lower snake case.",
          "type": [
            "string",
            "null"
          ]
        },
        "source_ref": {
          "description": "Where it came from, for example a URL.",
          "type": [
            "string",
            "null"
          ]
        },
        "grant_id": {
          "description": "The source grant that wrote it; null when an owner key wrote it.",
          "type": [
            "string",
            "null"
          ]
        },
        "client_id": {
          "description": "The OAuth client, owner key id or source key id.",
          "type": [
            "string",
            "null"
          ]
        },
        "content_sha256": {
          "description": "Lower-case hex SHA-256 of the canonical content. Required on every proposal; ARKZ recomputes it and refuses a mismatch.",
          "type": [
            "string",
            "null"
          ],
          "pattern": "^[0-9a-f]{64}$"
        },
        "signature": {
          "description": "Optional detached signature by the source's registered key.",
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "lineage": {
      "type": "object",
      "properties": {
        "supersedes": {
          "type": [
            "string",
            "null"
          ]
        },
        "superseded_by": {
          "type": [
            "string",
            "null"
          ]
        },
        "derived_from": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    },
    "status": {
      "description": "Assigned by ARKZ.",
      "enum": [
        "proposed",
        "accepted",
        "rejected",
        "expired",
        "superseded",
        "revoked",
        "held"
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "anyOf": [
          {
            "not": {
              "required": [
                "id"
              ]
            }
          },
          {
            "required": [
              "status"
            ],
            "properties": {
              "status": {
                "const": "proposed"
              }
            }
          }
        ]
      },
      "then": {
        "required": [
          "provenance"
        ],
        "properties": {
          "content": {
            "minProperties": 1
          },
          "provenance": {
            "required": [
              "content_sha256"
            ],
            "properties": {
              "content_sha256": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "identity"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "name",
              "bio",
              "expertise",
              "mastery",
              "role"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "belief_value"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "belief",
              "value",
              "opinion",
              "identity"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "knowledge"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "knowledge",
              "skill",
              "document",
              "passage",
              "raw"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "framework"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "process",
              "pattern",
              "definition",
              "correction"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "position_decision"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "decision",
              "position"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "experience_story"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "experience",
              "story",
              "journal"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "preference_boundary"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "preference",
              "boundary"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "voice"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "utterance",
              "marker",
              "profile_version"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "likeness"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "audio_profile",
              "likeness_asset",
              "face_reference",
              "voiceprint",
              "motion_reference",
              "laugh_sample",
              "consent_scope",
              "likeness_model"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "behavior_execution"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "habit",
              "task",
              "project",
              "trade"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "relationship"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "person",
              "interaction"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "provenance_consent"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "certificate",
              "grant",
              "attestation"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "disposition"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "baseline",
              "state",
              "expression",
              "trigger",
              "coping"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "humor"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "profile",
              "sarcasm_index",
              "laugh",
              "bit",
              "never"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "mannerism"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "verbal",
              "physical",
              "ritual",
              "rhythm",
              "appearance"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "facet": {
            "const": "body_of_work"
          }
        }
      },
      "then": {
        "properties": {
          "kind": {
            "enum": [
              "work",
              "collection",
              "credit",
              "style_profile"
            ]
          }
        }
      }
    }
  ]
}
