{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aslice.sh/schematics/json/recovery-receipt.schema.json",
  "title": "Recovery receipt",
  "description": "Version 1 structural contract. Normative field semantics: docs/STATE-AND-RECOVERY.md section 10.2 and docs/DATABASE.md section 9. Cryptography, canonical encoding, chain continuity, ordering, and filesystem safety require semantic validation.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "format": {
      "const": 1
    },
    "owner": {
      "enum": [
        "client-state",
        "client-cache",
        "system-state",
        "coordinator",
        "publisher",
        "release-signer"
      ]
    },
    "instance_id": {
      "type": "string",
      "pattern": "^[0-9a-f]{32}$"
    },
    "operation_id": {
      "type": "string",
      "pattern": "^[0-9a-f]{32}$"
    },
    "intent": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "step": {
      "type": "integer",
      "minimum": 0,
      "maximum": 9007199254740991
    },
    "state": {
      "enum": [
        "prepared",
        "applied",
        "commit-ready",
        "acknowledged",
        "reversed"
      ]
    },
    "before": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "after": {
      "anyOf": [
        {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        {
          "type": "null"
        }
      ]
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "digest": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          },
          "size": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          }
        },
        "required": [
          "digest",
          "size"
        ]
      },
      "uniqueItems": true
    }
  },
  "required": [
    "format",
    "owner",
    "instance_id",
    "operation_id",
    "intent",
    "step",
    "state",
    "before",
    "after",
    "evidence"
  ]
}
