{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:certarail:schema:event:certarail.checkout.partner-delivery.v1",
  "title": "CertaRail checkout partner delivery event v1",
  "description": "Durable, PII-minimized partner-webhook delivery evidence. The exact body bytes are replayed for retries; URLs and signing secrets are deliberately excluded.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "delivery_event_id",
    "event_type",
    "event_version",
    "tenant_id",
    "aggregate_id",
    "correlation_id",
    "occurred_at",
    "partner_endpoint_reference",
    "key_id",
    "body_sha256",
    "attempt",
    "state",
    "safety"
  ],
  "properties": {
    "delivery_event_id": {
      "type": "string",
      "pattern": "^webhook_evt_[A-Za-z0-9._:/-]{1,111}$"
    },
    "event_type": { "const": "certarail.checkout.partner-delivery.v1" },
    "event_version": { "const": 1 },
    "tenant_id": { "type": "string", "minLength": 1, "maxLength": 128 },
    "aggregate_id": {
      "type": "string",
      "pattern": "^(checkout_|deal_)[A-Za-z0-9._:/-]{1,120}$"
    },
    "correlation_id": { "type": "string", "minLength": 1, "maxLength": 128 },
    "occurred_at": { "type": "string", "format": "date-time" },
    "partner_endpoint_reference": { "type": "string", "minLength": 1, "maxLength": 160 },
    "key_id": { "type": "string", "minLength": 1, "maxLength": 96 },
    "body_sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "attempt": { "type": "integer", "minimum": 1, "maximum": 32 },
    "state": { "enum": ["PENDING", "IN_FLIGHT", "DELIVERED", "RETRY_SCHEDULED", "QUARANTINED"] },
    "next_attempt_at": { "type": "string", "format": "date-time" },
    "delivered_at": { "type": "string", "format": "date-time" },
    "safety": {
      "type": "object",
      "additionalProperties": false,
      "required": ["environment", "execution_mode", "external_calls", "monetary", "production_enforceable"],
      "properties": {
        "environment": { "const": "SANDBOX" },
        "execution_mode": { "const": "SANDBOX" },
        "external_calls": { "const": 0 },
        "monetary": { "const": false },
        "production_enforceable": { "const": false }
      }
    }
  }
}
