{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/anchord-ai/json-schema/anchord-ai-entity-schema.json",
  "title": "Entity",
  "x-generated": "2026-11-01",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/anchord-ai-openapi.yaml#/components/schemas/Entity",
  "type": "object",
  "required": [
    "id",
    "kind",
    "merge_state"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "kind": {
      "$ref": "#/$defs/EntityKind"
    },
    "name": {
      "type": [
        "string",
        "null"
      ]
    },
    "domain": {
      "type": [
        "string",
        "null"
      ],
      "description": "Primary canonical domain (company entities)."
    },
    "identifiers": {
      "type": "object",
      "additionalProperties": true,
      "description": "Contains both flat primary identifier keys and structured multi-value arrays. Flat keys (e.g. email, stripe_customer_id) are the primary/canonical values used for highest-confidence matching. Structured arrays (emails, domains, external_ids) accumulate all known values from linked source records over time.\n",
      "properties": {
        "email": {
          "type": "string",
          "description": "Primary canonical email (person entities)."
        },
        "emails": {
          "type": "array",
          "description": "All known emails accumulated from linked source records.",
          "items": {
            "type": "object",
            "properties": {
              "value": {
                "type": "string"
              },
              "source": {
                "type": "string",
                "description": "System that provided this email."
              },
              "source_record_id": {
                "type": "string",
                "format": "uuid"
              }
            }
          }
        },
        "domains": {
          "type": "array",
          "description": "All known domains accumulated from linked source records.",
          "items": {
            "type": "object",
            "properties": {
              "value": {
                "type": "string"
              },
              "source": {
                "type": "string",
                "description": "System that provided this domain."
              },
              "source_record_id": {
                "type": "string",
                "format": "uuid"
              }
            }
          }
        },
        "external_ids": {
          "type": "array",
          "description": "External system identifiers with integration-level provenance.",
          "items": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "description": "Identifier type (e.g. stripe_customer_id, salesforce_account_id)."
              },
              "value": {
                "type": "string"
              },
              "source": {
                "type": "string"
              },
              "integration_id": {
                "type": "string",
                "format": "uuid",
                "description": "Which integration instance provided this ID."
              },
              "integration_label": {
                "type": "string",
                "description": "Human-friendly label for the integration instance."
              },
              "source_record_id": {
                "type": "string",
                "format": "uuid"
              }
            }
          }
        }
      }
    },
    "metadata": {
      "type": "object",
      "additionalProperties": true
    },
    "merge_state": {
      "$ref": "#/$defs/MergeState"
    },
    "canonical_entity_id": {
      "type": [
        "string",
        "null"
      ],
      "format": "uuid",
      "description": "Points to the canonical entity when this entity has been merged."
    },
    "merged_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "merge_reason": {
      "type": [
        "string",
        "null"
      ]
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    }
  },
  "$defs": {
    "EntityKind": {
      "type": "string",
      "enum": [
        "company",
        "person"
      ]
    },
    "MergeState": {
      "type": "string",
      "enum": [
        "canonical",
        "merged"
      ]
    }
  }
}