components:
  schemas:
    AdminFileDetailResponse:
      additionalProperties: false
      properties:
        content:
          type: string
        createdAt:
          type: string
        environment:
          type: string
        fileCategory:
          type: string
        fileHash:
          type: string
        fileName:
          type: string
        fileType:
          type: string
        generationDate:
          type: string
        id:
          type: string
        institutionCode:
          type: string
        recordCount:
          format: int64
          type: integer
        status:
          type: string
        updatedAt:
          type: string
      required:
        - id
        - fileCategory
        - fileName
        - fileType
        - environment
        - institutionCode
        - recordCount
        - fileHash
        - status
        - generationDate
        - createdAt
        - updatedAt
      type: object
    AdminFileListItem:
      additionalProperties: false
      properties:
        createdAt:
          type: string
        environment:
          type: string
        fileCategory:
          type: string
        fileHash:
          type: string
        fileName:
          type: string
        fileType:
          type: string
        generationDate:
          type: string
        id:
          type: string
        institutionCode:
          type: string
        recordCount:
          format: int64
          type: integer
        status:
          type: string
        transmissionDate:
          type: string
        updatedAt:
          type: string
      required:
        - id
        - fileCategory
        - fileName
        - fileType
        - environment
        - institutionCode
        - recordCount
        - fileHash
        - status
        - generationDate
        - createdAt
        - updatedAt
      type: object
    AdminOrderListItem:
      additionalProperties: false
      properties:
        chaveRegistro:
          type: string
        codigoResposta:
          type: string
        createdAt:
          type: string
        dataHoraProtocolo:
          type: string
        escopoOrdem:
          type: string
        id:
          type: string
        ordemBloqueioPermanente:
          type: boolean
        retryCount:
          format: int64
          type: integer
        slaDeadline:
          type: string
        status:
          type: string
        tipoOrdem:
          type: string
        updatedAt:
          type: string
      required:
        - id
        - chaveRegistro
        - tipoOrdem
        - ordemBloqueioPermanente
        - status
        - retryCount
        - dataHoraProtocolo
        - slaDeadline
        - createdAt
        - updatedAt
      type: object
    AdminProcessingStatsResponse:
      additionalProperties: false
      properties:
        byStatus:
          additionalProperties:
            format: int64
            type: integer
          type: object
        byTipoOrdem:
          additionalProperties:
            format: int64
            type: integer
          type: object
        total:
          format: int64
          type: integer
      required:
        - total
        - byStatus
        - byTipoOrdem
      type: object
    AuditVerifyResponse:
      additionalProperties: false
      properties:
        firstMissingIndex:
          format: int64
          type: integer
        firstTamperedIndex:
          format: int64
          type: integer
        fromIndex:
          format: int64
          type: integer
        ok:
          type: boolean
        toIndex:
          format: int64
          type: integer
        verified:
          format: int64
          type: integer
      required:
        - ok
        - verified
        - fromIndex
        - toIndex
      type: object
    CreateInstitutionConfigRequest:
      additionalProperties: false
      properties:
        enabled:
          description: Whether the institution configuration is active.
          examples:
            - true
          type: boolean
        institutionCode:
          description: The institution's BACEN CNPJ (8 digits) for return-file headers and file header validation.
          examples:
            - "12345678"
          type: string
        institutionId:
          description: The institution's unique identifier (UUID) that addresses the new configuration.
          examples:
            - 550e8400-e29b-41d4-a716-446655440000
          type: string
        retryPolicyConfig:
          description: Operational retry policy (backoff/attempts) as arbitrary JSON.
          examples:
            - initialBackoffMs: 100
              maxAttempts: 3
      required:
        - institutionId
        - institutionCode
        - enabled
      type: object
    Detail:
      additionalProperties: true
      properties:
        code:
          description: "Stable, machine-readable domain error code scoped to the emitting service (format: <SERVICE>-NNNN)."
          type: string
        detail:
          description: A human-readable explanation specific to this occurrence of the problem.
          examples:
            - Property foo is required but is missing.
          type: string
        errors:
          description: Optional list of individual error details
          items:
            $ref: "#/components/schemas/ErrorDetail"
          type:
            - array
            - "null"
        instance:
          description: A URI reference that identifies the specific occurrence of the problem.
          examples:
            - https://example.com/error-log/abc123
          format: uri
          type: string
        status:
          description: HTTP status code
          examples:
            - 400
          format: int64
          type: integer
        title:
          description: A short, human-readable summary of the problem type. This value should not change between occurrences of the error.
          examples:
            - Bad Request
          type: string
        type:
          default: about:blank
          description: A URI reference to human-readable documentation for the error.
          examples:
            - https://example.com/errors/example
          format: uri
          type: string
        upstream:
          $ref: "#/components/schemas/Upstream"
          description: "RFC 9457 extension member: the error a proxied third-party provider reported. Absent unless the emitting service explicitly surfaced one."
      type: object
    ErrorDetail:
      additionalProperties: false
      properties:
        location:
          description: Where the error occurred, e.g. 'body.items[3].tags' or 'path.thing-id'
          type: string
        message:
          description: Error message text
          type: string
        value:
          description: The value at the given location
      type: object
    InstitutionConfigResponse:
      additionalProperties: false
      properties:
        createdAt:
          description: RFC 3339 creation timestamp (UTC).
          examples:
            - "2024-01-15T10:30:00Z"
          type: string
        enabled:
          description: Whether the institution configuration is active.
          examples:
            - true
          type: boolean
        institutionCode:
          description: The institution's BACEN CNPJ (8 digits) for return-file headers and file header validation.
          examples:
            - "12345678"
          type: string
        institutionId:
          description: The institution's unique identifier (UUID).
          examples:
            - 550e8400-e29b-41d4-a716-446655440000
          type: string
        retryPolicyConfig:
          description: Operational retry policy (backoff/attempts) as arbitrary JSON.
          examples:
            - maxAttempts: 3
        updatedAt:
          description: RFC 3339 last-update timestamp (UTC).
          examples:
            - "2024-01-15T12:00:00Z"
          type: string
      required:
        - institutionId
        - institutionCode
        - enabled
        - createdAt
        - updatedAt
      type: object
    OrderDetail:
      additionalProperties: false
      properties:
        chaveRegistro:
          type: string
        codigoResposta:
          type: string
        cpfCnpj:
          type: string
        createdAt:
          type: string
        dataHoraProtocolo:
          type: string
        escopoOrdem:
          type: string
        id:
          type: string
        juizSolicitante:
          type: string
        motivoNegativa:
          type: string
        numeroProcesso:
          type: string
        ordemBloqueioPermanente:
          type: boolean
        retryCount:
          format: int64
          type: integer
        slaDeadline:
          type: string
        status:
          type: string
        tipoOrdem:
          type: string
        updatedAt:
          type: string
        valorBloqueado:
          type: string
        valorBloqueioMinimo:
          type: string
        valorDesbloqueado:
          type: string
        valorRemanescente:
          type: string
        valorSolicitado:
          type: string
        valorTransferido:
          type: string
      required:
        - id
        - chaveRegistro
        - tipoOrdem
        - ordemBloqueioPermanente
        - status
        - retryCount
        - dataHoraProtocolo
        - slaDeadline
        - createdAt
        - updatedAt
        - cpfCnpj
        - numeroProcesso
        - juizSolicitante
        - valorSolicitado
        - valorBloqueado
        - valorDesbloqueado
        - valorTransferido
        - valorRemanescente
        - motivoNegativa
      type: object
    PageAdminFileListItem:
      additionalProperties: false
      properties:
        data:
          items:
            $ref: "#/components/schemas/AdminFileListItem"
          type:
            - array
            - "null"
        limit:
          format: int64
          type: integer
        offset:
          format: int64
          type: integer
        total:
          format: int64
          type: integer
      required:
        - data
        - limit
        - offset
        - total
      type: object
    PageAdminOrderListItem:
      additionalProperties: false
      properties:
        data:
          items:
            $ref: "#/components/schemas/AdminOrderListItem"
          type:
            - array
            - "null"
        limit:
          format: int64
          type: integer
        offset:
          format: int64
          type: integer
        total:
          format: int64
          type: integer
      required:
        - data
        - limit
        - offset
        - total
      type: object
    PatchInstitutionConfigRequest:
      additionalProperties: false
      properties:
        enabled:
          description: Whether the institution configuration is active. Omitted leaves the flag unchanged; explicitly false disables it.
          examples:
            - false
          type: boolean
        institutionCode:
          description: The institution's BACEN CNPJ (8 digits). When present, replaces the stored value.
          examples:
            - "12345678"
          type: string
        retryPolicyConfig:
          description: Operational retry policy as arbitrary JSON. When present, replaces the stored value.
          examples:
            - maxAttempts: 5
      type: object
    PostJustificationBody:
      additionalProperties: false
      properties:
        justificativa:
          description: The cleartext justification (PII; sealed server-side, never logged nor echoed).
          examples:
            - Batch delay caused by upstream connector outage; SLA breach accepted under ops incident INC-2026-042.
          type: string
      required:
        - justificativa
      type: object
    PostJustificationResponse:
      additionalProperties: false
      properties:
        id:
          description: The opaque non-compliance log id (UUID) the justification was recorded against.
          examples:
            - bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb
          format: uuid
          type: string
      required:
        - id
      type: object
    PostLgpdRequestBody:
      additionalProperties: false
      properties:
        cpfCnpj:
          description: The data subject's cleartext CPF or CNPJ (tokenized server-side; never echoed nor logged).
          examples:
            - "52998224725"
          type: string
        docType:
          description: The document type (cpf or cnpj); inferred from the subject value when omitted.
          examples:
            - cpf
          type: string
        legalJustification:
          description: The legal basis for the request (sealed verbatim into the audit payload).
          examples:
            - LGPD art. 18 data subject request
          type: string
        requestType:
          description: The LGPD request type (e.g. access, portability).
          examples:
            - access
          type: string
        requesterProtocol:
          description: The caller-supplied protocol identifier for correlation.
          examples:
            - PROT-2026-0001
          type: string
      required:
        - requestType
        - cpfCnpj
        - requesterProtocol
        - legalJustification
      type: object
    PostLgpdRequestResponse:
      additionalProperties: false
      properties:
        id:
          description: The newly created LGPD request id.
          examples:
            - 11111111-1111-1111-1111-111111111111
          type: string
        requesterProtocol:
          description: The caller-supplied protocol identifier echoed for correlation.
          examples:
            - PROT-2026-0001
          type: string
      required:
        - id
        - requesterProtocol
      type: object
    PostResolveLgpdRequestBody:
      additionalProperties: false
      properties:
        decision:
          description: The resolution decision (e.g. fulfilled, refused, partial).
          examples:
            - fulfilled
          type: string
        decisionReason:
          description: Optional human-readable reason for the decision.
          examples:
            - Records delivered via secure channel.
          type: string
        deliveryRef:
          description: Optional delivery reference for the exported data.
          examples:
            - DEL-2026-0007
          type: string
        recordsAffected:
          description: Optional count of records affected by the decision.
          examples:
            - 42
          format: int64
          type: integer
        recordsEliminated:
          description: Optional count of records eliminated.
          examples:
            - 12
          format: int64
          type: integer
        recordsRetained:
          description: Optional count of records retained.
          examples:
            - 30
          format: int64
          type: integer
        tokensGenerated:
          description: Optional count of new tokens generated during the resolution.
          examples:
            - 12
          format: int64
          type: integer
      required:
        - decision
      type: object
    PostResolveLgpdResponse:
      additionalProperties: false
      properties:
        id:
          description: The resolved LGPD request id.
          examples:
            - 11111111-1111-1111-1111-111111111111
          type: string
      required:
        - id
      type: object
    ReturnFileGenerateResponse:
      additionalProperties: false
      properties:
        environment:
          description: The resolved SISBAJUD environment.
          examples:
            - production
          type: string
        failedGroups:
          description: "The number of response groups whose answer failed in this run. Non-zero with generated=true is a partial failure: the generated files stand and the failed groups are retried by the next run."
          examples:
            - 0
          format: int64
          type: integer
        fileHash:
          description: The file content hash.
          examples:
            - sha256:abc123...
          type: string
        fileName:
          description: The generated file name.
          examples:
            - retorno-2026-07-14.txt
          type: string
        fileType:
          description: The SISBAJUD file-type code.
          examples:
            - RETORNO
          type: string
        generated:
          description: Whether this run created a new return file.
          examples:
            - true
          type: boolean
        generatedCount:
          description: The number of return files created by this run. A remittance whose answer matches an existing file is stamped onto that file and creates none. The fields above describe the newest one.
          examples:
            - 3
          format: int64
          type: integer
        generationDate:
          description: The RFC3339 generation timestamp.
          examples:
            - "2026-07-14T12:00:00Z"
          type: string
        id:
          description: The generated file id.
          examples:
            - dddddddd-dddd-dddd-dddd-dddddddddddd
          type: string
        recordCount:
          description: The number of records in the generated file.
          examples:
            - 42
          format: int64
          type: integer
        status:
          description: The file status.
          examples:
            - GENERATED
          type: string
      required:
        - generated
        - recordCount
        - generatedCount
        - failedGroups
      type: object
    ReturnFileReconsolidateResponse:
      additionalProperties: false
      properties:
        responseDeadline:
          description: RFC3339 instant of the response deadline that the Mensageria computed for these orders. Omitted when the file answers no remittance.
          examples:
            - "2026-09-10T22:00:00Z"
          type: string
        unstampedOrders:
          description: How many judicial orders were released back to the unreturned set.
          examples:
            - 42
          format: int64
          type: integer
      required:
        - unstampedOrders
      type: object
    ReturnFileResolveTransmissionRequest:
      additionalProperties: false
      properties:
        action:
          description: probe_now asks Lerian STA whether a transfer for this file already exists; attach_transfer binds one you located, after Lerian STA confirms it is this file's; force_fail gives up on a stuck submission so the file becomes reconsolidable; cancel_now retries cancelling a size-mismatched transfer that is still live.
          enum:
            - probe_now
            - attach_transfer
            - force_fail
            - cancel_now
          examples:
            - probe_now
          type: string
        reason:
          description: "Why this remedy is being applied, in your own words. MUST NOT contain personal data (CPF/CNPJ, names, process numbers) or monetary values: it is written verbatim into a permanent, append-only audit record. Text carrying a run of more than 10 digits is refused with 422 — that is a floor against pasting an identifier, not a check that recognises a name."
          examples:
            - Lerian STA unavailable since 14:00; response deadline at 19:00
          type: string
        transferId:
          description: Required by attach_transfer; ignored otherwise. Lerian STA is asked to confirm it belongs to this file before anything is bound.
          examples:
            - eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee
          type: string
      required:
        - action
        - reason
      type: object
    ReturnFileResolveTransmissionResponse:
      additionalProperties: false
      properties:
        outcome:
          description: "A token from the closed set: reconciled_by_list, still_absent, attached, forced_failed, cancelled. A failed cancel_now answers with an error, not an outcome."
          examples:
            - reconciled_by_list
          type: string
        transferId:
          description: The transfer the file ended up bound to, when the action produced one.
          examples:
            - eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee
          type: string
      required:
        - outcome
      type: object
    RotateInstitutionKekResponse:
      additionalProperties: false
      properties:
        institutionId:
          description: The institution the rotation targeted.
          examples:
            - 44444444-4444-4444-4444-444444444444
          type: string
        newKekVersion:
          description: The newly active KEK version.
          examples:
            - v3
          type: string
        previousKekVersion:
          description: The KEK version that was active before the rotation.
          examples:
            - v2
          type: string
        rewrapStatus:
          description: The rewrap progress status (e.g. IN_PROGRESS).
          examples:
            - IN_PROGRESS
          type: string
        rotatedAt:
          description: The RFC3339 timestamp the rotation committed.
          examples:
            - "2026-06-08T12:00:00Z"
          type: string
      required:
        - institutionId
        - newKekVersion
        - previousKekVersion
        - rotatedAt
        - rewrapStatus
      type: object
    RotateKEKRequest:
      additionalProperties: false
      properties:
        reason:
          description: Optional operator-supplied free-text reason for the rotation (sealed verbatim into the audit payload).
          examples:
            - scheduled_annual_rotation
          type: string
      type: object
    RotateKeysetRequest:
      additionalProperties: false
      properties:
        reason:
          description: Optional operator-supplied free-text reason for the rotation (sealed verbatim into the audit payload).
          examples:
            - quarterly_keyset_rotation
          type: string
      type: object
    RotateKeysetResponse:
      additionalProperties: false
      properties:
        institutionId:
          description: The institution the rotation targeted.
          examples:
            - 44444444-4444-4444-4444-444444444444
          type: string
        newKeysetVersion:
          description: The newly active tokenization-keyset version.
          examples:
            - 3
          format: int64
          type: integer
        previousKeysetVersion:
          description: The tokenization-keyset version that was active before the rotation.
          examples:
            - 2
          format: int64
          type: integer
        rotatedAt:
          description: The RFC3339 timestamp the rotation committed.
          examples:
            - "2026-06-08T12:00:00Z"
          type: string
      required:
        - institutionId
        - previousKeysetVersion
        - newKeysetVersion
        - rotatedAt
      type: object
    STADLQAcknowledgeRequest:
      additionalProperties: false
      properties:
        action:
          description: "What you did: replayed (cause fixed, message shovelled back — the consumer is idempotent), recorded (the disposition stands; the commonest case is a syntactic parse_rejected, where the remittance row is already REJECTED — never parse_domain_refused, whose remittance is partially applied), escalated (the order could not be reproduced inside the window and the institution is talking to the court)."
          enum:
            - replayed
            - recorded
            - escalated
          examples:
            - replayed
          type: string
        note:
          description: "Why, in your own words. MUST NOT contain personal data (CPF/CNPJ, names, process numbers) or monetary values: it is written verbatim into a permanent, append-only audit record. Text carrying a run of more than 10 digits is refused with 422 — that is a floor against pasting an identifier, not a check that recognises a name."
          examples:
            - institution config was missing the STA credential; added and replayed
          type: string
        queue:
          description: Which of the two queues the message was parked from. These are the values the metric's queue label carries — the direction, not the configured queue name, so the record can be read next to the series.
          enum:
            - inbound
            - outbound
          examples:
            - outbound
          type: string
        reason:
          description: The parking token, read from the message's x-sisbajud-reason header. The values are the consumer's closed set; "other" is deliberately absent, being the fallback the code produces for a token nobody declared.
          enum:
            - direction_mismatch
            - doctype_header_mismatch
            - doctype_not_allowed
            - doctype_pair_mismatch
            - doctype_unexpected_shape
            - doctype_unmapped
            - event_duplicate
            - handler_not_wired
            - handler_panic
            - institution_unresolved
            - lock_held
            - object_key_out_of_scope
            - object_missing
            - parse_domain_refused
            - parse_rejected
            - payload_shape_invalid
            - payload_too_large
            - receive_transient
            - sha256_mismatch
            - sta_state_unknown
            - tenant_scope_mismatch
            - terminal_conflict
            - transfer_not_found
            - transfer_not_found_after_retry
            - transition_out_of_order
          examples:
            - institution_unresolved
          type: string
      required:
        - queue
        - reason
        - action
      type: object
    STADLQAcknowledgeResponse:
      additionalProperties: false
      properties:
        receiptId:
          description: "The audit record's id. It identifies THIS acknowledgement, not the message: Lerian STA's event id is a string and is recorded as the audit correlation id."
          examples:
            - cccccccc-cccc-cccc-cccc-cccccccccccc
          type: string
      required:
        - receiptId
      type: object
    SlaBandCounts:
      additionalProperties: false
      properties:
        green:
          format: int64
          type: integer
        orange:
          format: int64
          type: integer
        red:
          format: int64
          type: integer
        total:
          format: int64
          type: integer
        yellow:
          format: int64
          type: integer
      required:
        - green
        - yellow
        - orange
        - red
        - total
      type: object
    SlaOrderStatus:
      additionalProperties: false
      properties:
        band:
          type: string
        dataHoraProtocolo:
          type: string
        elapsedPercent:
          format: double
          type: number
        id:
          type: string
        slaDeadline:
          type: string
        status:
          type: string
      required:
        - id
        - status
        - band
        - elapsedPercent
        - dataHoraProtocolo
        - slaDeadline
      type: object
    SlaStatusResult:
      additionalProperties: false
      properties:
        counts:
          $ref: "#/components/schemas/SlaBandCounts"
        orders:
          items:
            $ref: "#/components/schemas/SlaOrderStatus"
          type:
            - array
            - "null"
      required:
        - counts
        - orders
      type: object
    SubjectExport:
      additionalProperties: false
      properties:
        files:
          items:
            $ref: "#/components/schemas/SubjectFileRef"
          type:
            - array
            - "null"
        generatedAt:
          type: string
        orders:
          items:
            $ref: "#/components/schemas/OrderDetail"
          type:
            - array
            - "null"
      required:
        - orders
        - files
        - generatedAt
      type: object
    SubjectFileRef:
      additionalProperties: false
      properties:
        createdAt:
          type: string
        fileName:
          type: string
        fileType:
          type: string
        generationDate:
          type: string
        id:
          type: string
        kind:
          type: string
        status:
          type: string
        transmissionDate:
          type: string
        updatedAt:
          type: string
      required:
        - id
        - kind
        - fileName
        - fileType
        - status
        - generationDate
        - createdAt
        - updatedAt
      type: object
    Upstream:
      additionalProperties: false
      properties:
        code:
          description: The upstream provider's own error code, verbatim.
          examples:
            - E4001
          type: string
        message:
          description: The upstream provider's own error message, verbatim (bounded, never its raw response body).
          examples:
            - account not found at provider
          type: string
      type: object
  securitySchemes:
    BearerAuth:
      bearerFormat: JWT
      description: JWT bearer token issued by the identity provider.
      scheme: bearer
      type: http
