{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://platoskallipolis.com/schemas/commercial-fulfillment-report.v1.json",
  "title": "Plato's Kallipolis commercial fulfillment report",
  "type": "object",
  "additionalProperties": false,
  "required": ["$schema", "schema", "runId", "taskId", "orderId", "paymentId", "paymentEnvironment", "targetEndpoint", "targetEndpointSha256", "protocol", "generatedAt", "observationLimit", "observations", "checks", "deliveryCostEvidence", "privacy"],
  "properties": {
    "$schema": { "const": "https://platoskallipolis.com/schemas/commercial-fulfillment-report.v1.json" },
    "schema": { "const": "kallipolis.commercial-fulfillment-report.v1" },
    "runId": { "type": "string", "format": "uuid" },
    "taskId": { "type": "string", "format": "uuid" },
    "orderId": { "type": "string", "format": "uuid" },
    "paymentId": { "type": "string", "format": "uuid" },
    "paymentEnvironment": { "enum": ["TEST", "LIVE"] },
    "targetEndpoint": { "type": "string", "format": "uri", "pattern": "^https://" },
    "targetEndpointSha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
    "protocol": { "enum": ["MCP", "A2A", "REST"] },
    "generatedAt": { "type": "string", "format": "date-time" },
    "observationLimit": { "const": 2 },
    "observations": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "prefixItems": [
        { "$ref": "#/$defs/observation", "properties": { "attempt": { "const": 1 } } },
        { "$ref": "#/$defs/observation", "properties": { "attempt": { "const": 2 } } }
      ],
      "items": false
    },
    "checks": {
      "type": "array",
      "minItems": 10,
      "maxItems": 10,
      "items": { "$ref": "#/$defs/check" }
    },
    "deliveryCostEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": ["durationMillis", "responseBytes", "directExternalCostMinor", "currency", "completeness", "missing"],
      "properties": {
        "durationMillis": { "type": "integer", "minimum": 0 },
        "responseBytes": { "type": "integer", "minimum": 0 },
        "directExternalCostMinor": { "type": ["integer", "null"], "minimum": 0 },
        "currency": { "type": ["string", "null"], "pattern": "^[A-Z]{3}$" },
        "completeness": { "enum": ["PARTIAL", "COMPLETE"] },
        "missing": { "type": "array", "items": { "type": "string" }, "uniqueItems": true }
      }
    },
    "privacy": {
      "type": "object",
      "additionalProperties": false,
      "required": ["rawResponseBodiesStored", "credentialsStored", "cookiesStored", "fullResponseHeadersStored"],
      "properties": {
        "rawResponseBodiesStored": { "const": false },
        "credentialsStored": { "const": false },
        "cookiesStored": { "const": false },
        "fullResponseHeadersStored": { "const": false }
      }
    }
  },
  "$defs": {
    "nullableSha256": { "type": ["string", "null"], "pattern": "^[a-f0-9]{64}$" },
    "observation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["attempt", "outcome", "statusCode", "mediaType", "redirectOriginSha256", "bodySha256", "bodyBytes", "semanticMatch", "errorCode", "durationMillis"],
      "properties": {
        "attempt": { "type": "integer", "minimum": 1, "maximum": 2 },
        "outcome": { "enum": ["PASS", "FAIL", "UNAVAILABLE"] },
        "statusCode": { "type": ["integer", "null"], "minimum": 100, "maximum": 599 },
        "mediaType": { "type": ["string", "null"], "maxLength": 160 },
        "redirectOriginSha256": { "$ref": "#/$defs/nullableSha256" },
        "bodySha256": { "$ref": "#/$defs/nullableSha256" },
        "bodyBytes": { "type": "integer", "minimum": 0, "maximum": 262144 },
        "semanticMatch": { "type": ["boolean", "null"] },
        "errorCode": { "type": ["string", "null"], "maxLength": 80 },
        "durationMillis": { "type": "integer", "minimum": 0 }
      }
    },
    "check": {
      "type": "object",
      "additionalProperties": false,
      "required": ["attempt", "id", "outcome", "evidence"],
      "properties": {
        "attempt": { "type": "integer", "minimum": 1, "maximum": 2 },
        "id": { "enum": ["transport", "http-status", "media-type", "protocol-semantic", "redirect"] },
        "outcome": { "enum": ["PASS", "FAIL", "UNAVAILABLE"] },
        "evidence": { "type": "string", "minLength": 1, "maxLength": 500 }
      }
    }
  }
}
