openapi: 3.1.0
info:
  title: OHN-48 Data Lifecycle and Legal Preservation
  version: 1.0.0
  description: |
    Executable contract for OHN-48. Configurable retention schedules (OHN-48-W001), immutable legal holds (OHN-48-W002),
    dual-approved disposal with signed deletion receipts (OHN-48-W003), archive integrity verification and the
    OHN-48-R001..R003 reports. Inventory mapping (ADR-0001 §1):
      - OHN-48-API-001 POST /api/ohn/v1/retention/policies -> POST /api/ohn/v1/data-lifecycle/retention/policies (form OHN-48-F001)
      - OHN-48-API-002 POST /api/ohn/v1/legal-holds       -> POST /api/ohn/v1/data-lifecycle/legal-holds (form OHN-48-F002)
      - OHN-48-API-003 POST /api/ohn/v1/disposal-requests -> POST /api/ohn/v1/data-lifecycle/disposal-requests (form OHN-48-F003)
      - OHN-48-API-004 GET  /api/ohn/v1/archives          -> GET  /api/ohn/v1/data-lifecycle/archives (form OHN-48-F004 posts to /archive-verifications)
    Every non-GET request requires an Idempotency-Key header. Every query is scoped to the token's jurisdiction and
    organisation. Every write checks the jurisdiction live in OHN-01 first. Errors: 400 malformed/missing key,
    401 unauthenticated, 403 denied_by_policy | jurisdiction_unavailable | jurisdiction_mismatch | self_approval |
    not_named_approver | approval_rule_denied | approver_cannot_execute, 404 not_found, 409 concurrent_mutation |
    invalid_transition | legal_hold_active | idempotency_conflict | evidence_immutable, 422 domain_validation_failed |
    legal_minimum_not_configured | retention_below_legal_minimum | privacy_governance_denied | retention_not_elapsed |
    non_disposable_class, 429 rate_limited, 503 dependency_unavailable (details name the dependency and the reason) | server_unavailable.
    A 202 means the local fact committed but OHN-18 audit forwarding failed (pending reconciliation).

    Java service (operations, reconciled with the observed TypeScript behaviour; see docs/program/java/ohn-48-contract-changes.md): tokens come
    from the platform gateway only (ES256, iss ohn-platform-gateway, aud ohn-48; the synthetic sign-in routes of the reference are not part of
    this contract); errors are application/problem+json carrying the reference's error and message (and details); 413 payload_too_large and
    400 malformed_request are the body-reader refusals; a path id that is not a UUID is 404. Fail closed: disposal, export and approval steps
    are refused (503 dependency_unavailable) when OHN-01, OHN-20 or OHN-45 cannot confirm, and nothing is deleted when a legal hold covers a
    record set or cannot be ruled out. No retention period, legal minimum or legal basis ships with the module: they are configuration entered
    by a legal officer and decided by OHN-20 (flagged for human review, docs/program/OWNER-BLOCKERS.md B525).
servers:
  - url: /
security:
  - bearer: []
tags:
  - name: retention
  - name: legal-holds
  - name: disposal
  - name: archives
  - name: reports
  - name: platform
