{
  "openapi": "3.1.0",
  "info": {
    "title": "OHN-24 Event and Subscription Infrastructure",
    "version": "1.0.0",
    "description": "Transactional outbox, inbox deduplication, schema registry, subscriptions, webhook and pull delivery, controlled replay, dead letters. Default deny. Bearer authentication. Every POST needs an Idempotency-Key header (8-128 characters). Delivery is at least once."
  },
  "servers": [
    {
      "url": "/api/ohn/v1"
    }
  ],
  "security": [
    {
      "bearer": []
    }
  ],
  "paths": {
    "/subscriptions": {
      "post": {
        "operationId": "ohn-24_post_subscriptions",
        "x-inventory-id": "OHN-24-API-001",
        "summary": "Create a subscription (F001)",
        "x-roles": [
          "event_operator",
          "integration_engineer"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SubscriptionCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        }
      },
      "get": {
        "operationId": "ohn-24_get_subscriptions",
        "summary": "List subscriptions",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "enum": [
                "active",
                "paused",
                "revoked"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Page"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/subscriptions/simulate": {
      "post": {
        "operationId": "ohn-24_post_subscriptions-simulate",
        "summary": "Permission simulator; persists nothing",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "deliver true/false with reason"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SimulateCommand"
              }
            }
          }
        }
      }
    },
    "/subscriptions/{id}": {
      "get": {
        "operationId": "ohn-24_get_subscriptions-id",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Subscription with history"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/subscriptions/{id}/transitions": {
      "post": {
        "operationId": "ohn-24_post_subscriptions-id-transitions",
        "summary": "Pause, resume or revoke (revoked is final and cancels unfinished deliveries)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TransitionCommand"
              }
            }
          }
        }
      }
    },
    "/subscriptions/{id}/pull": {
      "post": {
        "operationId": "ohn-24_post_subscriptions-id-pull",
        "summary": "Lease deliveries (event_subscriber of the subscriber organisation only)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Leased events: items[{delivery_id, lease_expires_at, event: envelope}] and subscription_status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "items": {
                      "type": "array"
                    },
                    "subscription_status": {
                      "enum": [
                        "active",
                        "paused",
                        "revoked"
                      ]
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        },
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PullCommand"
              }
            }
          }
        }
      }
    },
    "/deliveries/{id}/acknowledge": {
      "post": {
        "operationId": "ohn-24_post_deliveries-id-acknowledge",
        "summary": "Acknowledge a leased delivery; repeating is harmless",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Acknowledged"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        }
      }
    },
    "/endpoints": {
      "post": {
        "operationId": "ohn-24_post_endpoints",
        "summary": "Register a destination (HTTPS, public hosts only)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "201": {
            "description": "Created"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EndpointCommand"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "ohn-24_get_endpoints",
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/event-schemas": {
      "post": {
        "operationId": "ohn-24_post_event-schemas",
        "summary": "Register a strict payload schema (root object, additionalProperties false)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "201": {
            "description": "Created"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SchemaCommand"
              }
            }
          }
        }
      },
      "get": {
        "operationId": "ohn-24_get_event-schemas",
        "responses": {
          "200": {
            "description": "OK"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/events": {
      "post": {
        "operationId": "ohn-24_post_events",
        "summary": "Publish an event (W001): schema check, inbox deduplication on (jurisdiction, source_system_id, source_event_id), event log, fan-out. 201 new, 200 duplicate, 409 source_event_conflict, 422 schema_not_registered",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PublishCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Accepted and persisted"
          },
          "200": {
            "description": "Duplicate: original event returned"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        }
      }
    },
    "/events/deliveries": {
      "get": {
        "operationId": "ohn-24_get_events-deliveries",
        "x-inventory-id": "OHN-24-API-002",
        "summary": "List deliveries",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "enum": [
                "enqueued",
                "attempted",
                "retrying",
                "acknowledged",
                "dead_lettered",
                "cancelled"
              ]
            }
          },
          {
            "name": "subscription_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "event_id",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Page"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/events/deliveries/{id}": {
      "get": {
        "operationId": "ohn-24_get_events-deliveries-id",
        "summary": "Delivery with attempts and history",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/events/dead-letters": {
      "get": {
        "operationId": "ohn-24_get_events-dead-letters",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "schema": {
              "enum": [
                "open",
                "held",
                "requeued",
                "discarded"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Page"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/events/dead-letters/{id}/disposition": {
      "post": {
        "operationId": "ohn-24_post_events-dead-letters-id-disposition",
        "summary": "Disposition (F003, event_operator only). operator_ref must equal the authenticated operator",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DispositionCommand"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OK"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        }
      }
    },
    "/events/maintenance/dispatch": {
      "post": {
        "operationId": "ohn-24_post_events-maintenance-dispatch",
        "summary": "Deliver due webhooks now; 409 dispatch_disabled unless delivery is enabled (ohn.m24.dispatch-enabled)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Counts"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        }
      }
    },
    "/events/maintenance/sweep": {
      "post": {
        "operationId": "ohn-24_post_events-maintenance-sweep",
        "summary": "Recover expired leases and reconcile replays (works with delivery disabled)",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Counts"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        }
      }
    },
    "/events/{id}/replay": {
      "post": {
        "operationId": "ohn-24_post_events-id-replay",
        "x-inventory-id": "OHN-24-API-003",
        "summary": "Request a controlled replay (F002): authorized, range sized, dry run. Nothing is delivered yet",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReplayCommand"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Dry-run result"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        }
      }
    },
    "/replays": {
      "get": {
        "operationId": "ohn-24_get_replays",
        "responses": {
          "200": {
            "description": "Page"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "parameters": [
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ]
      }
    },
    "/replays/{id}": {
      "get": {
        "operationId": "ohn-24_get_replays-id",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Replay with history and delivery states"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/replays/{id}/start": {
      "post": {
        "operationId": "ohn-24_post_replays-id-start",
        "summary": "Start a replay. Only the named approver (not the requester) may do this",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "200": {
            "description": "Started"
          },
          "403": {
            "$ref": "#/components/responses/Error"
          },
          "409": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReplayStartCommand"
              }
            }
          }
        }
      }
    },
    "/events/reports/{reportId}": {
      "get": {
        "operationId": "ohn-24_get_events-reports-reportid",
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-24-R001",
                "OHN-24-R002",
                "OHN-24-R003"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/Filter_period_from"
          },
          {
            "$ref": "#/components/parameters/Filter_period_to"
          },
          {
            "$ref": "#/components/parameters/Filter_subscriber"
          },
          {
            "$ref": "#/components/parameters/Filter_event_type"
          },
          {
            "$ref": "#/components/parameters/Filter_service"
          },
          {
            "$ref": "#/components/parameters/Cursor"
          }
        ],
        "responses": {
          "200": {
            "description": "Report"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "summary": "Run a report (R001 delivery SLO, R002 replay accounting, R003 outbox backlog); 100 rows per page"
      }
    },
    "/events/reports/{reportId}/export": {
      "post": {
        "operationId": "ohn-24_post_events-reports-reportid-export",
        "summary": "Signed, single-use, five-minute export (csv|pdf)",
        "parameters": [
          {
            "name": "reportId",
            "in": "path",
            "required": true,
            "schema": {
              "enum": [
                "OHN-24-R001",
                "OHN-24-R002",
                "OHN-24-R003"
              ]
            }
          },
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "responses": {
          "201": {
            "description": "download_path"
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "422": {
            "$ref": "#/components/responses/Error"
          },
          "503": {
            "description": "503 dependency_unavailable: Export signing is not configured",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "400": {
            "$ref": "#/components/responses/IdempotencyKeyRequired"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ExportCommand"
              }
            }
          }
        }
      }
    },
    "/events/exports/{token}": {
      "get": {
        "operationId": "ohn-24_get_events-exports-token",
        "parameters": [
          {
            "name": "token",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{20,64}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "File",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/Error"
          },
          "410": {
            "description": "410 export_expired or export_consumed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "500": {
            "description": "500 export_integrity_failed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthenticated"
          },
          "403": {
            "$ref": "#/components/responses/Denied"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        },
        "summary": "Download once, within five minutes, as the requester (404 for anyone else)"
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearer": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "parameters": {
      "Id": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "Cursor": {
        "name": "cursor",
        "in": "query",
        "schema": {
          "type": "string",
          "maxLength": 64
        }
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "minLength": 8,
          "maxLength": 128
        }
      },
      "Filter_period_from": {
        "name": "period_from",
        "in": "query",
        "description": "ISO instant with offset",
        "schema": {
          "type": "string",
          "format": "date-time"
        }
      },
      "Filter_period_to": {
        "name": "period_to",
        "in": "query",
        "description": "ISO instant with offset; not before period_from (compared as text)",
        "schema": {
          "type": "string",
          "format": "date-time"
        }
      },
      "Filter_subscriber": {
        "name": "subscriber",
        "in": "query",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      },
      "Filter_event_type": {
        "name": "event_type",
        "in": "query",
        "description": "R001 only",
        "schema": {
          "type": "string",
          "maxLength": 128
        }
      },
      "Filter_service": {
        "name": "service",
        "in": "query",
        "description": "R003 only: the source system id",
        "schema": {
          "type": "string",
          "format": "uuid"
        }
      }
    },
    "responses": {
      "Error": {
        "description": "Typed error: the platform problem+json superset of {error, message, details}",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthenticated": {
        "description": "401 unauthenticated: no, invalid or expired token, a subject, jurisdiction or organization that is not a UUID, or an unknown role",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Denied": {
        "description": "403 denied_by_policy: role or purpose of use not permitted (audited)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "TooLarge": {
        "description": "413 payload_too_large: body over 512 kB",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "429 rate_limited (Retry-After set)",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "IdempotencyKeyRequired": {
        "description": "400 idempotency_key_required, or 400 malformed_request for a body that is not JSON; 409 idempotency_key_reused / request_in_progress",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "details": {
            "type": "object",
            "description": "First failing check per top-level field, as the zod issue code (invalid_type, too_small, too_big, invalid_string, invalid_enum_value), a domain reason or a custom message; unknown keys under \"_\" as unrecognized_keys",
            "additionalProperties": {
              "type": "string"
            }
          },
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "trace_id": {
            "type": "string"
          }
        }
      },
      "Classification": {
        "enum": [
          "public",
          "internal",
          "confidential",
          "restricted",
          "phi"
        ]
      },
      "SubscriptionCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "subscriber_org",
          "event_type",
          "destination_endpoint",
          "delivery_mode",
          "scope",
          "max_retry_window_hours"
        ],
        "properties": {
          "subscriber_org": {
            "type": "string",
            "format": "uuid"
          },
          "event_type": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)+$",
            "maxLength": 128
          },
          "destination_endpoint": {
            "type": "string",
            "format": "uuid"
          },
          "delivery_mode": {
            "enum": [
              "webhook",
              "pull"
            ]
          },
          "scope": {
            "type": "string",
            "maxLength": 8192,
            "description": "JSON text: {organization_ids: uuid[1..50], max_classification}. organization_ids may only contain the creating organisation; no wildcard",
            "minLength": 1
          },
          "max_retry_window_hours": {
            "type": "integer",
            "minimum": 0,
            "description": "At most the platform maximum (default 72)"
          }
        }
      },
      "PublishCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "event_type",
          "schema_version",
          "occurred_at",
          "aggregate_id",
          "aggregate_version",
          "correlation_id",
          "causation_id",
          "data_classification",
          "payload",
          "source_system_id",
          "source_event_id"
        ],
        "properties": {
          "event_type": {
            "type": "string",
            "maxLength": 128
          },
          "schema_version": {
            "type": "string",
            "pattern": "^\\d+\\.\\d+\\.\\d+$"
          },
          "occurred_at": {
            "type": "string",
            "format": "date-time"
          },
          "aggregate_id": {
            "type": "string",
            "format": "uuid"
          },
          "aggregate_version": {
            "type": "integer",
            "minimum": 1
          },
          "correlation_id": {
            "type": "string",
            "format": "uuid"
          },
          "causation_id": {
            "type": "string",
            "format": "uuid"
          },
          "data_classification": {
            "$ref": "#/components/schemas/Classification"
          },
          "payload": {
            "type": "object"
          },
          "source_system_id": {
            "type": "string",
            "format": "uuid"
          },
          "source_event_id": {
            "type": "string",
            "maxLength": 200,
            "minLength": 1
          }
        }
      },
      "ReplayCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "subscription_ref",
          "event_range_start",
          "event_range_end",
          "replay_reason",
          "approved_by"
        ],
        "properties": {
          "subscription_ref": {
            "type": "string",
            "format": "uuid"
          },
          "event_range_start": {
            "type": "string",
            "format": "date-time"
          },
          "event_range_end": {
            "type": "string",
            "format": "date-time"
          },
          "replay_reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          },
          "approved_by": {
            "type": "string",
            "format": "uuid"
          },
          "include_acknowledged": {
            "type": "boolean",
            "default": false
          }
        },
        "description": "event_range_start must be before event_range_end; the range may not exceed the platform maximum (default 24 h); approved_by must differ from the requester (dual control)"
      },
      "DispositionCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "dead_letter_id",
          "resolution",
          "operator_ref",
          "remediation_notes",
          "expected_version"
        ],
        "properties": {
          "dead_letter_id": {
            "type": "string",
            "format": "uuid"
          },
          "resolution": {
            "enum": [
              "requeue",
              "discard",
              "hold"
            ]
          },
          "operator_ref": {
            "type": "string",
            "format": "uuid"
          },
          "remediation_notes": {
            "type": "string",
            "minLength": 1,
            "maxLength": 8192
          },
          "retry_after": {
            "type": "string",
            "format": "date-time",
            "description": "Only with requeue"
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        },
        "description": "retry_after is only valid with resolution requeue (422 with the message as detail)"
      },
      "EndpointCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "subscriber_org",
          "url"
        ],
        "properties": {
          "subscriber_org": {
            "type": "string",
            "format": "uuid"
          },
          "url": {
            "type": "string",
            "minLength": 1,
            "maxLength": 2048,
            "description": "https only to public hosts; no credentials or fragment. Loopback and private hosts are refused unless the non-production switch is on"
          },
          "description": {
            "type": "string",
            "maxLength": 200
          }
        }
      },
      "SchemaCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "event_type",
          "schema_version",
          "payload_schema"
        ],
        "properties": {
          "event_type": {
            "type": "string",
            "maxLength": 128,
            "pattern": "^[a-z][a-z0-9_]*(\\.[a-z][a-z0-9_]*)+$"
          },
          "schema_version": {
            "type": "string",
            "pattern": "^\\d+\\.\\d+\\.\\d+$"
          },
          "payload_schema": {
            "type": "object",
            "description": "JSON-Schema subset: type, required, properties, additionalProperties (must be false at the root), enum, items, minLength, maxLength, minimum, maximum, description, format, title, $schema"
          },
          "description": {
            "type": "string",
            "maxLength": 500
          }
        }
      },
      "TransitionCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "to_status",
          "expected_version",
          "reason"
        ],
        "properties": {
          "to_status": {
            "enum": [
              "active",
              "paused",
              "revoked"
            ]
          },
          "expected_version": {
            "type": "integer",
            "minimum": 1
          },
          "reason": {
            "type": "string",
            "minLength": 10,
            "maxLength": 4096
          }
        }
      },
      "PullCommand": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "limit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 10
          }
        }
      },
      "ReplayStartCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "expected_version"
        ],
        "properties": {
          "expected_version": {
            "type": "integer",
            "minimum": 1
          }
        }
      },
      "SimulateCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "scope",
          "event_type",
          "event_classification"
        ],
        "properties": {
          "scope": {
            "type": "string",
            "minLength": 1,
            "maxLength": 8192
          },
          "event_type": {
            "type": "string",
            "maxLength": 128
          },
          "event_classification": {
            "$ref": "#/components/schemas/Classification"
          },
          "event_organization": {
            "type": "string",
            "format": "uuid"
          },
          "subscription_status": {
            "enum": [
              "active",
              "paused",
              "revoked"
            ]
          }
        }
      },
      "ExportCommand": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "format"
        ],
        "properties": {
          "format": {
            "enum": [
              "csv",
              "pdf"
            ]
          },
          "filters": {
            "type": "object",
            "description": "The report filters (period_from, period_to, subscriber, event_type, service, cursor), string values of at most 128 characters; anything else is 422 Report filter is not valid",
            "additionalProperties": {
              "type": "string",
              "maxLength": 128
            }
          }
        }
      }
    }
  }
}
