{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://sierracatalina.com/context-layer/implementation/receipt.schema.json",
  "title": "operation receipt",
  "description": "Phase 0 payload-minimized evidence for a Context Layer operation.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "spec_version",
    "type",
    "id",
    "created_at",
    "issuer",
    "operation",
    "actor",
    "subject_ref",
    "request_ref",
    "decision_ref",
    "bundle_ref",
    "started_at",
    "completed_at",
    "outcome",
    "policy_snapshot",
    "input_digest",
    "output_digest",
    "user_summary",
    "payload_included"
  ],
  "properties": {
    "spec_version": {
      "const": "context-layer/0.1-draft"
    },
    "type": {
      "const": "receipt"
    },
    "id": {
      "type": "string",
      "pattern": "^urn:cl:receipt:[A-Za-z0-9._~-]+$"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "issuer": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "string",
          "minLength": 3,
          "maxLength": 512
        }
      }
    },
    "operation": {
      "$ref": "#/$defs/name"
    },
    "actor": {
      "type": "string",
      "minLength": 3,
      "maxLength": 512
    },
    "subject_ref": {
      "type": "string",
      "pattern": "^urn:cl:alias:[A-Za-z0-9._~-]+$"
    },
    "request_ref": {
      "type": "string",
      "pattern": "^urn:cl:request:[A-Za-z0-9._~-]+$"
    },
    "decision_ref": {
      "type": "string",
      "pattern": "^urn:cl:decision:[A-Za-z0-9._~-]+$"
    },
    "bundle_ref": {
      "type": "string",
      "pattern": "^urn:cl:bundle:[A-Za-z0-9._~-]+$"
    },
    "started_at": {
      "type": "string",
      "format": "date-time"
    },
    "completed_at": {
      "type": "string",
      "format": "date-time"
    },
    "outcome": {
      "enum": [
        "success",
        "failure",
        "indeterminate"
      ]
    },
    "policy_snapshot": {
      "$ref": "#/$defs/digest"
    },
    "input_digest": {
      "$ref": "#/$defs/digest"
    },
    "output_digest": {
      "$ref": "#/$defs/digest"
    },
    "user_summary": {
      "type": "string",
      "minLength": 1,
      "maxLength": 500
    },
    "payload_included": {
      "const": false
    }
  },
  "$defs": {
    "name": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9]*(?:[._-][a-z0-9]+)*$"
    },
    "digest": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    }
  }
}