info:
  description: API for the Lerian SISBAJUD Mensageria, the regulatory side of Lerian SISBAJUD. It covers institution configuration, order and file queries, return files, LGPD requests, key rotation, non-compliance justifications and the Lerian STA dead-letter queue.
  title: Lerian SISBAJUD Mensageria API
  version: 1.0.0
openapi: 3.1.0
paths:
  /v1/institutions:
    post:
      description: Creates a new institution configuration (create-only; 409 if one already exists for the id) and provisions its tokenization PRF + audit MAC keysets in the same flow. The institution id is supplied in the request body. With KMS_PROVIDER=aws managed, a key the institution alias names that is not yet registered (another provisioning holds it) maps to 503 SBJ-0008 (retryable), and one that is not the registered key maps to 409 SBJ-0012 (not retryable; nothing is adopted).
      operationId: create-institution-config
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateInstitutionConfigRequest"
        required: true
      responses:
        "201":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/InstitutionConfigResponse"
          description: Created
        "409":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: "SBJ-0007: a configuration already exists for the id, or the institution code is taken. SBJ-0012 (KMS_PROVIDER=aws managed): the key behind the institution alias is not the registered key; nothing is adopted; not retryable."
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: "SBJ-0002: internal error. The body detail is \"internal error\"."
        "503":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: "SBJ-0008 (KMS_PROVIDER=aws managed): the institution's key provisioning is in progress; retryable. The body detail is \"internal error\"."
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Create institution config and provision keys
      tags:
        - Institution
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/create-institution-config-and-provision-keys
  /v1/institutions/{institutionId}:
    get:
      description: Returns the institution's configuration as a safe metadata view. The institution is addressed by the path id.
      operationId: get-institution-config
      parameters:
        - description: The institution's unique identifier (UUID).
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            type: string
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/InstitutionConfigResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Get institution config by id
      tags:
        - Institution
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/get-institution-config-by-id
    patch:
      description: Applies a partial update (institutionCode/retryPolicyConfig/enabled) to an existing institution configuration addressed by the path id. Returns 404 when the institution has no configuration.
      operationId: patch-institution-config
      parameters:
        - description: The institution's unique identifier (UUID).
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PatchInstitutionConfigRequest"
        required: true
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/InstitutionConfigResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Update institution config by id
      tags:
        - Institution
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/update-institution-config-by-id
  /v1/institutions/{institutionId}/audit/verify:
    get:
      description: Re-verifies a contiguous slice of the institution's append-only audit log by leaf index, without decrypting any payload. Returns a tamper / internal-deletion report. The institution comes from the path; a malformed institutionId is 400 and a caller without the role is 403.
      operationId: verify-audit-trail
      parameters:
        - description: The institution whose audit trail is verified (UUID). Authorized by the caller's RBAC role.
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution whose audit trail is verified (UUID). Authorized by the caller's RBAC role.
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
        - description: Zero-based leaf index of the first event to verify (required).
          explode: false
          in: query
          name: fromIndex
          required: true
          schema:
            description: Zero-based leaf index of the first event to verify (required).
            examples:
              - "0"
            type: string
        - description: Zero-based leaf index of the last event to verify (required).
          explode: false
          in: query
          name: toIndex
          required: true
          schema:
            description: Zero-based leaf index of the last event to verify (required).
            examples:
              - "99"
            type: string
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AuditVerifyResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Verify audit trail integrity (admin)
      tags:
        - Admin
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/verify-audit-trail-integrity-admin
  /v1/institutions/{institutionId}/awaiting-decision-orders:
    get:
      description: Returns the institution-scoped paginated list of orders the return generator holds for a human decision and that are not resolved yet (no human decision recorded, never answered in a return file), with non-sensitive summary fields. An order leaves the list once decided or answered.
      operationId: list-awaiting-decision-orders
      parameters:
        - description: The institution's unique identifier (UUID).
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            type: string
        - description: Maximum items per page.
          explode: false
          in: query
          name: limit
          schema:
            description: Maximum items per page.
            examples:
              - 50
            format: int64
            type: integer
        - description: Pagination offset.
          explode: false
          in: query
          name: offset
          schema:
            description: Pagination offset.
            examples:
              - 0
            format: int64
            type: integer
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PageAdminOrderListItem"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: List orders awaiting a human decision (admin)
      tags:
        - Admin
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/list-orders-awaiting-a-human-decision-admin
  /v1/institutions/{institutionId}/failed-orders:
    get:
      description: Returns the institution-scoped paginated list of orders in the FAILED terminal state, plus orders with an open executor give-up non-compliance log (e.g. a reiteration whose original gave up), each with its own SLA deadline and non-sensitive summary fields.
      operationId: list-failed-orders
      parameters:
        - description: The institution's unique identifier (UUID).
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            type: string
        - description: Maximum items per page.
          explode: false
          in: query
          name: limit
          schema:
            description: Maximum items per page.
            examples:
              - 50
            format: int64
            type: integer
        - description: Pagination offset.
          explode: false
          in: query
          name: offset
          schema:
            description: Pagination offset.
            examples:
              - 0
            format: int64
            type: integer
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PageAdminOrderListItem"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: List failed orders (admin)
      tags:
        - Admin
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/list-failed-orders-admin
  /v1/institutions/{institutionId}/files:
    get:
      description: Returns the institution-scoped paginated list of remittance or return file metadata. No file content or encrypted bytes are exposed.
      operationId: list-files
      parameters:
        - description: The institution's unique identifier (UUID).
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            type: string
        - description: File type discriminator (remittance or return; defaults to remittance).
          explode: false
          in: query
          name: type
          schema:
            description: File type discriminator (remittance or return; defaults to remittance).
            examples:
              - remittance
            type: string
        - description: Filter by file status for the selected type.
          explode: false
          in: query
          name: status
          schema:
            description: Filter by file status for the selected type.
            examples:
              - PROCESSED
            type: string
        - description: Maximum items per page.
          explode: false
          in: query
          name: limit
          schema:
            description: Maximum items per page.
            examples:
              - 50
            format: int64
            type: integer
        - description: Pagination offset.
          explode: false
          in: query
          name: offset
          schema:
            description: Pagination offset.
            examples:
              - 0
            format: int64
            type: integer
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PageAdminFileListItem"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: List files (admin)
      tags:
        - Admin
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/list-files-admin
  /v1/institutions/{institutionId}/files/{id}:
    get:
      description: Returns the single-file metadata plus the decrypted file content (base64-encoded), elided per the request masking policy unless the caller is cleared for cleartext. Covers both remittance and return files.
      operationId: get-file-detail
      parameters:
        - description: The institution's unique identifier (UUID).
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            type: string
        - description: The file's unique identifier (UUID).
          in: path
          name: id
          required: true
          schema:
            description: The file's unique identifier (UUID).
            examples:
              - 660e8400-e29b-41d4-a716-446655440000
            type: string
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminFileDetailResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Get file detail (admin)
      tags:
        - Admin
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/get-file-detail-admin
  /v1/institutions/{institutionId}/lgpd/requests:
    post:
      description: Creates an LGPD access or portability request scoped to the path institution. The acting admin subject is derived from the validated identity; the CPF/CNPJ is tokenized server-side and never echoed. An institution with no tokenization keyset maps to 404.
      operationId: create-lgpd-request
      parameters:
        - description: The institution's unique identifier (UUID) the LGPD request is scoped to.
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID) the LGPD request is scoped to.
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PostLgpdRequestBody"
        required: true
      responses:
        "201":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PostLgpdRequestResponse"
          description: Created
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Create an LGPD data-subject request
      tags:
        - LGPD
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/create-an-lgpd-data-subject-request
  /v1/institutions/{institutionId}/lgpd/requests/{id}/resolve:
    post:
      description: Records the decision (fulfilled, refused, partial) for an existing LGPD request. A not-found request maps to 404; an already-resolved (terminal) request maps to 409.
      operationId: resolve-lgpd-request
      parameters:
        - description: The institution's unique identifier (UUID) the LGPD request is scoped to.
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID) the LGPD request is scoped to.
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
        - description: The LGPD request id to resolve.
          in: path
          name: id
          required: true
          schema:
            description: The LGPD request id to resolve.
            examples:
              - 11111111-1111-1111-1111-111111111111
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PostResolveLgpdRequestBody"
        required: true
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PostResolveLgpdResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Record the resolution of an LGPD request
      tags:
        - LGPD
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/record-the-resolution-of-an-lgpd-request
  /v1/institutions/{institutionId}/lgpd/subject-data:
    get:
      description: Tokenizes the query subject value across all active key versions, reunites the institution-scoped orders, decrypts each in full, and returns the subject export. The response body is the only place the decrypted subject data surfaces.
      operationId: export-lgpd-subject-data
      parameters:
        - description: The institution's unique identifier (UUID) the subject data is scoped to.
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID) the subject data is scoped to.
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
        - description: The data subject's cleartext CPF or CNPJ (tokenized server-side; never logged).
          explode: false
          in: query
          name: cpf_cnpj
          schema:
            description: The data subject's cleartext CPF or CNPJ (tokenized server-side; never logged).
            examples:
              - "52998224725"
            type: string
        - description: The document type (cpf or cnpj); inferred from the subject value when omitted.
          explode: false
          in: query
          name: doc_type
          schema:
            description: The document type (cpf or cnpj); inferred from the subject value when omitted.
            examples:
              - cpf
            type: string
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SubjectExport"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Export a data subject's records
      tags:
        - LGPD
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/export-a-data-subject-s-records
  /v1/institutions/{institutionId}/non-compliance-logs/{id}/justification:
    post:
      description: Registers an institution's justification on an SLA-breach non-compliance log. An empty or oversized justification maps to 400; an absent record to 404; an already-justified record to 409. The audit actor is derived from the validated identity (403 when absent).
      operationId: register-non-compliance-justification
      parameters:
        - description: The institution's unique identifier (UUID) the non-compliance log belongs to.
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID) the non-compliance log belongs to.
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
        - description: The non-compliance log id to register the justification against.
          in: path
          name: id
          required: true
          schema:
            description: The non-compliance log id to register the justification against.
            examples:
              - bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PostJustificationBody"
        required: true
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PostJustificationResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Register a justification on a non-compliance log
      tags:
        - Non-Compliance
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/register-a-justification-on-a-non-compliance-log
  /v1/institutions/{institutionId}/orders:
    get:
      description: Returns the institution-scoped paginated list of judicial orders with non-sensitive summary fields. The institution is addressed by the path id; filters (status, tipo_ordem, period, subject) are optional.
      operationId: list-orders
      parameters:
        - description: The institution's unique identifier (UUID).
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            type: string
        - description: Filter by judicial order status.
          explode: false
          in: query
          name: status
          schema:
            description: Filter by judicial order status.
            examples:
              - PENDING
            type: string
        - description: Filter by order type.
          explode: false
          in: query
          name: tipo_ordem
          schema:
            description: Filter by order type.
            examples:
              - BLOQUEIO
            type: string
        - description: Period start (RFC3339).
          explode: false
          in: query
          name: periodo_inicio
          schema:
            description: Period start (RFC3339).
            examples:
              - "2026-01-01T00:00:00Z"
            type: string
        - description: Period end (RFC3339).
          explode: false
          in: query
          name: periodo_fim
          schema:
            description: Period end (RFC3339).
            examples:
              - "2026-01-31T23:59:59Z"
            type: string
        - description: Filter by subject CPF/CNPJ (tokenized server-side).
          explode: false
          in: query
          name: cpf_cnpj
          schema:
            description: Filter by subject CPF/CNPJ (tokenized server-side).
            examples:
              - "52998224725"
            type: string
        - description: Subject document type (cpf or cnpj; inferred when absent).
          explode: false
          in: query
          name: doc_type
          schema:
            description: Subject document type (cpf or cnpj; inferred when absent).
            examples:
              - cpf
            type: string
        - description: Maximum items per page.
          explode: false
          in: query
          name: limit
          schema:
            description: Maximum items per page.
            examples:
              - 50
            format: int64
            type: integer
        - description: Pagination offset.
          explode: false
          in: query
          name: offset
          schema:
            description: Pagination offset.
            examples:
              - 0
            format: int64
            type: integer
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PageAdminOrderListItem"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: List orders (admin)
      tags:
        - Admin
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/list-orders-admin
  /v1/institutions/{institutionId}/orders/{id}:
    get:
      description: Returns the fully decrypted single-order detail with sensitive fields masked per the request masking policy. A cleartext-authorized read reveals the fields and records the access in the audit trail.
      operationId: get-order
      parameters:
        - description: The institution's unique identifier (UUID).
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            type: string
        - description: The judicial order's unique identifier (UUID).
          in: path
          name: id
          required: true
          schema:
            description: The judicial order's unique identifier (UUID).
            examples:
              - 660e8400-e29b-41d4-a716-446655440000
            type: string
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OrderDetail"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Get order detail (admin)
      tags:
        - Admin
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/get-order-detail-admin
  /v1/institutions/{institutionId}/return-file/generate:
    post:
      description: Forces one return-file generation for the institution in the path and returns the generated file's summary. A malformed institutionId is 400; a caller without the role is 403; an institution not configured with an institution_code is 422; a missing reception flow fails closed with 503.
      operationId: generate-return-file
      parameters:
        - description: The institution the return file is generated for (UUID). Authorized by the caller's RBAC role.
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution the return file is generated for (UUID). Authorized by the caller's RBAC role.
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ReturnFileGenerateResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Force a return-file generation
      tags:
        - Return File
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/force-a-return-file-generation
  /v1/institutions/{institutionId}/return-file/{id}/reconsolidate:
    post:
      description: "Releases the judicial orders held by a FAILED return file so a later generation can answer them. The file STAYS FAILED — it is the record that an attempt was made and did not arrive. Answers with how many orders were released and, when the file answers a remittance, the response deadline that the Mensageria computed. Refused with 409 while the Lerian STA transfer may still be live (a size mismatch whose cancel did not succeed): releasing then would put the same judicial answers in front of BACEN twice. 422 when the file is not FAILED or records no Lerian STA terminal; 404 when it does not exist."
      operationId: reconsolidate-return-file
      parameters:
        - description: The institution the return file belongs to (UUID). Authorized by the caller's RBAC role.
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution the return file belongs to (UUID). Authorized by the caller's RBAC role.
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
        - description: The return file id (UUID).
          in: path
          name: id
          required: true
          schema:
            description: The return file id (UUID).
            examples:
              - dddddddd-dddd-dddd-dddd-dddddddddddd
            type: string
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ReturnFileReconsolidateResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Release a failed return file's judicial orders
      tags:
        - Return File
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/release-a-failed-return-file-s-judicial-orders
  /v1/institutions/{institutionId}/return-file/{id}/resolve-transmission:
    post:
      description: Applies one human remedy to a submission no automatic path can finish. probe_now asks Lerian STA whether a transfer for this file already exists and binds it if so; attach_transfer binds a transfer you located, but ONLY after Lerian STA confirms it belongs to this file; force_fail gives up on a stuck submission so the file becomes reconsolidable, but only once its last submission attempt is 5 minutes old and only after Lerian STA shows no transfer for the file that can still reach BACEN (none, or one that ended Rejected, Inconsistent, Canceled or NotAuthorized); otherwise it is refused with 422; cancel_now retries cancelling a size-mismatched transfer that is still live at Lerian STA. Any action answers 503 when Lerian STA cannot be reached. reason is required and MUST NOT contain personal data or monetary values — it is written verbatim into the audit trail. 422 names the door that IS open when the action does not apply to the file's state.
      operationId: resolve-return-file-transmission
      parameters:
        - description: The institution the return file belongs to (UUID). Authorized by the caller's RBAC role.
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution the return file belongs to (UUID). Authorized by the caller's RBAC role.
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
        - description: The return file id (UUID).
          in: path
          name: id
          required: true
          schema:
            description: The return file id (UUID).
            examples:
              - dddddddd-dddd-dddd-dddd-dddddddddddd
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ReturnFileResolveTransmissionRequest"
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ReturnFileResolveTransmissionResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Resolve a stuck return-file transmission
      tags:
        - Return File
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/resolve-a-stuck-return-file-transmission
  /v1/institutions/{institutionId}/security/kek:rotate:
    post:
      description: "Triggers a manual key-encryption-key rotation for the addressed institution. The KEK advances and the registry mirror syncs; the per-record DEKs are rewrapped asynchronously by the backfill (rewrapStatus IN_PROGRESS), and audit_event DEKs are never rewrapped. An institution with no provisioned (ACTIVE registered) key maps to 404 (SBJ-0005) before any KMS call, with either KMS_PROVIDER. A key registry whose ACTIVE version is behind the KMS's live version maps to 409 SBJ-0012 before any KMS call (restart the service to reconcile, then retry); one ahead of it maps to 409 SBJ-0012 (not retryable). The live version read made before any KMS call also maps to 409 SBJ-0012 (not retryable; nothing is rotated or written), with either KMS_PROVIDER, when the registered key is no longer in the KMS (vault: the Transit key is missing; aws: the alias or the key is gone), when the KMS denies access to the key (aws AccessDenied, on the key or on its key-material listing), when the key is disabled or not in a usable state, or when the recorded key version is not readable. 409 SBJ-0007 means only a contended same-institution rotation (retryable once it completes). 409 SBJ-0012 (not retryable) covers, with KMS_PROVIDER=aws managed, a registered reference that cannot be verified (legacy alias label, bare multi-Region id or malformed; refused before any KMS call), a key behind the alias that differs from the registered key, or a registered key no longer reachable under its alias (all not retryable; nothing is rotated or written). A definitive KMS refusal of the rotation request also maps to 409 (SBJ-0012, not retryable, nothing rotated): with aws managed access denied, key not found, key disabled or not in a rotatable state, or the key's on-demand rotation quota exhausted; with vault any 4xx answer to the Transit rotate write other than 429. A transient KMS failure before any rotation maps to 503 (SBJ-0008, retryable): with aws throttling of the single rotation request attempt (the SDK does not retry it); with vault a 429 on the Transit rotate write or a transient failure before it. A rotation whose outcome is unknown maps to 500 SBJ-0013 (rotation outcome unknown; do not retry; the key registry reconciles on service restart): an uncertain failure of the rotation request (aws: timeout, server fault, conflict, transport; vault: a 5xx, 408, transport error or timeout on the Transit rotate write) whose KMS advance is not proven by the live version read that follows it. A KEK owned by the key custodian (KMS_PROVIDER=aws with KMS_AWS_KEY_MODE=provided) is never rotated by the service and maps to 422 with nothing changed (no lock, no audit, no KMS call); a rotation the KMS is proven to have made (the rotation request completed, or the live version read after an uncertain one shows the key advanced) whose follow-up was refused or failed (registry advance or audit) maps to 500 SBJ-0014 (do not retry), whatever the cause. Every other 500 is SBJ-0002. Every 5xx body is the generic \"internal error\"; the code is the client's branch."
      operationId: rotate-institution-kek
      parameters:
        - description: The institution's unique identifier (UUID) the KEK rotation targets.
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID) the KEK rotation targets.
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RotateKEKRequest"
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RotateInstitutionKekResponse"
          description: OK
        "404":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: "SBJ-0005: the institution has no provisioned key (either KMS_PROVIDER); nothing was rotated."
        "409":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: "SBJ-0007: a rotation already in progress (retryable). SBJ-0012: the key registry is behind the key custodian (restart the service to reconcile, then retry) or ahead of it (not retryable), both before any KMS call; on the live version read before any KMS call (not retryable) a registered key no longer in the KMS, an access denial (aws), a disabled key or a recorded key version that is not readable; (KMS_PROVIDER=aws managed, not retryable) a registered reference that cannot be verified, a key behind the alias that differs from the registered key or one no longer reachable under it; or a definitive KMS refusal of the rotation request (aws: access denied, not found, disabled, rotation quota exhausted; vault: a 4xx other than 429 on the Transit rotate write); not retryable."
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: "SBJ-0013: rotation outcome unknown; do not retry; the key registry reconciles on service restart. SBJ-0014: rotation committed but a follow-up step failed; do not retry. SBJ-0002: any other internal error. The body detail is always \"internal error\"."
        "503":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: "A transient KMS failure before any rotation (aws: throttling of the single rotation request attempt; vault: a 429 on the Transit rotate write, or a transient failure before it); retryable."
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Rotate an institution's KEK
      tags:
        - Security
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/rotate-an-institution-s-kek
  /v1/institutions/{institutionId}/security/keyset:rotate:
    post:
      description: Triggers a manual tokenization-keyset rotation (adds a fresh primary PRF key) for the addressed institution. A contended same-institution rotation or a stale-version optimistic-concurrency conflict maps to 409; an institution with no active keyset maps to 422; a committed-but-unaudited rotation maps to 500 (non-retryable; escalate).
      operationId: rotate-institution-keyset
      parameters:
        - description: The institution's unique identifier (UUID) the keyset rotation targets.
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID) the keyset rotation targets.
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/RotateKeysetRequest"
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/RotateKeysetResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Rotate an institution's tokenization keyset
      tags:
        - Security
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/rotate-an-institution-s-tokenization-keyset
  /v1/institutions/{institutionId}/sla-status:
    get:
      description: "Returns the institution-scoped SLA-risk view of active (non-terminal) orders: per-band counts plus per-order detail. No PII, no decryption."
      operationId: get-sla-status
      parameters:
        - description: The institution's unique identifier (UUID).
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            type: string
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SlaStatusResult"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Get SLA status (admin)
      tags:
        - Admin
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/get-sla-status-admin
  /v1/institutions/{institutionId}/sta-dlq/{eventId}/acknowledge:
    post:
      description: "Writes the audit record that answers the three-day dead-letter window: which parked record, from which direction, under which parking token, and what the operator did about it (replayed, recorded, escalated). It does NOT remove anything: the dead-letter destination is the Kafka topic lerian.streaming.br-sisbajud.dlq, a LOG with its own retention, so a treated record stays exactly where it is and this acknowledgement — not the record's absence — is what says it was handled. Replaying means seeking the consumer group back to the source offset the record's headers name. Answers with a receipt id for the ticket. 422 when the parking token is not one the consumer emits, when the action is unknown, or when institutionId or eventId are missing — the refusal carries a code and a canned detail, so the valid tokens are published as this request's reason enum rather than named in the answer."
      operationId: acknowledge-sta-dlq-event
      parameters:
        - description: "The institution on whose behalf the dead-letter queue was drained, authorized by the caller's RBAC role. This is NOT necessarily the institution the message resolved to: institution_unresolved is itself one of the parking reasons, and a message parked under it resolved to nobody."
          in: path
          name: institutionId
          required: true
          schema:
            description: "The institution on whose behalf the dead-letter queue was drained, authorized by the caller's RBAC role. This is NOT necessarily the institution the message resolved to: institution_unresolved is itself one of the parking reasons, and a message parked under it resolved to nobody."
            examples:
              - 44444444-4444-4444-4444-444444444444
            type: string
        - description: Lerian STA's event id, exactly as it appears on the parked message. It is a string on Lerian STA's side and is not required to be a UUID.
          in: path
          name: eventId
          required: true
          schema:
            description: Lerian STA's event id, exactly as it appears on the parked message. It is a string on Lerian STA's side and is not required to be a UUID.
            examples:
              - evt-7f3c9a10
            type: string
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/STADLQAcknowledgeRequest"
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/STADLQAcknowledgeResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Record the human treatment of a parked STA event
      tags:
        - STA Dead-Letter
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/record-the-human-treatment-of-a-parked-sta-event
  /v1/institutions/{institutionId}/stats:
    get:
      description: "Returns the institution-scoped processing statistics: total order count plus breakdowns by status and tipo_ordem, optionally constrained to a created_at window."
      operationId: get-processing-stats
      parameters:
        - description: The institution's unique identifier (UUID).
          in: path
          name: institutionId
          required: true
          schema:
            description: The institution's unique identifier (UUID).
            examples:
              - 550e8400-e29b-41d4-a716-446655440000
            type: string
        - description: Period start (RFC3339).
          explode: false
          in: query
          name: periodo_inicio
          schema:
            description: Period start (RFC3339).
            examples:
              - "2026-01-01T00:00:00Z"
            type: string
        - description: Period end (RFC3339).
          explode: false
          in: query
          name: periodo_fim
          schema:
            description: Period end (RFC3339).
            examples:
              - "2026-01-31T23:59:59Z"
            type: string
        - description: Maximum items per page (ignored for stats).
          explode: false
          in: query
          name: limit
          schema:
            description: Maximum items per page (ignored for stats).
            examples:
              - 50
            format: int64
            type: integer
        - description: Pagination offset (ignored for stats).
          explode: false
          in: query
          name: offset
          schema:
            description: Pagination offset (ignored for stats).
            examples:
              - 0
            format: int64
            type: integer
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminProcessingStatsResponse"
          description: OK
        "422":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Unprocessable Entity
        "500":
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Internal Server Error
        default:
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Detail"
          description: Error
      summary: Get processing stats (admin)
      tags:
        - Admin
      x-mint:
        href: /pt/reference/rails/sisbajud/mensageria/get-processing-stats-admin
security:
  - BearerAuth: []
servers:
  - url: https://api.example.com
    description: Replace the example host with the URL provided during environment onboarding.
tags:
  - description: "Institution configuration lifecycle: create (with key provisioning), read, and partial update of an institution configuration addressed by institution id."
    name: Institution
  - description: LGPD data-subject access, portability and resolution operations, addressed by institution id.
    name: LGPD
  - description: "Manual cryptographic key administration: KEK and tokenization-keyset rotation for an institution, addressed by institution id."
    name: Security
  - description: Non-compliance-log administration, such as registering an SLA-breach justification, addressed by institution id.
    name: Non-Compliance
  - description: Return (response) file administration, such as forcing an on-demand return-file generation outside the scheduled cron.
    name: Return File
  - description: "Admin read API: institution-scoped order, file, SLA, and processing-stats queries, plus audit-trail integrity verification. PII fields are masked unless the caller proves a cleartext grant."
    name: Admin
