openapi: 3.0.3
info:
  title: Zuia API
  version: 1.0.0
  description: |
    Sanctions list monitoring and due diligence engine (UN Security Council Consolidated List and CMC communications).

    **Authentication.** Every `/api/v1` operation except the public `auth/*` operations and `desktop/latest` needs
    either a bearer token or a scoped API key in `X-API-Key`. Tokens come from one of three sign-in modes
    (`GET /api/v1/auth/config` says which): `oidc` (e.g. Microsoft Entra ID — people with authorization code + PKCE,
    systems with OAuth2 client credentials), `local` (user name, password and an authenticator-app code, see below)
    or `dev` (demo users). Roles: `ADMIN`, `COMPLIANCE_OFFICER`, `COMPLIANCE_REVIEWER`, `BROKER`, `AUDITOR`, `STAFF`.

    **Local sign-in.** `POST /auth/login` checks the password and returns the next step: `MFA_REQUIRED` (send the
    6-digit code or a recovery code to `/auth/mfa/verify`) or `MFA_ENROLLMENT_REQUIRED` (scan the QR code, then
    `/auth/mfa/enroll`). The answer to a wrong user name, wrong password or disabled account is the same
    (`401 auth.invalidCredentials`). After repeated failures the identifier is locked (`429 auth.locked` with
    `Retry-After`), whether or not the account exists. Sessions are checked on the server at every call and end
    after inactivity, at their maximum age, on `/auth/logout`, on a password change or reset, or when the account
    is disabled. `/auth/password/forgot` always answers `202`; the e-mailed link carries a single-use token in the
    URL fragment.

    **Errors.** Errors are `application/problem+json` (RFC 9457) with the standard members `type`, `title`,
    `status`, `detail`, `instance` and the extension members `code`, `message` and `correlationId`. `401`
    answers include `WWW-Authenticate` (RFC 6750); `429` answers include `Retry-After`.

    **Caching.** API responses are sent with `Cache-Control: no-store`.

    **Language.** Error messages follow `Accept-Language` (`pt-AO` default, `en`).

    **Tracing.** Send `X-Correlation-ID` to have it recorded in the audit log; it is echoed in every response.

    **Idempotency.** Screening calls accept an `Idempotency-Key` header (8–128 characters). Repeating a call with the
    same key returns the original result.

    **Pagination.** Collections (cases, screenings, audit, users, circulars, list updates, inbox, …) take
    `offset` (default 0) and `limit` (default 100, at most 1000). The body is the JSON array for that page;
    `X-Total-Count` gives the total number of matching items and `Link` (RFC 8288) the `first`, `prev`, `next`
    and `last` pages. Follow `rel="next"` until it is absent to read everything.

    **Rate limits.** Requests are limited per client (default 300 per minute); over the limit returns `429`.
  contact:
    name: Direcção de Compliance
servers:
  - url: /
security:
  - bearerAuth: []
  - apiKey: []
tags:
  - name: auth
  - name: me
  - name: lists
  - name: circulars
  - name: screening
  - name: cases
  - name: reports
  - name: admin