paths:
  /health/ohn-48:
    get:
      operationId: ohn48_health
      tags: [platform]
      security: []
      summary: Liveness, the policy version and each dependency's mode. Public; 503 when the database is unavailable. (The reference's synthetic_auth field is gone with the synthetic sign-in.)
      responses:
        '200': { description: OK, content: { application/json: { schema: { $ref: '#/components/schemas/Health' } } } }
        '503': { description: Database unavailable, content: { application/json: { schema: { $ref: '#/components/schemas/Health' } } } }
  /api/ohn/v1/data-lifecycle/health:
    get:
      operationId: ohn48_serviceHealth
      tags: [platform]
      security: []
      summary: Public service liveness with each dependency's mode (live | synthetic-fake | unconfigured).
      responses:
        '200': { description: OK, content: { application/json: { schema: { type: object, required: [status, service, version, dependencies], properties: { status: { const: ok }, service: { const: OHN-48 }, version: { const: 1.0.0 }, dependencies: { $ref: '#/components/schemas/DependencyModes' } } } } } }
  /api/ohn/v1/data-lifecycle/code-lists:
    get:
      operationId: ohn48_codeLists
      tags: [platform]
      responses: { '200': { description: Controlled vocabularies v1.0.0, dependency modes and policy } }
  /api/ohn/v1/data-lifecycle/legal-minimums:
    get:
      operationId: ohn48_listLegalMinimums
      tags: [retention]
      responses: { '200': { description: Configured minimums and the record classes still missing one } }
    post:
      operationId: ohn48_configureLegalMinimum
      tags: [retention]
      summary: Legal officer configures the legal minimum retention for a record class (configuration, not code).
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/LegalMinimumCommand' } } } }
      responses:
        '201': { $ref: '#/components/responses/Committed' }
        '403': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/data-lifecycle/record-sets:
    get:
      operationId: ohn48_listRecordSets
      tags: [disposal]
      parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { $ref: '#/components/parameters/Status' }, { $ref: '#/components/parameters/RecordClass' }, { $ref: '#/components/parameters/Sort' }]
      responses: { '200': { $ref: '#/components/responses/Page' } }
    post:
      operationId: ohn48_registerRecordSet
      tags: [disposal]
      summary: Register a SYNTHETIC record set (synthetic must be true; the database rejects anything else).
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/RecordSetCommand' } } } }
      responses:
        '201': { $ref: '#/components/responses/Committed' }
        '422': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/data-lifecycle/record-sets/{id}:
    get:
      operationId: ohn48_getRecordSet
      tags: [disposal]
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses: { '200': { description: Record set with item count, content hash and covering holds }, '404': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/retention/policies:
    get:
      operationId: ohn48_listRetentionPolicies
      tags: [retention]
      parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { $ref: '#/components/parameters/Status' }, { $ref: '#/components/parameters/RecordClass' }, { $ref: '#/components/parameters/Sort' }]
      responses: { '200': { $ref: '#/components/responses/Page' } }
    post:
      operationId: ohn48_createRetentionPolicy
      tags: [retention]
      summary: OHN-48-API-001 / form OHN-48-F001 - draft a retention schedule (W001 enters at draft).
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/RetentionPolicyCommand' } } } }
      responses:
        '201': { $ref: '#/components/responses/Committed' }
        '202': { $ref: '#/components/responses/Committed' }
        '400': { $ref: '#/components/responses/Error' }
        '401': { $ref: '#/components/responses/Error' }
        '403': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '429': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/data-lifecycle/retention/policies/{id}:
    get:
      operationId: ohn48_getRetentionPolicy
      tags: [retention]
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses: { '200': { description: Schedule with legal minimum and history }, '404': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/retention/policies/{id}/transitions:
    post:
      operationId: ohn48_transitionRetentionPolicy
      tags: [retention]
      summary: |
        OHN-48-W001 draft -> legal_review -> approved -> effective -> superseded (legal_review -> draft allowed).
        approved: legal_officer only, not the author; requires a configured legal minimum, retention >= minimum and an
        OHN-20 permit (contract ohn20.retention-decision/1.0.0). effective supersedes the current effective schedule.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/TransitionCommand' } } } }
      responses:
        '200': { $ref: '#/components/responses/Committed' }
        '403': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/data-lifecycle/retention-calendar:
    get:
      operationId: ohn48_getRetentionCalendar
      tags: [retention]
      summary: Screen OHN-48-P001 - each record set with its effective schedule, archive due, retention due and hold status.
      parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { $ref: '#/components/parameters/RecordClass' },
        { name: status, in: query, schema: { enum: [retained, disposal_eligible, on_hold, no_effective_schedule, disposed] } }, { name: q, in: query, schema: { type: string, maxLength: 200 } }, { $ref: '#/components/parameters/Sort' }]
      responses: { '200': { $ref: '#/components/responses/Page' } }
  /api/ohn/v1/data-lifecycle/legal-holds:
    get:
      operationId: ohn48_listLegalHolds
      tags: [legal-holds]
      summary: Screen OHN-48-P002 legal hold queue.
      parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { $ref: '#/components/parameters/Status' }, { name: case_reference, in: query, schema: { type: string, format: uuid } }, { $ref: '#/components/parameters/Sort' }]
      responses: { '200': { $ref: '#/components/responses/Page' } }
    post:
      operationId: ohn48_placeLegalHold
      tags: [legal-holds]
      summary: OHN-48-API-002 / form OHN-48-F002 - request a hold. It blocks disposal immediately (any state but released). Emits legal-hold.placed.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/LegalHoldCommand' } } } }
      responses:
        '201': { $ref: '#/components/responses/Committed' }
        '422': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/data-lifecycle/legal-holds/{id}:
    get:
      operationId: ohn48_getLegalHold
      tags: [legal-holds]
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses: { '200': { description: Hold with history }, '404': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/legal-holds/{id}/scope-preview:
    get:
      operationId: ohn48_previewLegalHoldScope
      tags: [legal-holds]
      summary: Screen OHN-48-P005 - covered record sets, blocked disposals, archives, unresolved refs, history.
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses: { '200': { description: Scope preview }, '404': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/legal-holds/{id}/transitions:
    post:
      operationId: ohn48_transitionLegalHold
      tags: [legal-holds]
      summary: OHN-48-W002 hold_requested -> scope_approved -> effective <-> periodic_review -> released (legal_officer; scope approver != placer; effective/periodic_review need a future next_review_at; released is terminal).
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/TransitionCommand' } } } }
      responses:
        '200': { $ref: '#/components/responses/Committed' }
        '403': { $ref: '#/components/responses/Error' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/data-lifecycle/disposal-requests:
    get:
      operationId: ohn48_listDisposalRequests
      tags: [disposal]
      parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { $ref: '#/components/parameters/Status' }, { $ref: '#/components/parameters/RecordClass' }, { $ref: '#/components/parameters/Sort' }]
      responses: { '200': { $ref: '#/components/responses/Page' } }
    post:
      operationId: ohn48_createDisposalRequest
      tags: [disposal]
      summary: OHN-48-API-003 / form OHN-48-F003 - request disposal (W003 eligible). Requester cannot be an approver; retention must have elapsed under an effective schedule; no covering hold; audit_evidence is never disposable.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/DisposalRequestCommand' } } } }
      responses:
        '201': { $ref: '#/components/responses/Committed' }
        '409': { $ref: '#/components/responses/Error' }
        '422': { $ref: '#/components/responses/Error' }
        '503': { $ref: '#/components/responses/Error' }
  /api/ohn/v1/data-lifecycle/disposal-requests/{id}:
    get:
      operationId: ohn48_getDisposalRequest
      tags: [disposal]
      summary: Screen OHN-48-P006 - request, approval rule, covering holds, deletion receipt and history.
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses: { '200': { description: Disposal request }, '404': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/disposal-requests/{id}/hold-check:
    post:
      operationId: ohn48_holdCheckDisposal
      tags: [disposal]
      summary: eligible -> hold_checked. No unreleased hold may cover the set and OHN-20 must permit disposal.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/VersionCommand' } } } }
      responses: { '200': { $ref: '#/components/responses/Committed' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' }, '503': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/disposal-requests/{id}/approvals:
    post:
      operationId: ohn48_approveDisposal
      tags: [disposal]
      summary: Two-person approval by the two named approvers (dual_records_legal = one records_manager + one legal_officer; dual_legal_only = two legal officers). The second approval moves hold_checked -> dual_approved.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ApprovalCommand' } } } }
      responses: { '200': { $ref: '#/components/responses/Committed' }, '403': { $ref: '#/components/responses/Error' }, '409': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/disposal-requests/{id}/execute:
    post:
      operationId: ohn48_executeDisposal
      tags: [disposal]
      summary: dual_approved -> executed (records_manager, not an approver, confirmation DISPOSE). Re-checks holds and eligibility, signs the deletion receipt and registers it in OHN-45 BEFORE deleting the synthetic items. Emits disposal.completed.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ExecuteCommand' } } } }
      responses: { '200': { $ref: '#/components/responses/Committed' }, '403': { $ref: '#/components/responses/Error' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' }, '503': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/disposal-requests/{id}/preserve-receipt:
    post:
      operationId: ohn48_preserveDeletionReceipt
      tags: [disposal]
      summary: executed -> receipt_preserved once OHN-45 verifies the receipt signature.
      parameters: [{ $ref: '#/components/parameters/Id' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/VersionCommand' } } } }
      responses: { '200': { $ref: '#/components/responses/Committed' }, '409': { $ref: '#/components/responses/Error' }, '503': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/archives:
    get:
      operationId: ohn48_listArchives
      tags: [archives]
      summary: OHN-48-API-004 - archive manifests plus KPI tiles, 30-day verification trend and exception worklist (screen OHN-48-P004).
      parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { $ref: '#/components/parameters/Status' }, { $ref: '#/components/parameters/RecordClass' }, { $ref: '#/components/parameters/Sort' }]
      responses: { '200': { $ref: '#/components/responses/Page' } }
    post:
      operationId: ohn48_registerArchive
      tags: [archives]
      summary: Archive an active record set under the effective schedule; the content hash and count are computed server-side.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ArchiveCommand' } } } }
      responses: { '201': { $ref: '#/components/responses/Committed' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/archives/{id}:
    get:
      operationId: ohn48_getArchive
      tags: [archives]
      parameters: [{ $ref: '#/components/parameters/Id' }]
      responses: { '200': { description: Manifest with verifications }, '404': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/archive-verifications:
    post:
      operationId: ohn48_verifyArchive
      tags: [archives]
      summary: Form OHN-48-F004 (screen OHN-48-P007) - match iff expected_hash equals the manifest hash AND the stored content still hashes to it.
      parameters: [{ $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ArchiveVerificationCommand' } } } }
      responses: { '201': { $ref: '#/components/responses/Committed' }, '404': { $ref: '#/components/responses/Error' }, '409': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/reports/{reportId}:
    get:
      operationId: ohn48_getReport
      tags: [reports]
      summary: OHN-48-R001 retention schedule coverage, OHN-48-R002 legal holds in effect, OHN-48-R003 disposal and archival evidence (formulas in metric_definitions and ADR-0001 §6).
      parameters:
        - { $ref: '#/components/parameters/ReportId' }
        - { name: country, in: query, schema: { type: string, format: uuid } }
        - { $ref: '#/components/parameters/RecordClass' }
        - { $ref: '#/components/parameters/Status' }
        - { name: case, in: query, schema: { type: string, format: uuid } }
        - { name: period_from, in: query, schema: { type: string, format: date-time } }
        - { name: period_to, in: query, schema: { type: string, format: date-time } }
      responses: { '200': { description: Report with rows, metrics, metric_definitions and provenance }, '404': { $ref: '#/components/responses/Error' }, '422': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/reports/{reportId}/export:
    post:
      operationId: ohn48_createExport
      tags: [reports]
      summary: Audited CSV/PDF export, Ed25519-signed and registered in OHN-45; one-time retrieval link. 503 when OHN-45 or the signing key is not configured.
      parameters: [{ $ref: '#/components/parameters/ReportId' }, { $ref: '#/components/parameters/IdempotencyKey' }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: '#/components/schemas/ExportCommand' } } } }
      responses: { '201': { $ref: '#/components/responses/Committed' }, '503': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/exports/{token}:
    get:
      operationId: ohn48_downloadExport
      tags: [reports]
      summary: One-time download by the requesting principal; X-OHN-Export-Signature carries the Ed25519 signature.
      parameters: [{ name: token, in: path, required: true, schema: { type: string } }]
      responses: { '200': { description: File, content: { text/csv: {}, application/pdf: {} } }, '404': { $ref: '#/components/responses/Error' } }
  /api/ohn/v1/data-lifecycle/audit-records:
    get:
      operationId: ohn48_listAuditRecords
      tags: [platform]
      parameters: [{ $ref: '#/components/parameters/PageSize' }, { $ref: '#/components/parameters/Cursor' }, { name: status, in: query, schema: { enum: [committed, denied] } }]
      responses: { '200': { $ref: '#/components/responses/Page' } }
components:
  securitySchemes:
    bearer: { type: http, scheme: bearer, bearerFormat: 'Gateway JWT (ES256) iss=ohn-platform-gateway aud=ohn-48; claims sub (uuid), role, jurisdiction (uuid), organization_id (uuid), purpose' }
  parameters:
    IdempotencyKey: { name: Idempotency-Key, in: header, required: true, schema: { type: string, minLength: 1, maxLength: 255 } }
    Id: { name: id, in: path, required: true, schema: { type: string, format: uuid } }
    ReportId: { name: reportId, in: path, required: true, schema: { enum: [OHN-48-R001, OHN-48-R002, OHN-48-R003] } }
    PageSize: { name: page_size, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 25 } }
    Cursor: { name: cursor, in: query, schema: { type: string, maxLength: 64 } }
    Status: { name: status, in: query, schema: { type: string, maxLength: 64 } }
    RecordClass: { name: record_class, in: query, schema: { $ref: '#/components/schemas/RecordClass' } }
    Sort: { name: sort, in: query, schema: { enum: [created_at, -created_at, updated_at, -updated_at] } }
  responses:
    Error:
      description: Error
      content: { application/json: { schema: { $ref: '#/components/schemas/Error' } } }
    Committed:
      description: Committed state change with an audit receipt (202 = audit forwarding to OHN-18 failed, pending reconciliation).
      content: { application/json: { schema: { type: object, required: [receipt], properties: { receipt: { $ref: '#/components/schemas/Receipt' }, pending_downstream: { type: boolean } }, additionalProperties: true } } }
    Page:
      description: Page of rows
      content: { application/json: { schema: { type: object, required: [data, next_cursor, provenance], properties: { data: { type: array, items: { type: object } }, next_cursor: { type: [string, 'null'] }, total: { type: integer }, provenance: { $ref: '#/components/schemas/Provenance' } } } } }
  schemas:
    Uuid: { type: string, format: uuid }
    RecordClass: { enum: [clinical_record, imaging, laboratory, billing, consent, correspondence, research, audit_evidence] }
    DisposalApprovalRule: { enum: [dual_records_legal, dual_legal_only] }
    Error:
      description: 'application/problem+json, a superset of the reference {error, message, details}. details: for a 422 the first failing check per top-level field as a zod issue code (invalid_type, too_small, too_big, invalid_string, invalid_enum_value, invalid_literal, not_multiple_of, custom; unrecognized_keys under _); for a 503 dependency_unavailable {dependency, reason: unconfigured or unreachable or bad_response}; for a stale expected_version {current_version}.'
      type: object
      required: [error]
      properties: { type: { type: string }, title: { type: string }, status: { type: integer }, detail: { type: string }, error: { type: string }, message: { type: string }, trace_id: { type: string }, details: { type: object, additionalProperties: true } }
    Receipt:
      type: object
      required: [receipt_id, committed_at, aggregate_id, aggregate_type, version, status, audit_forwarding, policy_version]
      properties:
        receipt_id: { $ref: '#/components/schemas/Uuid' }
        committed_at: { type: string, format: date-time }
        aggregate_id: { $ref: '#/components/schemas/Uuid' }
        aggregate_type: { type: string }
        version: { type: integer }
        status: { const: committed }
        audit_forwarding: { enum: [forwarded, pending, failed] }
        policy_version: { type: string }
    Provenance: { type: object, properties: { source: { type: string }, source_version: { type: string }, generated_at: { type: string, format: date-time }, completeness: { enum: [complete, partial] } } }
    DependencyModes:
      type: object
      required: [OHN-01, OHN-18, OHN-20, OHN-45]
      properties: { OHN-01: { $ref: '#/components/schemas/DependencyMode' }, OHN-18: { $ref: '#/components/schemas/DependencyMode' }, OHN-20: { $ref: '#/components/schemas/DependencyMode' }, OHN-45: { $ref: '#/components/schemas/DependencyMode' } }
    DependencyMode: { enum: [live, synthetic-fake, unconfigured], description: 'live = HTTP contract client configured; synthetic-fake = test double (ohn.m48.synthetic-gateways=true only); unconfigured = fail closed (503 dependency_unavailable; OHN-18 forwarding stays pending)' }
    Health: { type: object, required: [status, module, dependencies], properties: { status: { enum: [ok, unavailable] }, module: { const: OHN-48 }, version: { const: 1.0.0 }, policy_version: { type: string }, dependencies: { $ref: '#/components/schemas/DependencyModes' } } }
    LegalMinimumCommand:
      type: object
      additionalProperties: false
      required: [jurisdiction_id, record_class, min_retention_years, authority_ref]
      properties: { jurisdiction_id: { $ref: '#/components/schemas/Uuid' }, record_class: { $ref: '#/components/schemas/RecordClass' }, min_retention_years: { type: number, minimum: 0, maximum: 1000 }, authority_ref: { $ref: '#/components/schemas/Uuid' } }
    RecordSetCommand:
      type: object
      additionalProperties: false
      required: [label, record_class, retention_start_at, synthetic, items]
      properties: { label: { type: string, minLength: 1, maxLength: 200 }, record_class: { $ref: '#/components/schemas/RecordClass' }, retention_start_at: { type: string, format: date-time }, synthetic: { const: true }, items: { type: array, minItems: 1, maxItems: 1000, items: { type: string, maxLength: 4096 } } }
    RetentionPolicyCommand:
      description: Form OHN-48-F001 Retention schedule.
      type: object
      additionalProperties: false
      required: [jurisdiction_id, record_class, legal_authority_ref, retention_years, archive_after_days, disposal_approval_rule]
      properties:
        jurisdiction_id: { $ref: '#/components/schemas/Uuid' }
        record_class: { $ref: '#/components/schemas/RecordClass' }
        legal_authority_ref: { $ref: '#/components/schemas/Uuid' }
        retention_years: { type: number, minimum: 0, maximum: 1000, multipleOf: 0.01 }
        archive_after_days: { type: integer, minimum: 0, maximum: 36500 }
        disposal_approval_rule: { $ref: '#/components/schemas/DisposalApprovalRule' }
    LegalHoldCommand:
      description: Form OHN-48-F002 Legal hold placement. placed_by must equal the signed-in principal. Without record_set_refs the hold covers the whole organisation.
      type: object
      additionalProperties: false
      required: [subject_or_record_scope, case_reference, authority_ref, reason, placed_by]
      properties:
        subject_or_record_scope: { type: string, minLength: 1, maxLength: 8192 }
        record_set_refs: { type: array, maxItems: 500, items: { $ref: '#/components/schemas/Uuid' } }
        case_reference: { $ref: '#/components/schemas/Uuid' }
        authority_ref: { $ref: '#/components/schemas/Uuid' }
        reason: { type: string, minLength: 10, maxLength: 4096 }
        placed_by: { $ref: '#/components/schemas/Uuid' }
    DisposalRequestCommand:
      description: Form OHN-48-F003 Disposal request. approval_a != approval_b != requester.
      type: object
      additionalProperties: false
      required: [record_set_ref, retention_policy, eligibility_evidence, approval_a, approval_b]
      properties: { record_set_ref: { $ref: '#/components/schemas/Uuid' }, retention_policy: { $ref: '#/components/schemas/Uuid' }, eligibility_evidence: { $ref: '#/components/schemas/Uuid' }, approval_a: { $ref: '#/components/schemas/Uuid' }, approval_b: { $ref: '#/components/schemas/Uuid' } }
    ArchiveCommand:
      type: object
      additionalProperties: false
      required: [record_set_ref, retention_policy, storage_tier, evidence_ref]
      properties: { record_set_ref: { $ref: '#/components/schemas/Uuid' }, retention_policy: { $ref: '#/components/schemas/Uuid' }, storage_tier: { enum: [warm, cold, deep_archive] }, evidence_ref: { $ref: '#/components/schemas/Uuid' } }
    ArchiveVerificationCommand:
      description: Form OHN-48-F004 Archive integrity verification.
      type: object
      additionalProperties: false
      required: [archive_manifest_id, expected_hash, verification_at, evidence_ref]
      properties: { archive_manifest_id: { $ref: '#/components/schemas/Uuid' }, expected_hash: { type: string, maxLength: 512, pattern: '^([A-Fa-f0-9]{64}|sha256:[A-Fa-f0-9]{64})$' }, verification_at: { type: string, format: date-time }, evidence_ref: { $ref: '#/components/schemas/Uuid' } }
    TransitionCommand:
      type: object
      additionalProperties: false
      required: [expected_version, to_state, evidence_ref, reason]
      properties: { expected_version: { type: integer, minimum: 1 }, to_state: { type: string, minLength: 1, maxLength: 64 }, evidence_ref: { $ref: '#/components/schemas/Uuid' }, reason: { type: string, minLength: 10, maxLength: 4096 }, next_review_at: { type: string, format: date-time } }
    VersionCommand: { type: object, additionalProperties: false, required: [expected_version], properties: { expected_version: { type: integer, minimum: 1 } } }
    ApprovalCommand: { type: object, additionalProperties: false, required: [expected_version, decision, reason], properties: { expected_version: { type: integer, minimum: 1 }, decision: { const: approve }, reason: { type: string, minLength: 10, maxLength: 4096 } } }
    ExecuteCommand: { type: object, additionalProperties: false, required: [expected_version, confirmation, reason], properties: { expected_version: { type: integer, minimum: 1 }, confirmation: { const: DISPOSE }, reason: { type: string, minLength: 10, maxLength: 4096 } } }
    ExportCommand:
      type: object
      additionalProperties: false
      required: [format]
      properties: { format: { enum: [csv, pdf] }, country: { $ref: '#/components/schemas/Uuid' }, record_class: { $ref: '#/components/schemas/RecordClass' }, status: { type: string }, case: { $ref: '#/components/schemas/Uuid' }, period_from: { type: string, format: date-time }, period_to: { type: string, format: date-time } }
