openapi: 3.1.0
info: {title: accountingd, version: 0.1.0}
security: [{bearer: []}]
components:
  securitySchemes: {bearer: {type: http, scheme: bearer}}
  parameters:
    id: {name: id, required: true, in: path, schema: {type: string, format: uuid}}
  schemas:
    IssuedBatchPage:
      type: object
      additionalProperties: false
      required: [month, journal, adviser, client, items, next]
      properties:
        month: {type: string, pattern: '^[0-9]{4}-[0-9]{2}$'}
        journal: {type: string}
        adviser: {type: string}
        client: {type: string}
        items:
          type: array
          maxItems: 100
          items:
            type: object
            additionalProperties: false
            required: [id, issued_on, profile_revision, entries, rows, parts]
            properties:
              id: {type: string, format: uuid}
              issued_on: {type: string, format: date}
              profile_revision: {type: string}
              entries: {type: integer, minimum: 1}
              rows: {type: integer, minimum: 1}
              parts: {type: integer, minimum: 1}
        next:
          type: [string, 'null']
          description: Opaque continuation for the same selection. Null on the last page.
    ExportPreview:
      type: object
      required: [month, journal, adviser, client, profile_revision, profile_sha256, journal_bound, journal_root, entries, rows, controls, files, preview_digest]
      properties:
        month: {type: string, pattern: '^[0-9]{4}-[0-9]{2}$'}
        journal: {type: string}
        adviser: {type: string}
        client: {type: string}
        profile_revision: {type: string}
        profile_sha256: {type: string, pattern: '^[0-9a-f]{64}$'}
        journal_bound: {type: integer, minimum: 0}
        journal_root: {type: string}
        preview_digest:
          type: string
          pattern: '^[0-9a-f]{64}$'
          description: SHA-256 of the compact UTF-8 preview JSON, with object keys sorted recursively and array order preserved. Omit preview_digest and the receipt-only fields id, issuer and issued_on.
        entries: {type: integer, minimum: 0}
        rows: {type: integer, minimum: 0}
        controls:
          type: object
          description: Turnover by mapped account in exact euro cents.
          additionalProperties:
            type: object
            required: [debit_cents, credit_cents]
            properties:
              debit_cents: {type: string, pattern: '^[0-9]+$'}
              credit_cents: {type: string, pattern: '^[0-9]+$'}
        files:
          type: array
          items:
            type: object
            required: [part, bytes, sha256, first_entry, last_entry, rows, entries]
            properties:
              part: {type: integer, minimum: 1}
              first_entry: {type: string, format: uuid}
              last_entry: {type: string, format: uuid}
              rows: {type: integer, minimum: 1, maximum: 99999}
              entries: {type: integer, minimum: 1}
              bytes: {type: integer, minimum: 1}
              sha256: {type: string, pattern: '^[0-9a-f]{64}$'}
    ExportReceipt:
      allOf:
        - {$ref: '#/components/schemas/ExportPreview'}
        - type: object
          required: [id, issuer, issued_on]
          properties:
            id: {type: string, format: uuid}
            issuer: {type: string}
            issued_on: {type: string, format: date}
    AgentCredit: {"type": "object", "additionalProperties": false, "required": ["id", "account", "bill", "line", "amount_cents", "line_cents", "due_cents", "remaining_line_cents", "reviewer", "approved_on"], "properties": {"id": {"type": "string", "format": "uuid"}, "account": {"type": "string", "format": "uuid"}, "bill": {"type": "string", "format": "uuid"}, "line": {"type": "integer", "minimum": 0}, "amount_cents": {"type": "integer", "minimum": 1}, "line_cents": {"type": "integer", "minimum": 1}, "due_cents": {"type": "integer", "minimum": 1}, "remaining_line_cents": {"type": "integer", "minimum": 1}, "reviewer": {"type": "string", "minLength": 1, "maxLength": 1000}, "approved_on": {"type": "string", "format": "date"}}}
    OnlineBudget:
      type: object
      required: [budget_cents, held_cents, grant_allowed]
      properties:
        budget_cents: {type: integer, minimum: 0, description: Maximum replacement hold after this settlement}
        held_cents: {type: integer, minimum: 0, description: Current hold for the session}
        grant_allowed: {type: boolean, description: False blocks new units including free units}
    OnlineReceipt:
      type: object
      required: [budget_cents, held_cents, funded_cents, excess_cents, journal]
      properties:
        budget_cents: {type: integer, minimum: 0, description: Remaining headroom after the replacement hold}
        held_cents: {type: integer, minimum: 0}
        funded_cents: {type: integer, minimum: 0}
        excess_cents: {type: integer, minimum: 0, description: Unreserved reported use covered by the operator}
        journal: {type: [string, 'null'], description: Posting reference for this settlement}
    PrepaidWallet:
      type: object
      required: [account, business_date, enrolled_on, available_cents, reserved_cents, balance_cents, shortfall_cents, spent_cents, cap_cents, rf, subscriptions, restriction, movements, last_processed_at, last_rated_at]
      properties:
        account: {type: string, format: uuid}
        business_date: {type: string, format: date}
        enrolled_on: {type: string, format: date}
        available_cents: {type: integer, minimum: 0, description: Spendable balance after outstanding online reservations}
        reserved_cents: {type: integer, minimum: 0, description: Active monetary holds across all months}
        balance_cents: {type: integer, minimum: 0, description: Confirmed journal liability before holds}
        shortfall_review: {type: [string, 'null'], format: uuid, description: Current finance review identity}
        shortfall_cents: {type: integer, minimum: 0}
        spent_cents: {type: integer, minimum: 0}
        cap_cents: {type: integer, minimum: 0}
        rf: {type: string, description: Structured creditor reference for funding}
        subscriptions: {type: array, items: {type: string, format: uuid}}
        restriction:
          oneOf: [{$ref: '#/components/schemas/PrepaidProposal'}, {type: 'null'}]
        last_processed_at: {type: [string, 'null'], format: date-time}
        last_rated_at: {type: [string, 'null'], format: date-time}
        movements:
          type: array
          maxItems: 100
          items:
            type: object
            required: [kind, date, delta_cents, recorded_at]
            properties:
              journal: {type: [string, 'null'], description: Posted journal reference}
              rating_evidence: {type: [string, 'null'], description: Rating revision visible to support and finance}
              actor: {type: string, description: Visible to finance}
              service_month: {type: [string, 'null'], format: date}
              exposure_cents: {type: integer, description: Signed change in operator coverage}
              input:
                type: object
                properties:
                  receipt: {type: string}
                  evidence: {type: string}
                  month: {type: string, format: date}
              kind: {enum: [fund, reversal, charge, cap, resolution, online]}
              date: {type: string, format: date}
              recorded_at: {type: string, format: date-time}
              delta_cents: {type: integer, description: Signed change in available credit}
    PrepaidProposal:
      type: object
      required: [id, account, revision, action, reason, scope, status, emergency_exempt, last_confirmed_action, last_confirmed_at, ready_at, acknowledged_at]
      properties:
        id: {type: string, format: uuid}
        account: {type: string, format: uuid}
        revision: {type: integer, minimum: 1}
        action: {enum: [restrict, release]}
        reason: {enum: [empty, cap, shortfall, cleared]}
        scope: {type: array, items: {type: string, format: uuid}}
        status: {enum: [pending, failed, confirmed]}
        emergency_exempt: {type: boolean, const: true}
        last_confirmed_at: {type: [string, 'null'], format: date-time}
        last_confirmed_action: {enum: [restrict, release, null]}
        ready_at: {type: string, format: date-time}
        acknowledged_at: {type: [string, 'null'], format: date-time}
    PrepaidMetrics:
      type: object
      required: [month, pending, failed, oldest_unconfirmed_seconds, p95_ack_seconds, rated_updates, p95_decision_seconds, disputes, active_wallets, disputes_per_1000, exposure_cents]
      properties:
        month: {type: string, format: date}
        pending: {type: integer}
        failed: {type: integer}
        oldest_unconfirmed_seconds: {type: [number, 'null']}
        rated_updates: {type: integer}
        p95_decision_seconds: {type: [number, 'null']}
        p95_ack_seconds: {type: [number, 'null']}
        disputes: {type: integer}
        active_wallets: {type: integer}
        disputes_per_1000: {type: [number, 'null']}
        exposure_cents: {type: integer}
    CompensationAward:
      type: object
      additionalProperties: false
      required: [id, subscription, account, amount, approved_on, rule]
      properties:
        id: {type: string, format: uuid, description: Immutable approval case}
        subscription: {type: string, format: uuid}
        account: {type: string, format: uuid}
        amount: {type: string, description: Positive EUR amount with cent precision}
        approved_on: {type: string, format: date}
        rule: {type: string}
    CompensationReceipt:
      type: object
      required: [id, subscription, account, amount, approved_on, rule, reference]
      properties:
        id: {type: string, format: uuid}
        subscription: {type: string, format: uuid}
        account: {type: string, format: uuid}
        amount: {type: string}
        approved_on: {type: string, format: date}
        rule: {type: string}
        reference: {type: string, description: Journal entry ID for an outage or the journal document reference for a missed appointment}
    Receipt:
      type: object
      required: [id, bank_ref, booked_on, amount, reason]
      properties:
        id: {type: string, description: Immutable booked receipt identifier}
        bank_ref: {type: string}
        booked_on: {type: string, format: date}
        amount: {type: string}
        reason: {enum: [matched, prepaid-reference, unknown-reference, no-unique-reference, amount-exceeds-due]}
    ReviewPage:
      type: object
      required: [items, next]
      properties:
        items: {type: array, items: {$ref: '#/components/schemas/Receipt'}}
        next: {type: [string, 'null']}
    Import:
      type: object
      required: [matched, review, duplicates, skipped]
      properties:
        matched: {type: integer}
        review: {type: integer}
        duplicates: {type: integer}
        skipped: {type: integer}
    Settlement:
      type: object
      required: [gross, paid, credits, open, payments]
      properties:
        gross: {type: string}
        paid: {type: string}
        credits: {type: string}
        open: {type: string}
        payments: {type: array, items: {$ref: '#/components/schemas/Receipt'}}
    Booking:
      type: object
      required: [bill, account, gross, draft]
      properties:
        bill: {type: string, format: uuid}
        account: {type: string, format: uuid}
        cites: {type: [string, 'null'], format: uuid}
        gross: {type: string}
        draft:
          type: object
          required: [key, date, kind, reference, sha256, postings]
          properties:
            key: {type: string}
            date: {type: string, format: date}
            kind: {enum: [invoice, final, credit-note]}
            reference: {type: string}
            sha256: {type: string}
            postings:
              type: array
              items:
                type: object
                required: [account, side, amount]
                properties: {account: {type: string}, side: {enum: [debit, credit]}, amount: {type: string}}