paths:
  /api/v1/auth/config:
    get:
      tags: [auth]
      summary: How clients should sign in (OIDC endpoints, or demo users in dev mode)
      security: []
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/AuthConfig" } } } }
  /api/v1/auth/dev-login:
    post:
      tags: [auth]
      summary: Dev mode only — issue a token for a demo user
      security: []
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/DevLoginRequest" } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/TokenResponse" } } } }
        "404": { $ref: "#/components/responses/Error" }
  /api/v1/auth/login:
    post:
      tags: [auth]
      summary: Local sign-in — check user name and password (auth.mode=local)
      security: []
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/LoginRequest" } } } }
      responses:
        "200": { description: Next step, content: { application/json: { schema: { $ref: "#/components/schemas/LoginResponse" } } } }
        "401": { $ref: "#/components/responses/Error" }
        "404": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /api/v1/auth/mfa/verify:
    post:
      tags: [auth]
      summary: Local sign-in — second step with the authenticator code or a recovery code
      security: []
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/MfaCodeRequest" } } } }
      responses:
        "200": { description: Signed in, content: { application/json: { schema: { $ref: "#/components/schemas/LoginResponse" } } } }
        "401": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /api/v1/auth/mfa/enroll:
    post:
      tags: [auth]
      summary: Local sign-in — confirm the authenticator app with its first code; returns recovery codes once
      security: []
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/MfaCodeRequest" } } } }
      responses:
        "200": { description: Signed in, content: { application/json: { schema: { $ref: "#/components/schemas/LoginResponse" } } } }
        "401": { $ref: "#/components/responses/Error" }
  /api/v1/auth/password/forgot:
    post:
      tags: [auth]
      summary: Request a password reset link by e-mail (always 202, whether or not the account exists)
      security: []
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/ForgotPasswordRequest" } } } }
      responses:
        "202": { description: Accepted, content: { application/json: { schema: { $ref: "#/components/schemas/AcceptedResponse" } } } }
        "429": { $ref: "#/components/responses/Error" }
  /api/v1/auth/password/reset/check:
    post:
      tags: [auth]
      summary: Check a reset or invitation link before showing the new-password form
      security: []
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/ResetTokenRequest" } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/ResetTokenInfo" } } } }
  /api/v1/auth/password/reset:
    post:
      tags: [auth]
      summary: Choose a new password with a reset or invitation link (ends every session of the account)
      security: []
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/ResetPasswordRequest" } } } }
      responses:
        "204": { description: Password set }
        "400": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /api/v1/auth/session:
    get:
      tags: [auth]
      summary: The current local session (timeouts), keeps it alive
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/SessionInfo" } } } }
        "401": { $ref: "#/components/responses/Error" }
  /api/v1/auth/logout:
    post:
      tags: [auth]
      summary: Sign out (ends the local session on the server)
      responses:
        "204": { description: Signed out }
  /api/v1/me/password:
    post:
      tags: [me]
      summary: Change my password (local sign-in); other sessions are signed out
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/ChangePasswordRequest" } } } }
      responses:
        "204": { description: Password changed }
        "400": { $ref: "#/components/responses/Error" }
        "422": { $ref: "#/components/responses/Error" }
  /api/v1/desktop/latest:
    get:
      tags: [auth]
      summary: Latest desktop app version and installer links (auto-update check)
      security: []
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/DesktopRelease" } } } }

  /api/v1/me:
    get:
      tags: [me]
      summary: The signed-in user, roles and preferences
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Me" } } } }
        "401": { $ref: "#/components/responses/Error" }
  /api/v1/me/preferences:
    put:
      tags: [me]
      summary: Save language and theme (applied at next sign-in)
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/PreferencesUpdate" } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Me" } } } }
  /api/v1/me/avatar:
    post:
      tags: [me]
      summary: Upload the caller's profile picture (PNG, JPEG or WebP, up to 2 MB; raw body with its Content-Type)
      requestBody:
        required: true
        content:
          image/png: { schema: { type: string, format: binary } }
          image/jpeg: { schema: { type: string, format: binary } }
          image/webp: { schema: { type: string, format: binary } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Me" } } } }
        "409": { $ref: "#/components/responses/Error" }
    delete:
      tags: [me]
      summary: Remove the caller's profile picture
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Me" } } } }
  /api/v1/users/{id}/avatar:
    get:
      tags: [me]
      summary: A user's profile picture (any signed-in user)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: Image, content: { image/*: { schema: { type: string, format: binary } } } }
        "404": { $ref: "#/components/responses/Error" }
  /api/v1/dashboard:
    get:
      tags: [me]
      summary: Home dashboard data for the caller's role
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Dashboard" } } } }
  /api/v1/inbox:
    get:
      tags: [me]
      summary: In-app inbox (circulars and urgent alerts)
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/InboxItem" } } } } }
        "400": { $ref: "#/components/responses/Error" }

  /api/v1/sources:
    get:
      tags: [lists]
      summary: Source health, current version and last check
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/SourceStatus" } } } } }
  /api/v1/sources/{id}/check:
    post:
      tags: [lists]
      summary: Download and compare a source now (Compliance)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { changed: { type: string }, updateId: { type: string } } } } } }
        "409": { $ref: "#/components/responses/Error" }
  /api/v1/sources/{id}/upload:
    post:
      tags: [lists]
      summary: Upload a new version of a hand-kept list (CSV, e.g. the Angolan domestic list ao-domestic). Compared at once.
      parameters:
        - { $ref: "#/components/parameters/Id" }
        - { name: fileName, in: query, schema: { type: string } }
      requestBody: { required: true, content: { text/csv: { schema: { type: string, format: binary } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { changed: { type: string }, updateId: { type: string } } } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/sources/{id}/template:
    get:
      tags: [lists]
      summary: CSV header for a hand-kept list
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: CSV, content: { text/csv: { schema: { type: string } } } }
  /api/v1/lists/updates:
    get:
      tags: [lists]
      summary: List updates and CMC communications, newest first
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/ListUpdateSummary" } } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/lists/updates/{id}:
    get:
      tags: [lists]
      summary: One update with its field-level delta
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/ListUpdateDetail" } } } }
        "404": { $ref: "#/components/responses/Error" }
  /api/v1/lists/{sourceId}/entries:
    get:
      tags: [lists]
      summary: Search the current list
      parameters:
        - { name: sourceId, in: path, required: true, schema: { type: string, example: un-consolidated } }
        - { name: q, in: query, schema: { type: string } }
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit200" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/ListEntry" } } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/lists/evidence/{sha256}:
    get:
      tags: [lists]
      summary: Raw downloaded list file, exactly as received (evidence for the CMC)
      parameters: [ { name: sha256, in: path, required: true, schema: { type: string } } ]
      responses:
        "200": { description: The XML file, content: { application/xml: { schema: { type: string, format: binary } } } }
        "404": { $ref: "#/components/responses/Error" }
  /api/v1/cmc-communications:
    get:
      tags: [lists]
      summary: Registered CMC communications
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/CmcCommunication" } } } } }
        "400": { $ref: "#/components/responses/Error" }
    post:
      tags: [lists]
      summary: Register a CMC communication (Compliance). Drafts a circular.
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/CmcCommunicationRequest" } } } }
      responses:
        "201": { description: Created, content: { application/json: { schema: { $ref: "#/components/schemas/ListUpdateSummary" } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/demo/cmc-communication:
    get:
      tags: [lists]
      summary: Demo mode only — the FAKE demo CMC communication, to prefill the form
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/CmcCommunicationRequest" } } } }

  /api/v1/circulars:
    get:
      tags: [circulars]
      summary: Circulars (drafts only for Compliance and auditors)
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/Circular" } } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/circulars/{id}:
    get:
      tags: [circulars]
      summary: One circular with every language rendition (template preview)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Circular" } } } }
  /api/v1/circulars/{id}/send:
    post:
      tags: [circulars]
      summary: Send a draft to distribution lists (Compliance)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/SendCircularRequest" } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Circular" } } } }
        "409": { $ref: "#/components/responses/Error" }
  /api/v1/circulars/{id}/acknowledge:
    post:
      tags: [circulars]
      summary: '"Tomei conhecimento" — record that the caller has read the circular'
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Circular" } } } }

  /api/v1/screen/party:
    post:
      tags: [screening]
      summary: Screen a person or entity (onboarding)
      parameters: [ { $ref: "#/components/parameters/IdempotencyKey" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/ScreenPartyRequest" } } } }
      responses:
        "200": { description: Result. POTENTIAL_MATCH opens a case and alerts Compliance., content: { application/json: { schema: { $ref: "#/components/schemas/ScreeningResult" } } } }
        "400": { $ref: "#/components/responses/Error" }
        "429": { $ref: "#/components/responses/Error" }
  /api/v1/screen/transaction:
    post:
      tags: [screening]
      summary: Screen an order or transfer before it runs. Returns ALLOW or HOLD.
      parameters: [ { $ref: "#/components/parameters/IdempotencyKey" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/ScreenTransactionRequest" } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/TransactionScreeningResult" } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/screen/rescreen:
    post:
      tags: [screening]
      summary: Re-screen the whole client base now (Compliance)
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/BatchRescreenResult" } } } }
  /api/v1/screen/runs:
    get:
      tags: [screening]
      summary: Batch re-screening runs
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/BatchRescreenResult" } } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/screenings:
    get:
      tags: [screening]
      summary: Screenings visible to the caller (brokers see only their own)
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit200" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/ScreeningResult" } } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/screenings/{id}:
    get:
      tags: [screening]
      summary: One screening
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/ScreeningResult" } } } }
        "404": { $ref: "#/components/responses/Error" }
  /api/v1/clients/import:
    post:
      tags: [screening]
      summary: Import clients/counterparties (CSV or XLSX) for batch re-screening (Compliance)
      parameters: [ { name: fileName, in: query, schema: { type: string, example: clients.csv } } ]
      requestBody:
        required: true
        content:
          text/csv: { schema: { type: string, format: binary } }
          application/vnd.openxmlformats-officedocument.spreadsheetml.sheet: { schema: { type: string, format: binary } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/ImportResult" } } } }

  /api/v1/cases:
    get:
      tags: [cases]
      summary: Cases (brokers see only cases from their screenings, without internal notes)
      parameters:
        - { name: status, in: query, schema: { $ref: "#/components/schemas/CaseStatus" } }
        - { name: assignee, in: query, schema: { type: string } }
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/Case" } } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/cases/{id}:
    get:
      tags: [cases]
      summary: One case
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/Case" } } } }
        "403": { $ref: "#/components/responses/Error" }
  /api/v1/cases/{id}/assign:
    post:
      tags: [cases]
      summary: Assign a case
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [assignee], properties: { assignee: { type: string } } } } } }
      responses: { "200": { $ref: "#/components/responses/Case" } }
  /api/v1/cases/{id}/start-review:
    post:
      tags: [cases]
      summary: OPEN → UNDER_REVIEW
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses: { "200": { $ref: "#/components/responses/Case" }, "409": { $ref: "#/components/responses/Error" } }
  /api/v1/cases/{id}/evidence:
    post:
      tags: [cases]
      summary: Add an evidence file (screenshot, PDF, document) to a case that is not closed (never shown to brokers)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/AddEvidenceRequest" } } } }
      responses: { "200": { $ref: "#/components/responses/Case" }, "403": { $ref: "#/components/responses/Error" }, "409": { $ref: "#/components/responses/Error" } }
  /api/v1/cases/{id}/notes:
    post:
      tags: [cases]
      summary: Add an internal note (never shown to brokers)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [text], properties: { text: { type: string } } } } } }
      responses: { "200": { $ref: "#/components/responses/Case" } }
  /api/v1/cases/{id}/propose:
    post:
      tags: [cases]
      summary: Propose FALSE_POSITIVE or CONFIRMED (first pair of eyes)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/ProposeDecisionRequest" } } } }
      responses: { "200": { $ref: "#/components/responses/Case" }, "409": { $ref: "#/components/responses/Error" } }
  /api/v1/cases/{id}/approve:
    post:
      tags: [cases]
      summary: Approve the proposal (COMPLIANCE_REVIEWER, must differ from the proposer)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/JustificationRequest" } } } }
      responses: { "200": { $ref: "#/components/responses/Case" }, "403": { $ref: "#/components/responses/Error" }, "409": { $ref: "#/components/responses/Error" } }
  /api/v1/cases/{id}/reject:
    post:
      tags: [cases]
      summary: Reject the proposal and send the case back to review
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/JustificationRequest" } } } }
      responses: { "200": { $ref: "#/components/responses/Case" } }
  /api/v1/cases/{id}/close:
    post:
      tags: [cases]
      summary: Close a decided case
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/JustificationRequest" } } } }
      responses: { "200": { $ref: "#/components/responses/Case" } }
  /api/v1/attachments/{id}:
    get:
      tags: [cases]
      summary: Download a decision attachment or case evidence file (images and PDFs keep their type)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses: { "200": { description: File, content: { application/octet-stream: { schema: { type: string, format: binary } } } } }
  /api/v1/whitelist:
    get:
      tags: [cases]
      summary: Approved false positives, tied to the listed entry's version
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/WhitelistEntry" } } } } }
        "400": { $ref: "#/components/responses/Error" }

  /api/v1/reports/{type}:
    get:
      tags: [reports]
      summary: CMC reports as JSON, PDF or XLSX
      parameters:
        - { name: type, in: path, required: true, schema: { type: string, enum: [list-updates, screening-stats, cases, broker-activity] } }
        - { name: from, in: query, schema: { type: string, format: date } }
        - { name: to, in: query, schema: { type: string, format: date } }
        - { name: format, in: query, schema: { type: string, enum: [json, pdf, xlsx], default: json } }
      responses:
        "200":
          description: Report
          content:
            application/json: { schema: { $ref: "#/components/schemas/ReportTable" } }
            application/pdf: { schema: { type: string, format: binary } }
            application/vnd.openxmlformats-officedocument.spreadsheetml.sheet: { schema: { type: string, format: binary } }
  /api/v1/audit:
    get:
      tags: [reports]
      summary: Audit log entries, newest first
      parameters:
        - { name: actor, in: query, schema: { type: string } }
        - { name: action, in: query, schema: { type: string }, description: Prefix, e.g. "case." }
        - { name: subjectId, in: query, schema: { type: string } }
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/AuditEntry" } } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/audit/verify:
    get:
      tags: [reports]
      summary: Verify the hash chain of the audit log
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/AuditVerification" } } } }

  /api/v1/settings:
    get:
      tags: [admin]
      summary: Engine settings (thresholds, SLA, retention, distribution lists, branding)
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/EngineSettings" } } } }
    put:
      tags: [admin]
      summary: Update settings (ADMIN)
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/EngineSettings" } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/EngineSettings" } } } }
  /api/v1/webhooks:
    get:
      tags: [admin]
      summary: Configured webhook subscriptions (ADMIN)
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/WebhookSubscription" } } } } }
  /api/v1/webhooks/deliveries:
    get:
      tags: [admin]
      summary: Recent webhook deliveries (ADMIN)
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { type: object } } } } }
        "400": { $ref: "#/components/responses/Error" }

  /api/v1/license:
    get:
      tags: [admin]
      summary: Free trial or licence status (any signed-in user; drives the trial banner)
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/LicenseStatus" } } } }
    put:
      tags: [admin]
      summary: Install a licence key signed by the vendor (ADMIN)
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [key], properties: { key: { type: string } } } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/LicenseStatus" } } } }
        "402": { $ref: "#/components/responses/Error" }
  /api/v1/users:
    get:
      tags: [admin]
      summary: User accounts (ADMIN, AUDITOR)
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/UserAccount" } } } } }
        "400": { $ref: "#/components/responses/Error" }
    post:
      tags: [admin]
      summary: Invite a user. Granting ADMIN or COMPLIANCE_REVIEWER opens a request for a second administrator.
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/InviteUserRequest" } } } }
      responses:
        "201": { description: Created, content: { application/json: { schema: { $ref: "#/components/schemas/UserChangeResult" } } } }
        "409": { $ref: "#/components/responses/Error" }
  /api/v1/users/{id}:
    put:
      tags: [admin]
      summary: Change name, roles or broker. Sensitive grants need a second administrator; nobody changes their own roles.
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/UpdateUserRequest" } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/UserChangeResult" } } } }
        "409": { $ref: "#/components/responses/Error" }
  /api/v1/users/{id}/disable:
    post:
      tags: [admin]
      summary: Disable an account (not yourself, not the last administrator)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/UserAccount" } } } }
  /api/v1/users/{id}/enable:
    post:
      tags: [admin]
      summary: Enable an account again
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/UserAccount" } } } }
  /api/v1/users/{id}/password-link:
    post:
      tags: [admin]
      summary: E-mail the user a password reset link (or a new invitation link) — local sign-in
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "202": { description: Link sent }
        "422": { $ref: "#/components/responses/Error" }
  /api/v1/users/{id}/mfa-reset:
    post:
      tags: [admin]
      summary: Remove the user's authenticator (lost phone); they set it up again at next sign-in
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "204": { description: Reset }
        "409": { $ref: "#/components/responses/Error" }
  /api/v1/role-requests:
    get:
      tags: [admin]
      summary: Role changes waiting for (or decided by) a second administrator
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/RoleChangeRequest" } } } } }
        "400": { $ref: "#/components/responses/Error" }
  /api/v1/role-requests/{id}/approve:
    post:
      tags: [admin]
      summary: Approve a role change (a different administrator from the requester and the user)
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/JustificationRequest" } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/RoleChangeRequest" } } } }
  /api/v1/role-requests/{id}/reject:
    post:
      tags: [admin]
      summary: Reject a role change
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/JustificationRequest" } } } }
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/RoleChangeRequest" } } } }
  /api/v1/access-config:
    get:
      tags: [admin]
      summary: Where roles come from (app or identity provider) and the group-to-role mappings
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: object, properties: { roleSource: { type: string, enum: [app, token] }, groupRoleMappings: { type: object } } } } } }
  /api/v1/api-keys:
    get:
      tags: [admin]
      summary: API keys created in the app (ADMIN). The key itself is never returned again.
      parameters:
        - { $ref: "#/components/parameters/Offset" }
        - { $ref: "#/components/parameters/Limit" }
      responses:
        "200": { description: One page (see X-Total-Count and Link), headers: { X-Total-Count: { $ref: "#/components/headers/TotalCount" }, Link: { $ref: "#/components/headers/PageLinks" } }, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/ApiKeyInfo" } } } } }
        "400": { $ref: "#/components/responses/Error" }
    post:
      tags: [admin]
      summary: Create an API key. The response contains the key once; store it safely.
      requestBody: { required: true, content: { application/json: { schema: { type: object, required: [name, roles], properties: { name: { type: string }, roles: { type: array, items: { $ref: "#/components/schemas/Role" } }, brokerId: { type: string } } } } } }
      responses:
        "201": { description: Created, content: { application/json: { schema: { type: object, properties: { info: { $ref: "#/components/schemas/ApiKeyInfo" }, key: { type: string } } } } } }
  /api/v1/api-keys/{id}/revoke:
    post:
      tags: [admin]
      summary: Revoke an API key
      parameters: [ { $ref: "#/components/parameters/Id" } ]
      responses:
        "200": { description: OK, content: { application/json: { schema: { $ref: "#/components/schemas/ApiKeyInfo" } } } }
  /api/v1/distribution-lists:
    get:
      tags: [admin]
      summary: Distribution lists and their recipients
      responses:
        "200": { description: OK, content: { application/json: { schema: { type: array, items: { type: object, properties: { list: { $ref: "#/components/schemas/DistributionList" }, recipients: { type: array, items: { $ref: "#/components/schemas/Recipient" } } } } } } } }
  /api/v1/distribution-lists/{list}:
    put:
      tags: [admin]
      summary: Replace the recipients of a distribution list (ADMIN)
      parameters: [ { name: list, in: path, required: true, schema: { $ref: "#/components/schemas/DistributionList" } } ]
      requestBody: { required: true, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/Recipient" } } } } }
      responses:
        "200": { description: OK }

components:
  securitySchemes:
    bearerAuth: { type: http, scheme: bearer, bearerFormat: JWT }
    apiKey: { type: apiKey, in: header, name: X-API-Key }
  parameters:
    Id: { name: id, in: path, required: true, schema: { type: string } }
    Offset: { name: offset, in: query, required: false, description: Items to skip (0 or more), schema: { type: integer, minimum: 0, default: 0 } }
    Limit: { name: limit, in: query, required: false, description: Page size (above 1000 is capped at 1000), schema: { type: integer, minimum: 1, maximum: 1000, default: 100 } }
    Limit200: { name: limit, in: query, required: false, description: Page size (above 1000 is capped at 1000), schema: { type: integer, minimum: 1, maximum: 1000, default: 200 } }
    IdempotencyKey: { name: Idempotency-Key, in: header, required: false, schema: { type: string, minLength: 8, maxLength: 128 } }
  headers:
    TotalCount: { description: Number of items that match the request (all pages), schema: { type: integer } }
    PageLinks: { description: 'RFC 8288 links to the first, prev, next and last pages, e.g. </api/v1/cases?offset=100&limit=100>; rel="next"', schema: { type: string } }
  responses:
    Error: { description: Problem details (RFC 9457), message in the Accept-Language language, content: { application/problem+json: { schema: { $ref: "#/components/schemas/ApiError" } } } }
    Case: { description: The updated case, content: { application/json: { schema: { $ref: "#/components/schemas/Case" } } } }
  schemas:
    ApiError:
      type: object
      description: RFC 9457 problem document with extension members code, message and correlationId.
      required: [code, message]
      properties:
        type: { type: string, example: "urn:sanctions-engine:problem:case.fourEyes" }
        title: { type: string }
        status: { type: integer, example: 409 }
        detail: { type: string }
        instance: { type: string, example: /api/v1/cases/CASE-0001/approve }
        code: { type: string, example: case.fourEyes }
        message: { type: string }
        correlationId: { type: string }
    Role: { type: string, enum: [ADMIN, COMPLIANCE_OFFICER, COMPLIANCE_REVIEWER, BROKER, AUDITOR, STAFF] }
    PartyType: { type: string, enum: [INDIVIDUAL, ENTITY] }
    AuthConfig:
      type: object
      properties:
        mode: { type: string, enum: [dev, oidc, local] }
        passwordMinLength: { type: integer }
        passwordMaxLength: { type: integer }
        mfaRequired: { type: boolean }
        sessionIdleMinutes: { type: integer }
        issuer: { type: string }
        authorizationEndpoint: { type: string }
        tokenEndpoint: { type: string }
        clientId: { type: string }
        scopes: { type: array, items: { type: string } }
        devUsers: { type: array, items: { type: object, properties: { userId: { type: string }, displayName: { type: string }, roles: { type: array, items: { $ref: "#/components/schemas/Role" } }, brokerId: { type: string } } } }
    LoginRequest: { type: object, required: [username, password], properties: { username: { type: string, description: User name or e-mail }, password: { type: string, format: password } } }
    LoginResponse:
      type: object
      properties:
        step: { type: string, enum: [SIGNED_IN, MFA_REQUIRED, MFA_ENROLLMENT_REQUIRED] }
        accessToken: { type: string }
        tokenType: { type: string }
        expiresIn: { type: integer }
        mfaToken: { type: string, description: Single-use, valid 5 minutes }
        enrollment: { type: object, properties: { secret: { type: string }, otpauthUri: { type: string }, qrPng: { type: string, description: PNG data URI } } }
        recoveryCodes: { type: array, items: { type: string } }
        sessionIdleMinutes: { type: integer }
    MfaCodeRequest: { type: object, required: [mfaToken, code], properties: { mfaToken: { type: string }, code: { type: string, example: "123456" } } }
    ForgotPasswordRequest: { type: object, required: [username], properties: { username: { type: string } } }
    AcceptedResponse: { type: object, properties: { message: { type: string } } }
    ResetTokenRequest: { type: object, required: [token], properties: { token: { type: string } } }
    ResetTokenInfo: { type: object, properties: { valid: { type: boolean }, purpose: { type: string, enum: [RESET, INVITE] }, expiresAt: { type: string, format: date-time } } }
    ResetPasswordRequest: { type: object, required: [token, newPassword], properties: { token: { type: string }, newPassword: { type: string, format: password } } }
    ChangePasswordRequest: { type: object, required: [currentPassword, newPassword], properties: { currentPassword: { type: string, format: password }, newPassword: { type: string, format: password } } }
    SessionInfo: { type: object, properties: { userId: { type: string }, createdAt: { type: string, format: date-time }, lastSeenAt: { type: string, format: date-time }, expiresAt: { type: string, format: date-time }, idleTimeoutSeconds: { type: integer } } }
    DevLoginRequest: { type: object, required: [userId], properties: { userId: { type: string, example: bruno.broker } } }
    TokenResponse: { type: object, properties: { accessToken: { type: string }, tokenType: { type: string }, expiresIn: { type: integer } } }
    DesktopRelease: { type: object, properties: { version: { type: string }, notes: { type: string }, downloads: { type: object, additionalProperties: { type: string } } } }
    Me:
      type: object
      properties:
        userId: { type: string }
        displayName: { type: string }
        email: { type: string }
        roles: { type: array, items: { $ref: "#/components/schemas/Role" } }
        language: { type: string, example: pt-AO }
        theme: { type: string, enum: [LIGHT, DARK, SYSTEM] }
        brokerId: { type: string }
        avatarId: { type: string, description: "Profile picture; download from /api/v1/users/{userId}/avatar" }
    PreferencesUpdate: { type: object, properties: { language: { type: string, example: en }, theme: { type: string, enum: [LIGHT, DARK, SYSTEM] } } }
    PartyQuery:
      type: object
      required: [name]
      properties:
        name: { type: string, example: Joao Manuel Exemplo }
        type: { $ref: "#/components/schemas/PartyType" }
        dateOfBirth: { type: string, description: yyyy-MM-dd or yyyy, example: "1975-08-14" }
        nationality: { type: string, example: Utopia }
        documentNumber: { type: string, example: UT1234567 }
        clientId: { type: string, example: C001 }
    ScreenPartyRequest:
      type: object
      required: [party]
      properties: { party: { $ref: "#/components/schemas/PartyQuery" }, brokerId: { type: string }, purpose: { type: string, default: ONBOARDING } }
    ScreenTransactionRequest:
      type: object
      required: [transactionId, kind, client, amount, currency]
      properties:
        transactionId: { type: string, example: T002 }
        kind: { type: string, enum: [ORDER, TRANSFER] }
        client: { $ref: "#/components/schemas/PartyQuery" }
        counterparty: { $ref: "#/components/schemas/PartyQuery" }
        amount: { type: string, description: Decimal as text, example: "45000.00" }
        currency: { type: string, example: USD }
        brokerId: { type: string }
    MatchResult:
      type: object
      properties:
        sourceId: { type: string }
        referenceNumber: { type: string, example: XXi.101 }
        listedName: { type: string }
        matchedName: { type: string }
        score: { type: number, format: double, example: 0.96 }
        nameScore: { type: number, format: double }
        matchedFields: { type: array, items: { type: string } }
        explanation: { type: string }
        regime: { type: string }
        partyType: { $ref: "#/components/schemas/PartyType" }
    ScreeningResult:
      type: object
      properties:
        id: { type: string, example: SCR-000123 }
        screenedAt: { type: string, format: date-time }
        outcome: { type: string, enum: [NO_MATCH, POTENTIAL_MATCH, CONFIRMED_MATCH] }
        subject: { $ref: "#/components/schemas/PartyQuery" }
        matches: { type: array, items: { $ref: "#/components/schemas/MatchResult" } }
        nearMisses: { type: array, items: { $ref: "#/components/schemas/MatchResult" } }
        threshold: { type: number }
        listVersions: { type: object, additionalProperties: { type: string } }
        caseId: { type: string }
        brokerId: { type: string }
        requestedBy: { type: string }
        purpose: { type: string }
        transactionId: { type: string }
        correlationId: { type: string }
    TransactionScreeningResult:
      type: object
      properties:
        transactionId: { type: string }
        decision: { type: string, enum: [ALLOW, HOLD] }
        screenings: { type: array, items: { $ref: "#/components/schemas/ScreeningResult" } }
        reason: { type: string }
    BatchRescreenResult:
      type: object
      properties:
        runId: { type: string }
        startedAt: { type: string, format: date-time }
        finishedAt: { type: string, format: date-time }
        trigger: { type: string }
        clientsScreened: { type: integer }
        potentialMatches: { type: integer }
        casesOpened: { type: integer }
        prioritizedReferences: { type: array, items: { type: string } }
    ImportResult: { type: object, properties: { imported: { type: integer }, rejected: { type: array, items: { type: string } } } }
    CaseStatus: { type: string, enum: [OPEN, UNDER_REVIEW, FALSE_POSITIVE, CONFIRMED, CLOSED] }
    Decision:
      type: object
      properties:
        kind: { type: string, enum: [FALSE_POSITIVE, CONFIRMED] }
        proposedBy: { type: string }
        proposedAt: { type: string, format: date-time }
        justification: { type: string }
        attachments: { type: array, items: { $ref: "#/components/schemas/Attachment" } }
    Attachment: { type: object, properties: { fileName: { type: string }, contentType: { type: string }, sizeBytes: { type: integer }, sha256: { type: string }, storageId: { type: string } } }
    Case:
      type: object
      properties:
        id: { type: string, example: CASE-0007 }
        status: { $ref: "#/components/schemas/CaseStatus" }
        subject: { $ref: "#/components/schemas/PartyQuery" }
        match: { $ref: "#/components/schemas/MatchResult" }
        screeningId: { type: string }
        brokerId: { type: string }
        openedAt: { type: string, format: date-time }
        slaDueAt: { type: string, format: date-time }
        pastSla: { type: boolean }
        escalated: { type: boolean }
        assignee: { type: string }
        pendingDecision: { $ref: "#/components/schemas/Decision" }
        finalDecision: { $ref: "#/components/schemas/Decision" }
        approvedBy: { type: string }
        closedAt: { type: string, format: date-time }
        notes: { type: array, items: { type: object, properties: { at: { type: string }, author: { type: string }, text: { type: string } } } }
        evidence: { type: array, items: { $ref: "#/components/schemas/CaseEvidence" } }
        history: { type: array, items: { type: object } }
        freezeGuidance: { type: string }
        authorityReportDraft: { type: string }
    ProposeDecisionRequest:
      type: object
      required: [kind, justification]
      properties:
        kind: { type: string, enum: [FALSE_POSITIVE, CONFIRMED] }
        justification: { type: string, minLength: 10 }
        attachments: { type: array, items: { $ref: "#/components/schemas/AttachmentUpload" } }
    CaseEvidence: { type: object, properties: { at: { type: string, format: date-time }, addedBy: { type: string }, attachment: { $ref: "#/components/schemas/Attachment" }, description: { type: string } } }
    AddEvidenceRequest: { type: object, required: [file], properties: { file: { $ref: "#/components/schemas/AttachmentUpload" }, description: { type: string, maxLength: 500 } } }
    AttachmentUpload: { type: object, required: [fileName, contentType, base64], properties: { fileName: { type: string }, contentType: { type: string }, base64: { type: string } } }
    JustificationRequest: { type: object, required: [justification], properties: { justification: { type: string, minLength: 10 } } }
    WhitelistEntry:
      type: object
      properties:
        id: { type: string }
        clientKey: { type: string }
        subjectName: { type: string }
        sourceId: { type: string }
        referenceNumber: { type: string }
        partyFingerprint: { type: string }
        listVersion: { type: string }
        caseId: { type: string }
        createdAt: { type: string, format: date-time }
        approvedBy: { type: string }
    ListUpdateSummary:
      type: object
      properties:
        id: { type: string, example: UPD-0002 }
        kind: { type: string, enum: [LIST_UPDATE, CMC_COMMUNICATION] }
        sourceId: { type: string }
        sourceName: { type: string }
        detectedAt: { type: string, format: date-time }
        updateDates: { type: array, items: { type: string, format: date } }
        fromVersion: { type: string }
        toVersion: { type: string }
        added: { type: integer }
        amended: { type: integer }
        removed: { type: integer }
        baseline: { type: boolean }
        committee: { type: string }
        resolution: { type: string }
        reference: { type: string }
        circularId: { type: string }
        circularStatus: { type: string, enum: [DRAFT, SENT] }
        rawSha256: { type: string }
        officialUrl: { type: string }
    ListUpdateDetail:
      type: object
      properties:
        summary: { $ref: "#/components/schemas/ListUpdateSummary" }
        delta: { type: object, description: "ListDelta: changes[] with type ADDED/REMOVED/AMENDED and fieldDiffs" }
        cmc: { $ref: "#/components/schemas/CmcCommunication" }
    ListEntry:
      type: object
      properties:
        sourceId: { type: string }
        referenceNumber: { type: string }
        partyType: { $ref: "#/components/schemas/PartyType" }
        name: { type: string }
        aliases: { type: array, items: { type: string } }
        nationalities: { type: array, items: { type: string } }
        listedOn: { type: string }
        regime: { type: string }
    Measure: { type: string, enum: [ASSET_FREEZE, TRAVEL_BAN, ARMS_EMBARGO] }
    CmcCommunicationRequest:
      type: object
      required: [receivedOn, reference]
      properties:
        receivedOn: { type: string, format: date }
        reference: { type: string, example: CMC/DEMO/2026/001 }
        committee: { type: string }
        resolution: { type: string, description: As written in the CMC communication. Never inferred. }
        legalBasis: { type: string }
        updateDates: { type: array, items: { type: string, format: date } }
        entriesAffected: { type: array, items: { type: string } }
        measures: { type: array, items: { $ref: "#/components/schemas/Measure" } }
        officialUrl: { type: string, description: Outlook safelinks URLs are unwrapped to the clean original. }
        attachment: { $ref: "#/components/schemas/AttachmentUpload" }
    CmcCommunication:
      allOf:
        - $ref: "#/components/schemas/CmcCommunicationRequest"
        - type: object
          properties:
            id: { type: string }
            attachment: { $ref: "#/components/schemas/Attachment" }
            registeredBy: { type: string }
            registeredAt: { type: string, format: date-time }
    SourceStatus:
      type: object
      properties:
        sourceId: { type: string }
        displayName: { type: string }
        officialUrl: { type: string }
        currentVersion: { type: string }
        lastCheckedAt: { type: string, format: date-time }
        lastSuccessAt: { type: string, format: date-time }
        lastError: { type: string }
        healthy: { type: boolean }
        entries: { type: integer }
    RenderedMessage: { type: object, properties: { language: { type: string }, subject: { type: string }, html: { type: string }, text: { type: string } } }
    Circular:
      type: object
      properties:
        id: { type: string, example: CIRC-0001 }
        updateId: { type: string }
        status: { type: string, enum: [DRAFT, SENT] }
        createdAt: { type: string, format: date-time }
        audiences: { type: array, items: { $ref: "#/components/schemas/DistributionList" } }
        renditions: { type: array, items: { $ref: "#/components/schemas/RenderedMessage" } }
        sentAt: { type: string, format: date-time }
        sentBy: { type: string }
        deliveries: { type: array, items: { type: object, properties: { channel: { type: string }, recipient: { type: string }, status: { type: string, enum: [PENDING, SENT, FAILED] }, attempts: { type: integer }, error: { type: string } } } }
        acknowledgements: { type: array, items: { type: object, properties: { userId: { type: string }, displayName: { type: string }, at: { type: string, format: date-time } } } }
        audienceSize: { type: integer }
    DistributionList: { type: string, enum: [ALL_STAFF, COMPLIANCE, BROKERS, MANAGEMENT] }
    SendCircularRequest: { type: object, properties: { audiences: { type: array, items: { $ref: "#/components/schemas/DistributionList" } } } }
    InboxItem:
      type: object
      properties:
        id: { type: string }
        circularId: { type: string }
        caseId: { type: string }
        subject: { type: string }
        text: { type: string }
        receivedAt: { type: string, format: date-time }
        urgent: { type: boolean }
        acknowledged: { type: boolean }
    Dashboard:
      type: object
      properties:
        sources: { type: array, items: { $ref: "#/components/schemas/SourceStatus" } }
        latestUpdate: { $ref: "#/components/schemas/ListUpdateSummary" }
        openCases: { type: integer }
        casesPastSla: { type: integer }
        screeningsToday: { type: integer }
        screeningsYesterday: { type: integer }
        screeningsSeries: { type: array, items: { type: object, properties: { date: { type: string }, count: { type: integer } } } }
        ackRate: { type: number }
        ackCount: { type: integer }
        audienceSize: { type: integer }
        timeline: { type: array, items: { type: object } }
        myCases: { type: array, items: { $ref: "#/components/schemas/Case" } }
        myScreenings: { type: array, items: { $ref: "#/components/schemas/ScreeningResult" } }
    AuditEntry:
      type: object
      properties:
        seq: { type: integer }
        at: { type: string, format: date-time }
        actor: { type: string }
        action: { type: string, example: case.decision_approved }
        subjectType: { type: string }
        subjectId: { type: string }
        details: { type: object, additionalProperties: { type: string } }
        correlationId: { type: string }
        prevHash: { type: string }
        hash: { type: string }
    AuditVerification: { type: object, properties: { valid: { type: boolean }, entries: { type: integer }, firstBrokenSeq: { type: integer }, headHash: { type: string } } }
    ReportTable:
      type: object
      properties:
        type: { type: string, enum: [LIST_UPDATES, SCREENING_STATS, CASES, BROKER_ACTIVITY] }
        title: { type: string }
        period: { type: string }
        generatedAt: { type: string, format: date-time }
        columns: { type: array, items: { type: string } }
        rows: { type: array, items: { type: array, items: { type: string } } }
        summary: { type: object, additionalProperties: { type: string } }
    EngineSettings:
      type: object
      properties:
        potentialMatchThreshold: { type: number, example: 0.85 }
        nameFloor: { type: number, example: 0.75 }
        fetchIntervalHours: { type: integer, example: 6 }
        caseSlaHours: { type: integer, example: 24 }
        sourceAlertAfterHours: { type: integer, example: 24 }
        retentionYears: { type: integer, example: 10, minimum: 10 }
        distributionLists: { type: object, additionalProperties: { type: array, items: { type: object } } }
        institutionName: { type: string }
        primaryColor: { type: string }
        logoUrl: { type: string }
    WebhookSubscription: { type: object, properties: { id: { type: string }, url: { type: string }, events: { type: array, items: { type: string } }, active: { type: boolean } } }

    LicenseStatus:
      type: object
      properties:
        state: { type: string, enum: [TRIAL, ACTIVE, EXPIRED] }
        edition: { type: string }
        licensee: { type: string }
        trialEndsOn: { type: string, format: date }
        expiresOn: { type: string, format: date }
        daysLeft: { type: integer }
        maxUsers: { type: integer }
        activeUsers: { type: integer }
        processingAllowed: { type: boolean, description: False after the trial or licence ends (read-only mode) }
    UserAccount:
      type: object
      properties:
        userId: { type: string }
        displayName: { type: string }
        email: { type: string }
        roles: { type: array, items: { $ref: "#/components/schemas/Role" } }
        brokerId: { type: string }
        status: { type: string, enum: [INVITED, ACTIVE, DISABLED] }
        createdAt: { type: string, format: date-time }
        createdBy: { type: string }
        lastSignInAt: { type: string, format: date-time }
        passwordSet: { type: boolean, description: Local sign-in only }
        mfaEnabled: { type: boolean, description: Local sign-in only }
        lockedUntil: { type: string, format: date-time, description: Local sign-in only }
        avatarId: { type: string }
    InviteUserRequest:
      type: object
      required: [userId, displayName]
      properties:
        userId: { type: string, description: Sign-in name (Entra UPN / e-mail) }
        displayName: { type: string }
        email: { type: string }
        roles: { type: array, items: { $ref: "#/components/schemas/Role" } }
        brokerId: { type: string }
    UpdateUserRequest:
      type: object
      properties:
        displayName: { type: string }
        roles: { type: array, items: { $ref: "#/components/schemas/Role" } }
        brokerId: { type: string }
    RoleChangeRequest:
      type: object
      properties:
        id: { type: string }
        userId: { type: string }
        fromRoles: { type: array, items: { $ref: "#/components/schemas/Role" } }
        toRoles: { type: array, items: { $ref: "#/components/schemas/Role" } }
        requestedBy: { type: string }
        requestedAt: { type: string, format: date-time }
        status: { type: string, enum: [PENDING, APPROVED, REJECTED] }
        decidedBy: { type: string }
        decidedAt: { type: string, format: date-time }
    UserChangeResult:
      type: object
      properties:
        user: { $ref: "#/components/schemas/UserAccount" }
        pendingRequest: { $ref: "#/components/schemas/RoleChangeRequest" }
    ApiKeyInfo:
      type: object
      properties:
        id: { type: string }
        name: { type: string }
        prefix: { type: string }
        roles: { type: array, items: { $ref: "#/components/schemas/Role" } }
        brokerId: { type: string }
        createdBy: { type: string }
        createdAt: { type: string, format: date-time }
        lastUsedAt: { type: string, format: date-time }
        revokedAt: { type: string, format: date-time }
    Recipient: { type: object, required: [id, displayName], properties: { id: { type: string }, displayName: { type: string }, email: { type: string }, language: { type: string, default: pt-AO } } }
