{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openinherit.org/v3/event.json",
  "title": "Event",
  "description": "An event that occurred during estate administration. The INHERIT document carries its own audit trail via the events array",
  "type": "object",
  "required": [ "id", "eventType", "occurredAt" ],
  "properties": {
    "id": {
      "description": "Unique identifier for this event",
      "type": "string",
      "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
      "format": "uuid"
    },
    "eventType": {
      "description": "Type of event. Core types cover standard estate administration events. Extension types use x-inherit- prefix",
      "anyOf": [
        {
          "enum": [
            "death_registered",
            "will_located",
            "will_read",
            "executor_appointed",
            "probate_applied",
            "probate_granted",
            "letters_of_administration_granted",
            "asset_identified",
            "asset_valued",
            "asset_collected",
            "asset_transferred",
            "asset_sold",
            "debt_identified",
            "debt_paid",
            "tax_return_filed",
            "tax_clearance_received",
            "distribution_made",
            "estate_accounts_filed",
            "estate_closed",
            "claim_received",
            "claim_resolved",
            "deed_of_variation_executed",
            "disclaimer_received",
            "other"
          ]
        },
        {
          "type": "string",
          "pattern": "^x-inherit-.+$"
        }
      ]
    },
    "occurredAt": {
      "description": "When the event occurred (ISO 8601 timestamp)",
      "readOnly": true,
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}",
      "format": "date-time"
    },
    "trigger": {
      "description": "What initiated this event",
      "enum": [
        "court_action",
        "executor_action",
        "beneficiary_action",
        "institutional_action",
        "calendar_deadline",
        "legislative_change",
        "marketplace_action",
        "system_generated"
      ]
    },
    "description": {
      "description": "Human-readable description of the event",
      "type": "string",
      "maxLength": 2000
    },
    "affectedEntityIds": {
      "description": "UUIDs of entities affected by this event",
      "type": "array",
      "maxItems": 100,
      "uniqueItems": true,
      "items": {
        "type": "string",
        "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
        "format": "uuid"
      }
    },
    "affectedEntityTypes": {
      "description": "Entity types affected (estate, asset, property, bequest, etc.)",
      "type": "array",
      "maxItems": 50,
      "items": {
        "type": "string",
        "maxLength": 500,
        "minLength": 1
      }
    },
    "actor": {
      "description": "The person, institution, or system that performed the action",
      "type": "object",
      "properties": {
        "name": {
          "description": "Name of the actor",
          "type": "string",
          "maxLength": 255
        },
        "type": {
          "description": "Category of actor",
          "enum": [
            "court",
            "executor",
            "beneficiary",
            "bank",
            "insurer",
            "tax_authority",
            "religious_body",
            "valuer",
            "marketplace",
            "system"
          ]
        },
        "jurisdiction": {
          "description": "Jurisdiction of the actor",
          "$ref": "common/jurisdiction.json"
        }
      },
      "additionalProperties": false
    },
    "metadata": {
      "description": "Type-specific metadata for this event. Structure depends on eventType",
      "type": "object",
      "properties": {
        "grantNumber": {
          "description": "Grant number (for probate_granted events)",
          "type": "string",
          "maxLength": 255
        },
        "grantValue": {
          "description": "Gross estate value on the grant",
          "$ref": "common/money.json"
        },
        "issuingCourt": {
          "description": "Court that issued the grant",
          "examples": [ "Birmingham District Probate Registry" ],
          "type": "string",
          "maxLength": 255
        },
        "valuationId": {
          "description": "Reference to a Valuation.id (for asset_valued events)",
          "type": "string",
          "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
          "format": "uuid"
        },
        "valuedAmount": {
          "description": "The valuation amount",
          "$ref": "common/money.json"
        },
        "recipientPersonId": {
          "description": "Person.id of distribution recipient (for distribution_made events)",
          "type": "string",
          "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
          "format": "uuid"
        },
        "recipientPersonIdDisplay": {
          "description": "Human-readable display name for the referenced recipient person",
          "type": "string",
          "maxLength": 255
        },
        "recipientOrganisationId": {
          "description": "Organisation.id of distribution recipient",
          "type": "string",
          "pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$",
          "format": "uuid"
        },
        "recipientOrganisationIdDisplay": {
          "description": "Human-readable display name for the referenced recipient organisation",
          "type": "string",
          "maxLength": 255
        },
        "distributionAmount": {
          "description": "Amount distributed",
          "$ref": "common/money.json"
        }
      },
      "additionalProperties": {
        "type": "string",
        "maxLength": 500
      }
    },
    "provenance": {
      "description": "Consolidated provenance metadata — how this entity was created, by whom, and whether a human has verified it",
      "$ref": "common/provenance.json"
    }
  },
  "additionalProperties": false
}
