{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "decision-response.v0.json",
  "title": "Warranted Crossings decision response (v0, proposed)",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "outcome",
    "reason_codes",
    "fixture_or_domain",
    "policy_ref",
    "mapping_ref",
    "invariant_ref",
    "signature_verification",
    "authority_verification",
    "evidence_verification",
    "valid_time",
    "record_time",
    "receipt_ref",
    "reassesses",
    "decision_digest"
  ],
  "properties": {
    "outcome": {
      "enum": [
        "EXECUTE",
        "HOLD"
      ]
    },
    "reason_codes": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "enum": [
          "UNAVAILABLE",
          "INVALID",
          "EXPIRED",
          "UNAUTHORIZED",
          "INVARIANT_FAILED",
          "POLICY_DENIED",
          "INPUT_BINDING_FAILED",
          "REPLAY_FAILED"
        ]
      },
      "description": "REPLAY_FAILED appears only when a replay comparison was run and failed; decide() itself never emits it."
    },
    "fixture_or_domain": {
      "type": "string"
    },
    "policy_ref": {
      "type": "string",
      "description": "sha256:<hex> plus the policy id, or a note that material is unavailable"
    },
    "mapping_ref": {
      "type": "string"
    },
    "invariant_ref": {
      "type": "string"
    },
    "signature_verification": {
      "$ref": "#/$defs/status",
      "description": "Ed25519 verification of the verdict bytes. Says who signed, not who may authorise."
    },
    "authority_verification": {
      "$ref": "#/$defs/status"
    },
    "evidence_verification": {
      "$ref": "#/$defs/status"
    },
    "valid_time": {
      "type": "string",
      "format": "date-time"
    },
    "record_time": {
      "type": "string",
      "format": "date-time"
    },
    "receipt_ref": {
      "type": "string",
      "pattern": "^wcr:sha256:[0-9a-f]{64}$"
    },
    "reassesses": {
      "type": [
        "string",
        "null"
      ],
      "description": "receipt_ref of the prior determination, if this is a reassessment"
    },
    "decision_digest": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "Digest over outcome, checks, inputs and conditions; excludes record_time so replays are comparable"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "outcome": {
            "const": "EXECUTE"
          }
        }
      },
      "then": {
        "properties": {
          "reason_codes": {
            "maxItems": 0
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "outcome": {
            "const": "HOLD"
          }
        }
      },
      "then": {
        "properties": {
          "reason_codes": {
            "minItems": 1
          }
        }
      }
    }
  ],
  "$defs": {
    "status": {
      "enum": [
        "PASS",
        "FAIL",
        "UNAVAILABLE",
        "UNMEASURABLE"
      ]
    }
  }
}
