{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://getzero.dev/contracts/zero.decision_receipt_card.v1.schema.json",
  "title": "ZERO Public Decision Receipt Card",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "kind",
    "status",
    "generated_at",
    "canonical_url",
    "public",
    "replay_id",
    "receipt_id",
    "title",
    "summary",
    "operator_handle",
    "agent_handle",
    "occurred_at",
    "outcome",
    "decision_loop",
    "signing",
    "journal",
    "audit",
    "links",
    "graph_context",
    "disclosures",
    "privacy_boundary",
    "score_gate",
    "blockers"
  ],
  "properties": {
    "schema_version": { "const": "zero.decision_receipt_card.v1" },
    "kind": { "const": "public_decision_receipt_card" },
    "status": { "const": "receipt_card_ready" },
    "generated_at": { "type": "string", "format": "date-time" },
    "canonical_url": {
      "type": "string",
      "format": "uri",
      "pattern": "^https://getzero\\.dev/api/replays/.+/receipt-card$"
    },
    "public": { "const": true },
    "replay_id": { "type": "string", "minLength": 1 },
    "receipt_id": { "type": "string", "pattern": "^receipt-[a-f0-9]{16}$" },
    "title": { "type": "string", "minLength": 1 },
    "summary": { "type": "string", "minLength": 1 },
    "operator_handle": { "type": "string", "minLength": 1 },
    "agent_handle": { "type": "string", "minLength": 1 },
    "occurred_at": { "type": "string", "format": "date-time" },
    "outcome": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "venue", "symbol", "direction", "performance_fields_included"],
      "properties": {
        "kind": { "enum": ["closed_trade", "heartbeat", "position", "refusal", "public_evidence"] },
        "venue": { "type": "string", "minLength": 1 },
        "symbol": { "type": ["string", "null"] },
        "direction": { "type": ["string", "null"] },
        "performance_fields_included": { "const": false }
      },
      "not": { "required": ["pnl_usd"] }
    },
    "decision_loop": {
      "type": "object",
      "additionalProperties": false,
      "required": ["complete_steps", "total_steps", "statuses"],
      "properties": {
        "complete_steps": { "type": "integer", "minimum": 0 },
        "total_steps": { "type": "integer", "minimum": 1 },
        "statuses": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["step", "status"],
            "properties": {
              "step": { "enum": ["observe", "hypothesize", "size", "commit", "resolve", "evolve", "replay"] },
              "status": { "enum": ["complete", "partial", "refused", "not_applicable"] }
            }
          }
        }
      }
    },
    "signing": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "boundary", "payload_hash", "private_keys_stored", "allowed_actions"],
      "properties": {
        "status": { "enum": ["complete", "partial", "not_applicable"] },
        "boundary": { "type": "string", "minLength": 1 },
        "payload_hash": { "type": ["string", "null"] },
        "private_keys_stored": { "const": false },
        "allowed_actions": {
          "type": "array",
          "items": { "enum": ["order", "cancel", "scheduleCancel"] }
        }
      }
    },
    "journal": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "root_hash", "anchor_url", "verifier"],
      "properties": {
        "status": { "enum": ["complete", "partial", "unavailable"] },
        "root_hash": { "type": ["string", "null"] },
        "anchor_url": { "type": ["string", "null"], "format": "uri" },
        "verifier": { "type": "string", "minLength": 1 }
      }
    },
    "audit": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "score", "complete_checks", "total_checks", "missing_evidence"],
      "properties": {
        "status": { "enum": ["complete", "partial", "weak"] },
        "score": { "type": "integer", "minimum": 0, "maximum": 100 },
        "complete_checks": { "type": "integer", "minimum": 0 },
        "total_checks": { "type": "integer", "minimum": 1 },
        "missing_evidence": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 }
        }
      }
    },
    "links": {
      "type": "object",
      "additionalProperties": false,
      "required": ["replay", "json", "export", "share_image", "schema", "operator", "replay_index", "entrypoints", "graph_context"],
      "properties": {
        "replay": { "type": "string", "format": "uri" },
        "json": { "type": "string", "format": "uri" },
        "export": { "type": "string", "format": "uri" },
        "share_image": { "type": "string", "format": "uri" },
        "schema": { "const": "https://getzero.dev/contracts/zero.decision_receipt_card.v1.schema.json" },
        "operator": { "type": "string", "format": "uri" },
        "replay_index": { "type": "string", "format": "uri" },
        "entrypoints": { "const": "https://getzero.dev/api/replays/entrypoints" },
        "graph_context": {
          "type": "string",
          "format": "uri",
          "pattern": "^https://getzero\\.dev/api/replays/.+/graph-context$"
        }
      }
    },
    "graph_context": {
      "type": "array",
      "minItems": 6,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["from", "to", "relation", "href"],
        "properties": {
          "from": { "const": "receipt_card" },
          "to": {
            "enum": [
              "decision_replay",
              "replay_json",
              "export_capsule",
              "share_image",
              "operator_profile",
              "replay_entrypoints",
              "replay_graph_context"
            ]
          },
          "relation": { "type": "string", "minLength": 1 },
          "href": { "type": "string", "format": "uri" }
        }
      }
    },
    "disclosures": {
      "type": "object",
      "additionalProperties": false,
      "required": ["not_investment_advice", "no_performance_promise", "no_auto_execution", "public_replay_delay_applies"],
      "properties": {
        "not_investment_advice": { "const": true },
        "no_performance_promise": { "const": true },
        "no_auto_execution": { "const": true },
        "public_replay_delay_applies": { "const": true }
      }
    },
    "privacy_boundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "public_only",
        "private_trace_payloads_public",
        "private_keys_public",
        "operator_ids_public",
        "performance_metrics_public"
      ],
      "properties": {
        "public_only": { "const": true },
        "private_trace_payloads_public": { "const": false },
        "private_keys_public": { "const": false },
        "operator_ids_public": { "const": false },
        "performance_metrics_public": { "const": false }
      }
    },
    "score_gate": {
      "type": "object",
      "additionalProperties": false,
      "required": ["can_promote_public_score", "reason", "next_blocker"],
      "properties": {
        "can_promote_public_score": { "const": true },
        "reason": { "type": "string", "minLength": 1 },
        "next_blocker": { "const": "recurring_public_decision_artifacts_missing" }
      }
    },
    "blockers": {
      "type": "array",
      "maxItems": 0
    }
  }
}
