{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.certarail.local/events/certarail.asset.movement.v1.schema.json",
  "title": "CertaRail Asset Movement Event v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["event_id", "event_type", "occurred_at", "tenant_id", "movement"],
  "properties": {
    "event_id": { "type": "string", "minLength": 1 },
    "event_type": { "const": "certarail.asset.movement.v1" },
    "occurred_at": { "type": "string", "format": "date-time" },
    "tenant_id": { "type": "string", "minLength": 1, "maxLength": 128 },
    "movement": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "movement_id",
        "request_id",
        "tenant_id",
        "decision_id",
        "kind",
        "direction",
        "asset_code",
        "quantity",
        "network",
        "status",
        "wallet_ref",
        "source_system",
        "source_event_ref",
        "observed_at",
        "recorded_at",
        "evidence_digest"
      ],
      "properties": {
        "movement_id": { "type": "string", "minLength": 1 },
        "request_id": { "type": "string", "minLength": 1 },
        "tenant_id": { "type": "string", "minLength": 1 },
        "decision_id": { "type": "string", "minLength": 1 },
        "kind": {
          "enum": [
            "BUY_FILL",
            "SELL_FILL",
            "DEPOSIT",
            "WITHDRAWAL",
            "INTERNAL_TRANSFER",
            "EXTERNAL_TRANSFER",
            "SWAP_LEG",
            "FEE",
            "REFUND",
            "REVERSAL",
            "REWARD",
            "AIRDROP",
            "FORK",
            "MINING",
            "STAKING",
            "CUSTODY_MOVE",
            "ADJUSTMENT"
          ]
        },
        "direction": { "enum": ["CREDIT", "DEBIT"] },
        "asset_code": { "type": "string", "minLength": 1 },
        "quantity": {
          "type": "object",
          "additionalProperties": false,
          "required": ["atomic_units", "decimals"],
          "properties": {
            "atomic_units": { "type": "string", "pattern": "^[1-9][0-9]{0,77}$" },
            "decimals": { "type": "integer", "minimum": 0, "maximum": 38 }
          }
        },
        "network": { "type": "string", "minLength": 1 },
        "status": { "enum": ["OBSERVED", "PENDING", "CONFIRMED", "FAILED", "REVERSED"] },
        "wallet_ref": { "type": "string", "minLength": 1 },
        "counterparty_ref": { "type": "string" },
        "venue_ref": { "type": "string" },
        "blockchain_transaction_id": { "type": "string" },
        "confirmations": { "type": "integer", "minimum": 0 },
        "source_system": { "type": "string", "minLength": 1 },
        "source_event_ref": { "type": "string", "minLength": 1 },
        "kyt_assessment_ref": { "type": "string" },
        "address_verification_ref": { "type": "string" },
        "travel_rule_ref": { "type": "string" },
        "observed_at": { "type": "string", "format": "date-time" },
        "recorded_at": { "type": "string", "format": "date-time" },
        "evidence_digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
      }
    }
  }
}
