{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://github.com/andrewhuot/headless-chat-sdk/schemas/identity.schema.json",
  "title": "ChatIdentity",
  "description": "Identity and conversation continuity primitives. Mirrors packages/gecx-chat/src/identity/types.ts.",
  "definitions": {
    "IdentityKind": {
      "type": "string",
      "enum": ["guest", "authenticated"]
    },
    "IdentityClaim": {
      "type": ["string", "number", "boolean"]
    },
    "ChatIdentity": {
      "type": "object",
      "required": ["kind", "identityId", "createdAt", "updatedAt"],
      "properties": {
        "kind": { "$ref": "#/definitions/IdentityKind" },
        "identityId": { "type": "string", "minLength": 1 },
        "externalId": { "type": "string" },
        "displayName": { "type": "string" },
        "email": { "type": "string" },
        "claims": {
          "type": "object",
          "additionalProperties": { "$ref": "#/definitions/IdentityClaim" }
        },
        "createdAt": { "type": "string", "format": "date-time" },
        "updatedAt": { "type": "string", "format": "date-time" }
      },
      "allOf": [
        {
          "if": { "properties": { "kind": { "const": "authenticated" } }, "required": ["kind"] },
          "then": { "required": ["externalId"] }
        }
      ]
    },
    "ConversationDescriptor": {
      "type": "object",
      "required": ["conversationId", "identityId", "lastActiveAt"],
      "properties": {
        "conversationId": { "type": "string", "minLength": 1 },
        "identityId": { "type": "string", "minLength": 1 },
        "title": { "type": "string" },
        "lastActiveAt": { "type": "string", "format": "date-time" },
        "surface": { "type": "string" },
        "metadata": { "type": "object" }
      }
    },
    "UpgradeInput": {
      "type": "object",
      "required": ["externalId"],
      "properties": {
        "externalId": { "type": "string", "minLength": 1 },
        "displayName": { "type": "string" },
        "email": { "type": "string" },
        "claims": {
          "type": "object",
          "additionalProperties": { "$ref": "#/definitions/IdentityClaim" }
        }
      }
    },
    "IdentityChangeReason": {
      "type": "string",
      "enum": [
        "bootstrap",
        "upgrade",
        "sign_out",
        "claims_updated",
        "cross_tab_sync",
        "external_set"
      ]
    },
    "SyncMessage": {
      "type": "object",
      "required": ["type", "sourceTabId"],
      "properties": {
        "type": {
          "type": "string",
          "enum": [
            "identity.changed",
            "identity.signed_out",
            "conversation.upserted",
            "conversation.removed"
          ]
        },
        "sourceTabId": { "type": "string" },
        "identityId": { "type": "string" },
        "conversationId": { "type": "string" }
      }
    }
  },
  "type": "object",
  "$ref": "#/definitions/ChatIdentity"
}