paths:
  /finance/exports:
    get:
      summary: List previously issued batches for one month and fiscal client
      description: Finance credentials can read retained batches across profile revisions. Results are newest issue first. A continuation excludes batches issued since the first page. Start again without a cursor to include them. All responses are private and no-store.
      parameters:
        - {in: query, name: month, required: true, schema: {type: string, pattern: '^[0-9]{4}-[0-9]{2}$'}}
        - {in: query, name: journal, required: true, schema: {type: string, minLength: 1, maxLength: 255, pattern: '^[!-*,-~]+$'}}
        - {in: query, name: adviser, required: true, schema: {type: string, pattern: '^[1-9][0-9]{3,6}$', not: {const: '1000'}}}
        - {in: query, name: client, required: true, schema: {type: string, pattern: '^[1-9][0-9]{0,4}$'}}
        - {in: query, name: limit, schema: {type: integer, minimum: 1, maximum: 100, default: 50}}
        - {in: query, name: cursor, description: Copy next from the previous page., schema: {type: string}}
      responses:
        '200': {description: Batches in the requested scope, content: {application/json: {schema: {$ref: '#/components/schemas/IssuedBatchPage'}}}}
        '401': {description: Valid bearer credential required}
        '403': {description: Finance credential required}
        '422': {description: Invalid selection (datev.selection) or unusable continuation (datev.cursor)}
  /finance/exports/preview:
    get:
      summary: Preview unclaimed posted EUR bookings for a calendar month
      description: Named finance credential. Checks pending commands at accountingd and billd before computing turnover. An empty month returns zero entries.
      parameters:
        - {in: query, name: month, required: true, schema: {type: string, pattern: '^[0-9]{4}-[0-9]{2}$'}}
      responses:
        '200': {description: Preview with file digests, content: {application/json: {schema: {$ref: '#/components/schemas/ExportPreview'}}}}
        '403': {description: Finance credential required}
        '409': {description: Pending commands or inconsistent controls}
        '422': {description: Invalid period or chart mapping}
        '503': {description: Export profile or source unavailable}
  /finance/exports/{id}:
    parameters: [{$ref: '#/components/parameters/id'}]
    put:
      summary: Issue or retrieve the immutable batch with this command UUID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [month, preview_digest]
              additionalProperties: false
              properties:
                month: {type: string, pattern: '^[0-9]{4}-[0-9]{2}$'}
                preview_digest: {type: string, pattern: '^[0-9a-f]{64}$'}
      responses:
        '200': {description: Issued or replayed receipt, content: {application/json: {schema: {$ref: '#/components/schemas/ExportReceipt'}}}}
        '403': {description: Finance credential required}
        '409': {description: "Changed preview, empty selection, pending bookings or conflicting request UUID"}
        '422': {description: "Invalid selection, digest or account mapping"}
        '503': {description: Export profile or source unavailable}
    get:
      summary: Read a stored receipt as a finance preparer
      responses:
        '200': {description: Immutable receipt, content: {application/json: {schema: {$ref: '#/components/schemas/ExportReceipt'}}}}
        '403': {description: Finance credential required}
        '404': {description: Unknown batch}
  /finance/exports/{id}/files/{part}:
    get:
      summary: Download an issued EXTF booking file
      parameters:
        - {$ref: '#/components/parameters/id'}
        - {name: part, in: path, required: true, schema: {type: integer, minimum: 1}}
      responses:
        '200':
          description: Immutable Windows-1252 CSV with CRLF line endings
          content: {text/csv: {schema: {type: string, format: binary}}}
        '403': {description: Finance credential required}
        '404': {description: Unknown batch or part}
  /agent-credit-basis/{id}:
    parameters: [{in: path, name: id, required: true, schema: {type: string, format: uuid}}]
    get:
      description: "Booking-only snapshot of invoice residual and goodwill already assigned to each line in cents."
      responses: {'200': {description: Success}, '403': {description: Credential outside scope}, '409': {description: Conflicting command or changed evidence}}
  /agent-credits:
    post:
      description: "Booking-only journal command. Matches reviewed balances under the settlement lock, posts once by proposal ID and returns the journal reference."
      requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/AgentCredit'}}}}
      responses: {'200': {description: Success}, '403': {description: Credential outside scope}, '409': {description: Conflicting command or changed evidence}}
  /prepaid/wallets/{id}/agent-evidence:
    get:
      summary: Booking credential only. Return the wallet figures billd can attest.
      parameters: [{$ref: '#/components/parameters/id'}]
      responses:
        '200':
          description: One committed snapshot of available credit, current month spending and last booked top-up
          content:
            application/json:
              schema:
                type: object
                required: [account, as_of, available_cents, spent_cents, last_topup_cents, last_topup_date]
                properties:
                  account: {type: string, format: uuid}
                  as_of: {type: string, format: date}
                  available_cents: {type: integer, minimum: 0}
                  spent_cents: {type: integer, minimum: 0}
                  last_topup_cents: {type: [integer, 'null'], minimum: 0}
                  last_topup_date: {type: [string, 'null'], format: date}
        '403': {description: Booking credential required}
        '404': {description: Wallet absent}
  /prepaid/wallets/{id}/html:
    get:
      description: German wallet statement for the authenticated account or authorized support.
      parameters: [{$ref: '#/components/parameters/id'}]
      responses:
        '200': {description: Private customer page, content: {text/html: {schema: {type: string}}}}
        '404': {description: Wallet unavailable to caller}
  /health:
    get:
      security: []
      responses: {'200': {description: Service identity}}
  /health/live:
    get:
      security: []
      responses: {'200': {description: Live}}
  /health/ready:
    get:
      security: []
      responses: {'200': {description: Ready}}
  /openapi.yaml:
    get:
      security: []
      responses: {'200': {description: OpenAPI}}
  /bookings:
    post:
      description: Accept an invoice posting or credit from the booking credential.
      requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/Booking'}}}}
      responses:
        '204': {description: Posted or already posted}
        '503': {description: "Journal unavailable, original booking pending or opening balances awaiting reconciliation. Retry the same booking."}
  /appointment-credits:
    post:
      description: Issue statutory compensation against an account, once per approved case. Requires the billing service booking credential.
      requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/CompensationAward'}}}}
      responses:
        '204': {description: Posted or already posted}
        '409': {description: Existing case has a different approval}
        '422': {description: Invalid approval}
        '503': {description: Journal unavailable or opening balances awaiting reconciliation. Retry the same award.}
  /appointment-credits/{id}:
    get:
      description: Journal receipt for a posted appointment compensation case.
      parameters: [{$ref: '#/components/parameters/id'}]
      responses:
        '200': {description: Posted, content: {application/json: {schema: {$ref: '#/components/schemas/CompensationReceipt'}}}}
        '404': {description: No posted credit for this case}
  /outage-credits:
    post:
      description: Book an approved total-outage award once using the private booking credential.
      requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/CompensationAward'}}}}
      responses:
        '204': {description: Credit recorded in the journal}
        '409': {description: A different decision already exists for this case}
        '422': {description: Invalid award}
        '503': {description: Journal unavailable. Retry the same award.}
  /outage-credits/{id}:
    get:
      description: Read a journal-confirmed credit with the private outage receipt credential.
      parameters: [{$ref: '#/components/parameters/id'}]
      responses:
        '200': {description: Frozen award and its 32-character hexadecimal journal entry ID, content: {application/json: {schema: {$ref: '#/components/schemas/CompensationReceipt'}}}}
        '404': {description: No confirmed posting for this case}
  /receivables/{id}:
    get:
      parameters: [{$ref: '#/components/parameters/id'}]
      responses: {'200': {description: Net ledger balance for a billing account, content: {application/json: {schema: {type: string}}}}}
  /bank-imports:
    post:
      description: Operator-only import of a camt.053.001.08 or camt.054.001.08 file, maximum 2 MiB.
      requestBody: {required: true, content: {application/xml: {schema: {type: string}}}}
      responses:
        '200': {description: Import outcomes, content: {application/json: {schema: {$ref: '#/components/schemas/Import'}}}}
        '503': {description: Journal unavailable or opening balances awaiting reconciliation. Retry the same statement.}
  /payment-review:
    get:
      parameters: [{name: before, in: query, schema: {type: string, pattern: '^[0-9]+$'}}]
      responses: {'200': {description: Up to 100 unapplied receipts in descending arrival order, content: {application/json: {schema: {$ref: '#/components/schemas/ReviewPage'}}}}}
  /settlements/{id}:
    get:
      parameters: [{$ref: '#/components/parameters/id'}]
      responses: {'200': {description: Reconciliation of one invoice or migrated open item, content: {application/json: {schema: {$ref: '#/components/schemas/Settlement'}}}}}
  /prepaid/proposals:
    get:
      description: Poll the latest pending or failed command per account. Apply increasing revisions per account, only to the prepaid gate on enrolled chargeable services in scope, leaving all independent bars in force and always preserving emergency access. Retry with the same id. Restart polling from the beginning after the last page.
      parameters:
        - {in: query, name: after, schema: {type: string, format: uuid}, description: Last account UUID returned}
      responses:
        '200':
          description: Up to 100 commands ordered by account
          content: {application/json: {schema: {type: array, items: {$ref: '#/components/schemas/PrepaidProposal'}}}}
  /prepaid/proposals/{id}/ack:
    put:
      description: Requires the dedicated prepaid-oss credential. A repeated confirmation returns the original acknowledgement time.
      parameters: [{$ref: '#/components/parameters/id'}]
      requestBody:
        required: true
        content: {application/json: {schema: {type: object, additionalProperties: false, required: [outcome], properties: {outcome: {enum: [confirmed, failed]}}}}}
      responses:
        '200': {description: Current acknowledgement, content: {application/json: {schema: {$ref: '#/components/schemas/PrepaidProposal'}}}}
        '409': {description: Superseded proposal or attempt to retract a confirmation}
  /prepaid/metrics:
    get:
      description: Current delivery backlog and monthly dispute, exposure and network confirmation measures. Dispute denominator counts accounts enrolled by month end. An empty cohort yields a null rate.
      parameters:
        - {in: query, name: month, schema: {type: string, format: date}, description: First day of a Berlin business month; defaults to current month}
      responses:
        '200': {description: Monthly measures and current backlog, content: {application/json: {schema: {$ref: '#/components/schemas/PrepaidMetrics'}}}}
  /prepaid/wallets/{id}/disputes/{case_id}:
    put:
      description: Register a unique bill-shock dispute on its first reporting date.
      parameters:
        - {$ref: '#/components/parameters/id'}
        - {in: path, name: case_id, required: true, schema: {type: string, format: uuid}}
      responses:
        '204': {description: Registered or already attributed to this account}
        '409': {description: Case already attributed to another account}
  /prepaid/wallets:
    post:
      summary: Enroll a verified set of subscriptions through billd
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [account, subscriptions, date, cap_cents]
              properties:
                account: {type: string, format: uuid}
                subscriptions: {type: array, minItems: 1, maxItems: 100, uniqueItems: true, items: {type: string, format: uuid}}
                date: {type: string, format: date}
                cap_cents: {type: integer, format: int64, minimum: 0}
      responses:
        '200': {description: Accepted command or matching replay}
        '409': {description: Conflicting reference or revision}
        '422': {description: Invalid request}
  /prepaid/top-ups:
    post:
      summary: Fund the wallet from one booked CAMT credit bearing its creditor reference
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [account, receipt]
              properties:
                account: {type: string, format: uuid}
                receipt: {type: string, description: Booked receipt id returned by payment review}
      responses:
        '200': {description: Accepted command or matching replay}
        '409': {description: Conflicting reference or revision}
        '422': {description: Invalid request}
  /prepaid/reversals:
    post:
      summary: Record a confirmed bank reversal with its reason and freeze any shortfall for review
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [account, receipt, date, reason]
              properties:
                account: {type: string, format: uuid}
                receipt: {type: string, description: Booked receipt id returned by payment review}
                date: {type: string, format: date}
                reason: {type: string, minLength: 1, maxLength: 500}
      responses:
        '200': {description: Accepted command or matching replay}
        '409': {description: Conflicting reference or revision}
        '422': {description: Invalid request}
  /prepaid/online-budget:
    post:
      summary: Quote the affordable next hold after settling actual usage
      description: Internal charging client. Amounts are nonnegative gross EUR cents.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [account, subscription, session, month, settle_cents]
              properties:
                account: {type: string, format: uuid}
                subscription: {type: string, format: uuid}
                session: {type: string, format: uuid}
                month: {type: string, format: date, description: First day of the session service month}
                settle_cents: {type: integer, format: int64, minimum: 0}
                covered_cents: {type: integer, format: int64, minimum: 0, default: 0, description: Operator share of the reported charge for unauthorized usage}
      responses:
        '200':
          description: Wallet decision
          content:
            application/json:
              schema: {$ref: '#/components/schemas/OnlineBudget'}
        '404': {description: Subscription or wallet not enrolled}
        '409': {description: Insufficient budget or conflicting invocation}
        '422': {description: Invalid command}
  /prepaid/online-postings:
    post:
      summary: Replace a monetary hold and settle reported usage atomically
      description: Internal charging client. Amounts are nonnegative gross EUR cents.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [account, subscription, session, month, settle_cents, sequence, reserve_cents, grant]
              properties:
                account: {type: string, format: uuid}
                subscription: {type: string, format: uuid}
                session: {type: string, format: uuid}
                month: {type: string, format: date, description: First day of the session service month}
                settle_cents: {type: integer, format: int64, minimum: 0}
                covered_cents: {type: integer, format: int64, minimum: 0, default: 0, description: Operator share of the reported charge for unauthorized usage}
                sequence: {type: integer, format: int64, minimum: 0}
                reserve_cents: {type: integer, format: int64, minimum: 0}
                grant: {type: boolean, description: Authorizes additional units including zero-cost units. False allows retention of existing holds only}
      responses:
        '200':
          description: Wallet decision
          content:
            application/json:
              schema: {$ref: '#/components/schemas/OnlineReceipt'}
        '404': {description: Subscription or wallet not enrolled}
        '409': {description: Insufficient budget or conflicting invocation}
        '422': {description: Invalid command}
  /prepaid/charges:
    post:
      summary: Apply the next cumulative rating revision for the subscription and service month
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [account, subscription, revision, rated_cents, evidence, month, date]
              properties:
                account: {type: string, format: uuid}
                subscription: {type: string, format: uuid}
                revision: {type: integer, format: int64, minimum: 1}
                rated_cents: {type: integer, format: int64, minimum: 0, description: Cumulative gross EUR cents}
                evidence: {type: string, format: uuid, description: Immutable billd rating evidence}
                month: {type: string, format: date, description: First day of the service month}
                date: {type: string, format: date}
      responses:
        '200': {description: Accepted command or matching replay}
        '409': {description: Conflicting reference or revision}
        '422': {description: Invalid request}
  /prepaid/caps:
    post:
      summary: Set the current and future gross monthly cap, retaining the reason
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [id, account, cap_cents, date, reason]
              properties:
                id: {type: string, format: uuid}
                account: {type: string, format: uuid}
                cap_cents: {type: integer, format: int64, minimum: 0}
                date: {type: string, format: date}
                reason: {type: string, minLength: 1, maxLength: 500}
      responses:
        '200': {description: Accepted command or matching replay}
        '409': {description: Conflicting reference or revision}
        '422': {description: Invalid request}
  /prepaid/wallets/{id}:
    parameters: [{$ref: '#/components/parameters/id'}]
    get:
      summary: Read the account balance, funding reference, last 100 movements and network status
      responses:
        '200':
          description: Current EUR wallet statement in integer cents
          content:
            application/json:
              schema: {$ref: '#/components/schemas/PrepaidWallet'}
        '404': {description: Wallet unavailable to this caller}
  /clock:
    get:
      summary: Read the accounting test clock
      responses: {'200': {description: Current business date and clock kind}}
    put:
      summary: Set the accounting test clock and reevaluate month boundaries
      requestBody:
        required: true
        content:
          application/json:
            schema: {type: object, additionalProperties: false, required: [today], properties: {today: {type: string, format: date}}}
      responses: {'200': {description: Current business date and clock kind}}
  /prepaid/shortfall-resolutions:
    post:
      summary: Conclude finance review of an expensed funding reversal
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [id, account, date, shortfall_cents, reason]
              properties:
                id: {type: string, format: uuid, description: Current shortfall_review from the operator wallet}
                account: {type: string, format: uuid}
                date: {type: string, format: date}
                shortfall_cents: {type: integer, format: int64, minimum: 1}
                reason: {type: string, minLength: 1, maxLength: 500}
      responses:
        '200': {description: Finance review recorded or replayed}
        '409': {description: Stale review or conflicting approval}
        '422': {description: Invalid reason or business date}
