openapi: 3.1.0
info:
  title: billd
  version: 0.1.0
  description: >-
    Price books, usage, the open bill, sealed bills with their HTML, PDF and e-invoice,
    Stornorechnungen and balances — billed from a projection of contract facts that arrive
    at /inbox as signed CloudEvents and are read back from the source. Its own events
    (source urn:telco:billd) are on /events. Account and operator routes require bearer credentials. Health, API descriptions and
    public tariff checks are anonymous. /inbox authenticates signed deliveries. Errors
    follow RFC 9457. TELCO_MCP=on enables /mcp and /agent/mcp. /clock requires a test clock.
servers:
  - url: http://127.0.0.1:9402
security:
  - bearer: []
components:
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
  parameters:
    idempotency:
      name: Idempotency-Key
      in: header
      required: false
      description: >-
        On any POST: a retry with the same key gets the first answer again (with
        Idempotent-Replayed: true), never a second effect. Per caller, bound to the method,
        path and body, kept 24 hours; 5xx answers are not kept.
      schema: { type: string, minLength: 1, maxLength: 255 }
    id:
      name: id
      in: path
      required: true
      schema: { type: string, format: uuid }
  schemas:
    OpenHold:
      type: object
      required: [billing_account, customer_number, name, period, code, since, rules, fix]
      properties:
        billing_account: { type: string, format: uuid }
        customer_number: { type: string }
        name: { type: string }
        period: { type: string }
        code: { type: string }
        since: { type: string, format: date }
        rules: { type: array, items: { type: string } }
        fix:
          type: [object, 'null']
          required: [field, operation]
          properties:
            field: { type: string }
            operation: { type: string }
    SelfcareBillLine:
      type: object
      required:
      - line
      - label
      - kind
      - item
      - from
      - to
      - amount
      - why
      properties:
        line:
          type: integer
          minimum: 0
        label:
          type: string
        kind:
          type: string
        item:
          type: string
        from:
          type: string
          format: date
        to:
          type: string
          format: date
        amount:
          type: string
          description: Exact decimal EUR amount
        why:
          type: string
    SelfcareBill:
      type: object
      required:
      - period
      - usage_state
      - gross
      - net
      - vat
      - prices
      - lines
      - id
      - number
      - kind
      - sealed_on
      - lang
      - due_on
      properties:
        period:
          type: string
        usage_state:
          type: string
          enum: [no-records, included, charged]
        gross:
          type: string
          description: Exact decimal EUR amount
        net:
          type: string
          description: Exact decimal EUR amount
        vat:
          type: string
          description: Exact decimal EUR amount
        prices:
          type: string
        lines:
          type: array
          items:
            $ref: '#/components/schemas/SelfcareBillLine'
        id:
          type: string
          format: uuid
        number:
          type: string
        kind:
          type: string
        sealed_on:
          type: string
          format: date
        lang:
          type: string
        due_on:
          anyOf:
          - type: string
            format: date
          - type: 'null'
    SelfcareBillSummary:
      type: object
      required:
      - id
      - number
      - sealed_on
      - kind
      - period
      - gross
      - read_on
      properties:
        id:
          type: string
          format: uuid
        number:
          type: string
        sealed_on:
          type: string
          format: date
        kind:
          type: string
        period:
          type: string
          format: date
        gross:
          type: string
          description: Exact decimal EUR amount
        read_on:
          anyOf:
          - type: string
            format: date
          - type: 'null'
    SelfcareObjection:
      type: object
      required:
      - id
      - bill
      - line
      - reason
      - status
      - received_on
      - answered_on
      - read_on
      - answer
      - remedy_bill
      - amount
      - currency
      - prices
      properties:
        id:
          type: string
          format: uuid
        bill:
          type: string
          format: uuid
        line:
          type: integer
          minimum: 0
        reason:
          type: string
        status:
          type: string
          enum:
          - received
          - answered
        received_on:
          type: string
          format: date
        answered_on:
          anyOf:
          - type: string
            format: date
          - type: 'null'
        read_on:
          anyOf:
          - type: string
            format: date
          - type: 'null'
        answer:
          anyOf:
          - type: string
          - type: 'null'
        remedy_bill:
          anyOf:
          - type: string
            format: uuid
          - type: 'null'
        amount:
          type: string
          description: Exact decimal EUR amount
        currency:
          const: EUR
        prices:
          type: string
    SelfcareBillReading:
      type: object
      required:
      - period
      - usage_state
      - gross
      - net
      - vat
      - prices
      - lines
      properties:
        period:
          type: string
        usage_state:
          type: string
          enum: [no-records, included, charged]
        gross:
          type: string
          description: Exact decimal EUR amount
        net:
          type: string
          description: Exact decimal EUR amount
        vat:
          type: string
          description: Exact decimal EUR amount
        prices:
          type: string
        lines:
          type: array
          items:
            $ref: '#/components/schemas/SelfcareBillLine'
    SelfcareBilling:
      type: object
      required:
      - account
      - as_of
      - open
      - open_error
      - bills
      - objections
      - subscriptions
      - plans
      properties:
        account:
          type: string
          format: uuid
        as_of:
          type: string
          format: date
        open:
          anyOf:
          - $ref: '#/components/schemas/SelfcareBillReading'
          - type: 'null'
        open_error:
          anyOf:
          - type: string
          - type: 'null'
        bills:
          type: array
          items:
            $ref: '#/components/schemas/SelfcareBillSummary'
        objections:
          type: array
          items:
            $ref: '#/components/schemas/SelfcareObjection'
        subscriptions:
          type: array
          items:
            type: object
            required:
            - id
            - book
            - plan
            properties:
              id:
                type: string
                format: uuid
              book:
                type: string
              plan:
                type: string
        plans:
          type: array
          items:
            type: object
            required:
            - reference
            - name
            properties:
              reference:
                type: string
              name:
                type: string
    SelfcarePreview:
      type: object
      required:
      - from
      - currency
      - assumption
      - current
      - proposed
      properties:
        from:
          type: string
          format: date
        currency:
          const: EUR
        assumption:
          type: string
        current:
          type: object
          required:
          - reference
          - first
          - regular
          - prices
          - first_lines
          - following_lines
          properties:
            reference:
              type: string
            first:
              type: string
              description: Exact decimal EUR amount
            regular:
              type: string
              description: Exact decimal EUR amount
            prices:
              enum: [gross, net]
              type: string
            first_lines:
              type: array
              items:
                type: object
                properties:
                  label:
                    type: string
                  kind:
                    type: string
                  item:
                    type: string
                  from:
                    type: string
                    format: date
                  to:
                    type: string
                    format: date
                  amount:
                    type: string
                    description: Exact decimal EUR amount
            following_lines:
              type: array
              items:
                type: object
                properties:
                  label:
                    type: string
                  kind:
                    type: string
                  item:
                    type: string
                  from:
                    type: string
                    format: date
                  to:
                    type: string
                    format: date
                  amount:
                    type: string
                    description: Exact decimal EUR amount
        proposed:
          type: object
          required:
          - reference
          - first
          - regular
          - prices
          - first_lines
          - following_lines
          properties:
            reference:
              type: string
            first:
              type: string
              description: Exact decimal EUR amount
            regular:
              type: string
              description: Exact decimal EUR amount
            prices:
              enum: [gross, net]
              type: string
            first_lines:
              type: array
              items:
                type: object
                properties:
                  label:
                    type: string
                  kind:
                    type: string
                  item:
                    type: string
                  from:
                    type: string
                    format: date
                  to:
                    type: string
                    format: date
                  amount:
                    type: string
                    description: Exact decimal EUR amount
            following_lines:
              type: array
              items:
                type: object
                properties:
                  label:
                    type: string
                  kind:
                    type: string
                  item:
                    type: string
                  from:
                    type: string
                    format: date
                  to:
                    type: string
                    format: date
                  amount:
                    type: string
                    description: Exact decimal EUR amount
    SelfcareVerification:
      type: object
      required:
      - path
      - expires_on
      - qr_path
      properties:
        path:
          type: string
        expires_on:
          type: string
          format: date
        qr_path:
          anyOf:
          - type: string
          - type: 'null'
    AgentProposal:
      type: object
      additionalProperties: false
      required:
      - id
      - contact_id
      - account
      - reason
      - action
      properties:
        id:
          type: string
          format: uuid
        contact_id:
          type: string
          format: uuid
        account:
          type: string
          format: uuid
        reason:
          type: string
          minLength: 1
          maxLength: 1000
        action:
          $ref: '#/components/schemas/AgentAction'
    AgentDecision:
      type: object
      additionalProperties: false
      required:
      - decision
      - reason
      properties:
        decision:
          enum:
          - approve
          - reject
        reason:
          type: string
          minLength: 1
          maxLength: 1000
        consent_reference:
          type: string
          maxLength: 256
    DispatchAck:
      type: object
      additionalProperties: false
      required:
      - reference
      - recipient
      - outcome
      properties:
        reference:
          type: string
          minLength: 1
          maxLength: 1000
        recipient:
          type: string
        outcome:
          enum:
          - sent
          - failed
    AgentAction:
      oneOf:
      - type: object
        additionalProperties: false
        required:
        - kind
        - bill
        - line
        - amount_cents
        properties:
          kind:
            const: credit
          bill:
            type: string
            format: uuid
          line:
            type: integer
            minimum: 0
          amount_cents:
            type: integer
            minimum: 1
      - type: object
        additionalProperties: false
        required:
        - kind
        - subscription
        - plan
        - from
        properties:
          kind:
            const: plan-switch
          subscription:
            type: string
            format: uuid
          plan:
            type: string
            minLength: 1
            maxLength: 1000
          from:
            type: string
            format: date
      - type: object
        additionalProperties: false
        required:
        - kind
        - answer_id
        properties:
          kind:
            const: dispute-answer
          answer_id:
            type: string
            format: uuid
    AgentReview:
      type: object
      required:
      - id
      - contact_id
      - account
      - reason
      - action
      - evidence
      - status
      - proposer
      - created_on
      - expires_on
      - decision_reason
      - decider
      - decided_on
      - receipt
      properties:
        id:
          type: string
          format: uuid
        contact_id:
          type: string
          format: uuid
        account:
          type: string
          format: uuid
        reason:
          type: string
          minLength: 1
          maxLength: 1000
        action:
          $ref: '#/components/schemas/AgentAction'
        evidence:
          type: object
          additionalProperties: true
          properties:
            label:
              type: string
            remaining_line_cents:
              type: integer
              format: int64
            due_cents:
              type: integer
              format: int64
            recipient:
              type: string
            current:
              type: object
              properties:
                plan:
                  type: string
            quote:
              type: object
              properties:
                sentence:
                  type: string
            answer:
              $ref: '#/components/schemas/CheckedAnswer'
            sha256: {type: string}
            book_hash: {type: string}
        status:
          type: string
          enum:
          - pending
          - approved
          - completed
          - rejected
          - expired
          - failed
          - stale
        proposer:
          type: string
        created_on:
          type: string
          format: date
        expires_on:
          type: string
          format: date
        decision_reason:
          type:
          - string
          - 'null'
        decider:
          type:
          - string
          - 'null'
        decided_on:
          type:
          - string
          - 'null'
          format: date
        receipt:
          type:
          - object
          - 'null'
          additionalProperties: true
    AgentClaim:
      type: object
      additionalProperties: false
      required: [field, value, unit]
      properties:
        field: {type: string, enum: [available, spent, last_topup, last_topup_date, as_of, period, number, sealed_on, net, tax, total]}
        value: {type: string, minLength: 1, maxLength: 80, description: 'Exact identifier or decimal, date or month in wire or German notation.'}
        unit: {type: string, enum: [eur, date, month, identifier]}
    AgentEvidenceSource:
      oneOf:
        - type: object
          required: [kind, system, bill, number, sha256]
          properties:
            kind: {const: bill}
            system: {const: billd}
            bill: {type: string, format: uuid}
            number: {type: string}
            sha256: {type: string}
        - type: object
          required: [kind, system, as_of]
          properties:
            kind: {const: wallet}
            system: {const: accountingd}
            as_of: {type: string, format: date}
    AgentEvidence:
      type: object
      required: [id, account, source, facts]
      properties:
        id: {type: string, format: uuid}
        account: {type: string, format: uuid}
        source: {$ref: '#/components/schemas/AgentEvidenceSource'}
        facts: {type: array, items: {$ref: '#/components/schemas/AgentClaim'}}
    CheckedAnswer:
      type: object
      required: [id, account, contact_id, evidence, text, sentences, source, disclosure, provenance]
      properties:
        id: {type: string, format: uuid}
        account: {type: string, format: uuid}
        contact_id: {type: string, format: uuid}
        evidence: {type: string, format: uuid}
        text: {type: string, description: Includes German AI disclosure and source context.}
        disclosure: {type: string}
        source: {$ref: '#/components/schemas/AgentEvidenceSource'}
        provenance: {type: object}
        sentences:
          type: array
          items:
            type: object
            required: [text, fact, evidence]
            properties:
              text: {type: string}
              fact: {$ref: '#/components/schemas/AgentClaim'}
              evidence: {type: string, format: uuid}
    AgentContactMetrics:
      type: object
      required: [month, eligible, handoffs, human_decisions, unresolved, reopened, confirmed_self_service, awaiting_follow_up, follow_up_days, self_service_percent]
      properties:
        month: {type: string}
        self_service_percent: {type: [integer, 'null']}
        eligible: {type: integer, minimum: 0}
        handoffs: {type: integer, minimum: 0}
        human_decisions: {type: integer, minimum: 0}
        unresolved: {type: integer, minimum: 0}
        reopened: {type: integer, minimum: 0}
        confirmed_self_service: {type: integer, minimum: 0}
        awaiting_follow_up: {type: integer, minimum: 0}
        follow_up_days: {type: integer, minimum: 0}
    PrepaidRating:
      type: object
      required: [id, subscription, account, month, revision, rated_cents, received_on, last_service_date, evidence, posted_at, receipt, error]
      properties:
        id: { type: string, format: uuid }
        subscription: { type: string, format: uuid }
        account: { type: string, format: uuid }
        month: { type: string, format: date, description: First service day of the calendar month }
        revision: { type: integer, format: int64, minimum: 1 }
        rated_cents: { type: integer, format: int64, minimum: 0 }
        received_on: { type: string, format: date }
        last_service_date: { type: string, format: date }
        evidence:
          type: object
          required: [books, subscriptions, usage, usage_sha256, totals]
          properties:
            books: { type: object, additionalProperties: { type: string } }
            subscriptions: { type: array, items: { type: object, additionalProperties: true } }
            usage: { type: array, items: { type: object, additionalProperties: true } }
            usage_sha256: { type: string, pattern: "^[a-f0-9]{64}$" }
            totals: { type: object, additionalProperties: true }
        posted_at: { type: [string, "null"], format: date-time }
        receipt:
          type: [object, "null"]
          required: [funded_cents, absorbed_cents]
          properties:
            funded_cents: { type: integer, format: int64, minimum: 0 }
            absorbed_cents: { type: integer, format: int64, minimum: 0 }
        error: { type: [string, "null"] }
    PrepaidRatingMetrics:
      type: object
      required: [pending, failed_attempts_pending, oldest_pending_seconds, posted_updates, posting_p95_seconds, source_lag_max_days]
      properties:
        pending: { type: integer, minimum: 0 }
        failed_attempts_pending: { type: integer, minimum: 0, description: Pending deliveries whose most recent attempt failed }
        oldest_pending_seconds: { type: [number, "null"] }
        posted_updates: { type: integer, minimum: 0 }
        posting_p95_seconds: { type: [number, "null"] }
        source_lag_max_days: { type: [integer, "null"] }
    MobileMeter:
      type: object
      required: [subscription, period, closed, volumes, notices, notice_enabled, last_usage_on, last_received_on, coverage_through, feed_state]
      properties:
        subscription: { type: string, format: uuid }
        period: { type: string, example: "2026-11" }
        closed: { type: boolean }
        notice_enabled: { type: boolean }
        notices:
          type: array
          items:
            type: object
            required: [kind, decided_on, message]
            properties:
              kind: { type: string, enum: [allowance, excessive] }
              decided_on: { type: string, format: date }
              message: { type: string }
        last_usage_on: { type: [string, "null"], format: date }
        last_received_on: { type: [string, "null"], format: date }
        coverage_through: { type: [string, "null"], format: date }
        feed_state: { type: string, enum: [unconfirmed, partial, complete] }
        volumes:
          type: array
          items:
            type: object
            required: [subscription, allowance, label, from, to, used_bytes, agreed_bytes, percent, coverage_through]
            properties:
              subscription: { type: string, format: uuid }
              allowance: { type: string }
              label: { type: string }
              from: { type: string, format: date }
              to: { type: string, format: date }
              used_bytes: { type: string, pattern: "^[0-9]+$" }
              agreed_bytes: { type: string, pattern: "^[0-9]+$" }
              percent: { type: string, description: "Percentage to one decimal place, rounded down." }
              coverage_through: { type: [string, "null"], format: date }
    MobileWarning:
      type: object
      required: [id, subscription_id, period, kind, rule, message, decided_on, state, deliveries]
      properties:
        id: { type: string, format: uuid }
        subscription_id: { type: string, format: uuid }
        period: { type: string }
        kind: { type: string, enum: [allowance, excessive] }
        rule: { type: string }
        message: { type: string }
        decided_on: { type: string, format: date }
        state: { type: string, enum: [pending, failed, delivered, suppressed] }
        deliveries:
          type: array
          items:
            type: object
            required: [outcome, reference, actor, recorded_on]
            properties:
              outcome: { type: string, enum: [failed, delivered] }
              reference: { type: string }
              actor: { type: string }
              recorded_on: { type: string, format: date }
    MobileNetwork:
      type: object
      additionalProperties: false
      required: [serving_country, access]
      properties:
        serving_country: { type: string, pattern: "^[A-Z]{2}$", description: Normalized territory of the serving network for this record. }
        access: { type: string, enum: [terrestrial, non-terrestrial, unknown] }
        destination_country: { type: string, pattern: "^[A-Z]{2}$", description: Called destination for ordinary outbound voice and SMS. Omit for data. }
        communication: { type: string, enum: [ordinary-outbound, value-added, incoming, unknown], description: Required for voice and SMS. Only ordinary outbound traffic can enter the tariff. Omit for data. }
        spend_control: { $ref: "#/components/schemas/MobileSpendReceipt" }
    MobileSpendReceipt:
      type: object
      additionalProperties: false
      required: [id, control_id, spent_net_cents]
      properties:
        id: { type: string, format: uuid, description: Serving-network receipt bound to one source record. }
        control_id: { type: string, format: uuid, description: Operator's witnessed network control. }
        spent_net_cents: { type: integer, minimum: 0, description: Cumulative calendar-month data roaming spend excluding VAT rounded up to cents. }
        warning: { type: string, format: uuid, description: Delivery evidence from 4000 cents. }
        cutoff_notice: { type: string, format: uuid, description: Limit notice evidence from 5000 cents. }
        additional_notice: { type: string, format: uuid, description: Additional notification evidence above 10000 cents. }
        continuation:
          type: object
          additionalProperties: false
          required: [receipt, through_net_cents]
          properties:
            receipt: { type: string, format: uuid, description: Explicit subscriber instruction to continue. }
            through_net_cents: { type: integer, minimum: 0, description: Total spend authorized by this consent. }
    RoamingControl:
      type: object
      additionalProperties: false
      required: [id, source, book, book_hash, plan, valid_from, valid_through, tests]
      properties:
        id: { type: string, format: uuid }
        source: { type: string, minLength: 1, maxLength: 128, pattern: '^[A-Za-z0-9_.-]+$' }
        valid_from: { type: string, format: date }
        valid_through: { type: string, format: date }
        book: { type: string, description: Loaded price book reference. }
        book_hash: { type: string, description: Price book hash used by the witnessed network controller. }
        plan: { type: string, description: Plan in the price book. }
        tests:
          type: object
          additionalProperties: false
          required: [alert, cutoff, continuation]
          properties:
            alert: { type: string, format: uuid }
            cutoff: { type: string, format: uuid }
            continuation: { type: string, format: uuid }
    RoamingAssessment:
      type: object
      additionalProperties: false
      required: [as_of]
      properties:
        as_of: { type: string, format: date }
        open_bundle:
          type: object
          additionalProperties: false
          required: [monthly_price_net_eur, roaming_bytes]
          properties:
            monthly_price_net_eur: { type: string, description: Entire domestic mobile bundle's periodic price excluding VAT. }
            domestic_limit_bytes: { type: integer, minimum: 1 }
            roaming_bytes: { type: integer, minimum: 0 }
        observation:
          type: object
          additionalProperties: false
          required: [window_end, presence_evidence, consumption_evidence, domestic_days, roaming_days, domestic_bytes, roaming_bytes]
          properties:
            window_end: { type: string, format: date, description: Last day of the four-calendar-month observation. }
            presence_evidence: { type: string, format: uuid }
            consumption_evidence: { type: string, format: uuid }
            domestic_days: { type: integer, minimum: 0, description: Distinct days with home registration including mixed days. }
            roaming_days: { type: integer, minimum: 0, description: Distinct days with only regulated visited-network registration. }
            domestic_bytes: { type: integer, minimum: 0 }
            roaming_bytes: { type: integer, minimum: 0 }
            warning:
              type: object
              additionalProperties: false
              required: [issued_on, delivery]
              properties:
                issued_on: { type: string, format: date }
                delivery: { type: string, format: uuid }
                follow_up:
                  type: object
                  additionalProperties: false
                  required: [reviewed_on, evidence, pattern_persists]
                  properties:
                    reviewed_on: { type: string, format: date }
                    evidence: { type: string, format: uuid }
                    pattern_persists: { type: boolean }
    RoamingAssessmentResult:
      type: object
      required: [as_of, data_cap_net_eur_per_gb, voice_cap_net_eur_per_minute, sms_cap_net_eur_per_message, surcharge_applied, open_bundle, permanent_roaming, rules]
      properties:
        as_of: { type: string, format: date }
        data_cap_net_eur_per_gb: { type: string }
        voice_cap_net_eur_per_minute: { type: string }
        sms_cap_net_eur_per_message: { type: string }
        surcharge_applied: { const: false }
        rules: { type: array, items: { type: string } }
        permanent_roaming: { type: [string, 'null'], enum: [null, insufficient-evidence, domestic-safe-harbour, warn-first, response-period, follow-up-required, eligible-for-review] }
        open_bundle:
          type: [object, 'null']
          required: [minimum_bytes, warning_at_bytes, status]
          properties:
            minimum_bytes: { type: string }
            warning_at_bytes: { type: string }
            status: { type: string }
    MobileUnit:
      type: string
      enum: [bytes, seconds, messages]
    MobileBatch:
      type: object
      additionalProperties: false
      required: [version, records]
      properties:
        version: { type: integer, const: 1 }
        records:
          type: array
          minItems: 1
          maxItems: 1000
          items:
            type: object
            additionalProperties: false
            required: [id, subscription, service_date, network, unit, quantity, containers]
            properties:
              id: { type: string, format: uuid }
              subscription: { type: string, format: uuid }
              service_date: { type: string, format: date }
              network: { $ref: "#/components/schemas/MobileNetwork" }
              unit: { $ref: "#/components/schemas/MobileUnit" }
              quantity: { type: integer, format: int64, minimum: 0 }
              containers:
                type: array
                minItems: 1
                maxItems: 1000
                items:
                  type: object
                  additionalProperties: false
                  required: [rating_group, quantity]
                  properties:
                    online_report: {type: string, format: uuid, description: CHF invocation report supplied by the network}
                    rating_group: { type: integer, minimum: 0, maximum: 4294967295 }
                    quantity: { type: integer, format: int64, minimum: 0 }
    MobileReceipt:
      type: object
      required: [id, rows, quantities]
      properties:
        id: { type: string, format: uuid }
        quantities: { type: object, additionalProperties: {type: object, additionalProperties: {type: integer, format: int64}} }
        rows:
          type: array
          items:
            type: object
            required: [id, record_id, rating_group, unit, quantity, status, reason]
            properties:
              id: { type: string, format: uuid }
              record_id: { type: string, format: uuid }
              rating_group: { type: integer }
              unit: { $ref: "#/components/schemas/MobileUnit" }
              quantity: { type: string }
              status: { type: string, enum: [accepted, held, duplicate, reconciliation] }
              reason: { type: string }
    MobileHoldPage:
      type: object
      required: [cohort, received_records, held_records, oldest_held_on, held_quantities, holds, next]
      properties:
        cohort: { type: [string, "null"], format: date }
        received_records: { type: integer }
        held_records: { type: integer }
        oldest_held_on: { type: [string, "null"], format: date }
        held_quantities:
          type: object
          required: [bytes, seconds, messages]
          properties:
            bytes: { type: string }
            seconds: { type: string }
            messages: { type: string }
        next: { type: [string, "null"], format: uuid }
        holds:
          type: array
          items:
            type: object
            required: [id, source, record_id, subscription_id, rating_group, unit, quantity, used_on, received_on, reason]
            properties:
              id: { type: string, format: uuid }
              record_id: { type: string, format: uuid }
              subscription_id: { type: string, format: uuid }
              rating_group: { type: integer }
              unit: { $ref: "#/components/schemas/MobileUnit" }
              quantity: { type: string }
              used_on: { type: string, format: date }
              received_on: { type: string, format: date }
              source: { type: string }
              reason: { type: string }
    UsagePage:
      type: object
      required: [period, records, next]
      properties:
        period: { type: string, example: "2026-10" }
        next: { type: [string, "null"], description: Exclusive source ID for the next page in this month. }
        records:
          type: array
          items:
            type: object
            required: [id, kind, used_on, received_on, quantity, bill_id, prepaid_revision, online_report]
            properties:
              id: { type: string }
              kind: { type: string }
              used_on: { type: string, format: date }
              received_on: { type: string, format: date }
              quantity: { type: string, pattern: "^[0-9]+$", description: Exact count in the tariff's base unit. }
              bill_id: { type: [string, "null"], format: uuid }
              online_report: {type: [string, "null"], format: uuid, description: CHF invocation supplying this measured quantity.}
              prepaid_revision: { type: [integer, "null"], format: int64, description: First cumulative wallet rating containing this record. }
    ClassifiedVoiceRow:
      type: object
      additionalProperties: false
      required: [row, subscription, id, kind, date, quantity]
      properties:
        row: { type: integer, minimum: 1, maximum: 1000 }
        subscription: { type: string, format: uuid }
        id: { type: string, pattern: "^voice:[0-9a-f]{64}$" }
        kind: { enum: [calls-landline, calls-mobile, calls-eu, calls-premium] }
        date: { type: string, format: date }
        quantity: { type: integer, minimum: 1, maximum: 4294967295, description: Measured seconds. }
    VoiceDisposition:
      type: object
      required: [row, status, reason]
      properties:
        row: { type: integer, minimum: 1 }
        status: { enum: [accepted, duplicate, held, rejected, reconciliation] }
        reason: { type: string }
    VoiceInvoiceFacts:
      type: object
      required: [id, number, account, period, prices, dispatched_on, records]
      properties:
        id: { type: string, format: uuid }
        number: { type: string }
        account: { type: string, format: uuid }
        period: { type: string, format: date }
        prices: { enum: [gross, net] }
        dispatched_on: { type: [string, "null"], format: date, description: Actual attested invoice dispatch date. }
        records:
          type: array
          items:
            type: object
            required: [id, subscription, amount, billed_units, lines, open_objection_on]
            properties:
              id: { type: string, pattern: "^voice:[0-9a-f]{64}$" }
              subscription: { type: string, format: uuid }
              amount: { type: string, description: EUR cents attributed from the sealed lines in invoice price basis. }
              billed_units: { type: integer, minimum: 0 }
              lines: { type: array, items: { type: integer, minimum: 0 } }
              open_objection_on: { type: [string, "null"], format: date, description: Date of the earliest unresolved objection against a contributing invoice line. }
    TmfMoney:
      type: object
      required: [unit, value]
      properties:
        unit: { const: EUR }
        value: { type: number }
    TmfProductUsage:
      type: object
      required: ['@type', id, href, product, status, usageType, usageCharacteristic]
      properties:
        '@type': { const: ProductUsage }
        id: { type: string, format: uuid }
        href: { type: string }
        product: { type: object, required: [id], properties: { id: { type: string, format: uuid } } }
        status: { type: string, enum: [validated, rated] }
        usageType: { type: string }
        usageCharacteristic:
          type: array
          description: Exact quantity, unit, local usageDate and customerBillId after sealing
          items: { type: object, required: [name, value], properties: { name: { type: string }, value: { type: string } } }
    TmfCustomerBill:
      type: object
      required: ["@type", id, href, billNo, category, billDate, billingAccount, taxExcludedAmount, taxIncludedAmount]
      properties:
        "@type": { const: CustomerBill }
        id: { type: string, format: uuid }
        href: { type: string, format: uri-reference }
        billNo: { type: string }
        category: { enum: [invoice, final, credit-note] }
        billDate: { type: string, format: date-time }
        billingAccount:
          type: object
          required: ["@type", id, "@referredType"]
          properties:
            "@type": { const: BillingAccountRef }
            "@referredType": { const: BillingAccount }
            id: { type: string, format: uuid }
        billingPeriod:
          type: object
          properties:
            startDateTime: { type: string, format: date-time }
            endDateTime: { type: string, format: date-time }
        taxExcludedAmount: { $ref: "#/components/schemas/TmfMoney" }
        taxIncludedAmount: { $ref: "#/components/schemas/TmfMoney" }
    Date: { type: string, format: date }
    Problem:
      type: object
      required: [type, title, status, code, detail]
      properties:
        type: { type: string }
        title: { type: string }
        status: { type: integer }
        code:
          type: string
          enum:
            - auth.missing
            - auth.forbidden
            - webhook.url-forbidden
            - webhook.exists
            - webhook.configured
            - webhook.limit
            - webhook.unconfigured
            - webhook.orphaned
            - idempotency.invalid
            - idempotency.mismatch
            - idempotency.in-progress
            - input.invalid
            - rate.unknown-plan
            - agent.already-decided
            - agent.proposal-conflict
            - agent.invalid
            - agent.stale
            - agent.unavailable
            - agent.evidence-stale
            - request.invalid
            - request.too-large
            - not-found
            - internal
            - contract.term-too-long
            - contract.notice-too-long
            - contract.invalid-terms
            - contract.awaiting-approval
            - contract.state
            - contract.not-effective
            - contract.already-terminated
            - contract.no-transparency-block
            - contract.addon-extends-term
            - subscription.transition
            - subscription.plan-overlap
            - identifier.taken
            - account.parent-mismatch
            - account.customer-mismatch
            - mobile.coverage-conflict
            - mobile.roaming-control
            - mobile.usage-held
            - mobile.warning-conflict
            - prepaid.amount
            - prepaid.conflict
            - prepaid.future
            - prepaid.ineligible
            - selfcare.invalid
            - selfcare.conflict
            - selfcare.busy
            - selfcare.replay-format
            - prepaid.pending
            - voice.batch-conflict
            - bill.replay-expired
            - dispatch.month-open
            - dispatch.scope-limit
            - bill.dispatch-conflict
            - usage.conflict
            - usage.period-closed
            - usage.unknown-subscription
            - bill.unknown-book
            - bill.mixed-prices
            - bill.already-credited
            - bill.not-creditable
            - bill.no-einvoice
            - bill.einvoice-invalid
            - account.invalid-iban
            - account.mandate-incomplete
            - account.no-creditor-id
            - letter.not-applicable
            - document.issuer-invalid
            - document.payment-invalid
            - quote.busy
            - render.busy
            - render.failed
            - ledger.unavailable
            - inbox.unauthenticated
            - outage.credit-refused
            - appointment.credit-refused
            - inbox.source-unavailable
        detail: { type: string }
        rule: { type: string, description: "Legal rule id, e.g. DE-TKG-56-1-term" }
        fix: { type: string }
        pointer: { type: string, description: "The part of the request the problem is about, as a JSON pointer (/account/iban)" }
    CloudEvent:
      type: object
      description: A CloudEvents 1.0 envelope; the same on the feed and on a webhook.
      required: [specversion, id, source, type, subject, time, datacontenttype, sequence, businessdate, data]
      properties:
        specversion: { type: string, const: "1.0" }
        id: { type: string, format: uuid, description: De-duplicate on this }
        source: { type: string, const: "urn:telco:billd" }
        type: { type: string, pattern: "^de\\.telco\\.bill\\.[a-z-]+$" }
        subject: { type: string, description: "The aggregate: bill/{id}, contract/{id}, billing-account/{id}, subscription/{id}, customer/{id}" }
        time: { type: string, format: date-time, description: When telco recorded the fact (UTC) }
        datacontenttype: { type: string, const: application/json }
        sequence: { type: string, description: The position in the feed (CloudEvents sequence extension) }
        businessdate: { $ref: "#/components/schemas/Date" }
        orderref: { type: string, description: "The seller's order reference, on every event of a contract that came through POST /signups" }
        data: { type: object, description: "Ids, states, dates and rule ids — never a name, an address or an amount" }
    NewCustomer:
      type: object
      additionalProperties: false
      required: [name, street, postcode, city, consumer, salutation]
      properties:
        name: { type: string }
        street: { type: string }
        postcode: { type: string }
        city: { type: string }
        country: { type: string, pattern: "^[A-Z]{2}$" }
        consumer: { type: boolean }
        salutation: { type: string, enum: [sie, du] }
    NewAccount:
      type: object
      additionalProperties: false
      required: [customer]
      properties:
        customer: { type: string, format: uuid }
        payment_terms_days: { type: integer, minimum: 0, maximum: 90 }
        vat_id: { type: string }
        buyer_reference: { type: string }
        peppol_id: { type: string }
        parent: { type: string, format: uuid }
        invoice_email: { type: string, format: email, description: Where e-invoices go; XRechnung needs it }
        payment_method: { type: string, enum: [transfer, direct-debit], default: transfer }
        mandate_reference: { type: string, maxLength: 35, description: Required for direct-debit }
        mandate_signed_on: { $ref: "#/components/schemas/Date" }
        iban: { type: string, description: The debtor IBAN; required for direct-debit; answers show it masked }
    NewContract:
      type: object
      additionalProperties: false
      required: [customer, billing_account, start, initial_months, notice_months, renews, summary_before_conclusion]
      properties:
        customer: { type: string, format: uuid }
        billing_account: { type: string, format: uuid }
        start: { $ref: "#/components/schemas/Date" }
        initial_months: { type: integer, minimum: 0, maximum: 120 }
        notice_months: { type: integer, minimum: 0, maximum: 24 }
        renews: { type: boolean }
        summary_before_conclusion: { type: boolean }
        bundle_code: { type: string }
    Approval:
      type: object
      additionalProperties: false
      required: [approved_on]
      properties: { approved_on: { $ref: "#/components/schemas/Date" } }
    NewTermination:
      type: object
      additionalProperties: false
      required: [received_on]
      properties:
        received_on: { $ref: "#/components/schemas/Date" }
        requested_on: { $ref: "#/components/schemas/Date" }
    Termination:
      type: object
      properties:
        effective: { $ref: "#/components/schemas/Date" }
        basis: { type: string, enum: [initial-term-end, ends-without-renewal, renewed-one-month, indefinite-notice] }
        rule: { type: [string, "null"] }
        requested_later: { type: boolean }
    NewSubscription:
      type: object
      additionalProperties: false
      required: [product, plan, book_version]
      properties:
        product: { type: string }
        plan: { type: string }
        book_version: { type: string }
        term_months: { type: integer, minimum: 1, maximum: 120 }
        term_extension_consent: { type: boolean }
    OnDate:
      type: object
      additionalProperties: false
      required: ["on"]
      properties: { "on": { $ref: "#/components/schemas/Date" } }
    PlanChange:
      type: object
      additionalProperties: false
      required: [plan, book_version, from]
      properties:
        plan: { type: string }
        book_version: { type: string }
        from: { $ref: "#/components/schemas/Date" }
    NewIdentifier:
      type: object
      additionalProperties: false
      required: [kind, value, from]
      properties:
        kind: { type: string, enum: [line, msisdn, imsi, api-key] }
        value: { type: string, minLength: 1, maxLength: 128 }
        from: { $ref: "#/components/schemas/Date" }
    OnlineReconciliationCounts:
      type: object
      required: [matched, unmatched, conflicting, pending_reports, missing_copies]
      properties:
        matched: {type: integer, minimum: 0}
        unmatched: {type: integer, minimum: 0}
        conflicting: {type: integer, minimum: 0}
        pending_reports: {type: integer, minimum: 0}
        missing_copies: {type: integer, minimum: 0}
    OnlineReconciliation:
      allOf:
        - {$ref: '#/components/schemas/OnlineReconciliationCounts'}
        - type: object
          required: [month, channels, entries, next]
          properties:
            month: {type: string}
            channels: {type: object, additionalProperties: {$ref: '#/components/schemas/OnlineReconciliationCounts'}}
            next: {type: [integer, 'null'], format: int64}
            entries:
              type: array
              items:
                type: object
                required: [id, subscription, used_on, source, record_key, report, kind, quantity, channel, status]
                properties:
                  id: {type: integer, format: int64}
                  subscription: {type: string, format: uuid}
                  used_on: {type: string, format: date}
                  source: {type: string}
                  record_key: {type: string}
                  report: {type: [string, 'null'], format: uuid}
                  kind: {type: string}
                  quantity: {type: string}
                  channel: {type: string, enum: [data, api, other]}
                  status: {type: string, enum: [matched, unmatched, conflicting, pending_reports]}
    UsageBatch:
      type: object
      additionalProperties: false
      required: [records]
      properties:
        records:
          type: array
          maxItems: 1000
          items:
            type: object
            additionalProperties: false
            required: [subscription, id, kind, date, quantity]
            properties:
              subscription: { type: string, format: uuid }
              id: { type: string, minLength: 1, maxLength: 128 }
              online_report: {type: string, format: uuid, description: Secondary observation of an online charging report}
              kind: { type: string }
              date: { $ref: "#/components/schemas/Date" }
              quantity: { type: integer, minimum: 0 }
    CreditNoteRequest:
      type: object
      additionalProperties: false
      required: [reason]
      properties: { reason: { type: string, minLength: 1 } }
    Object: { type: object }
  responses:
    TmfUsagePage:
      description: Accepted mobile measurements in public UUID order.
      headers:
        X-Result-Count: { schema: { type: integer } }
      content:
        application/json:
          schema: { type: array, items: { $ref: "#/components/schemas/TmfProductUsage" } }
    TmfBillPage:
      description: Authorized sealed bills in invoice number order.
      headers:
        X-Result-Count: { schema: { type: integer } }
      content:
        application/json:
          schema: { type: array, items: { $ref: "#/components/schemas/TmfCustomerBill" } }
    Problem:
      description: An RFC 9457 problem
      content:
        application/problem+json:
          schema: { $ref: "#/components/schemas/Problem" }
    Ok:
      description: The resource
      content:
        application/json:
          schema: { $ref: "#/components/schemas/Object" }
    Html:
      description: A self-contained, accessible HTML page
      content:
        text/html:
          schema: { type: string }
    Pdf:
      description: One PDF that conforms to PDF/UA-1 and PDF/A-3b; a business bill embeds its e-invoice (ZUGFeRD). Stored at the first request; the ETag is its SHA-256.
      content:
        application/pdf:
          schema: { type: string, format: binary }
paths:
  /finance-close/{period}:
    get:
      operationId: checkFinanceClose
      summary: Count billing commands awaiting accounting acknowledgement for a booking month
      description: >-
        Requires the finance role. Counts committed open or parked billing drafts,
        unacknowledged prepaid charges and approved credit commands at the time of the read.
        Commands arriving later can produce supplemental postings.
      parameters:
        - name: period
          in: path
          required: true
          schema: { type: string, pattern: '^[0-9]{4}-(0[1-9]|1[0-2])$' }
      responses:
        "200":
          description: Aggregate count by intended journal date
          content:
            application/json:
              schema:
                type: object
                required: [period, pending]
                properties:
                  period: { type: string }
                  pending: { type: integer, minimum: 0 }
        default: { $ref: "#/components/responses/Problem" }
  /selfcare/billing:
    get:
      operationId: selfcareBilling
      summary: Bills, next estimate, objections and selectable plans for the authenticated customer.
      parameters:
      - name: lang
        in: query
        required: false
        schema:
          type: string
          enum:
          - de
          - de-easy
          - en
          default: de
      responses:
        '200':
          description: Bills, next estimate, objections and selectable plans for the authenticated customer.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SelfcareBilling'
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /selfcare/bills/{id}:
    get:
      operationId: selfcareBill
      summary: Read the sealed figures in a chosen language.
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      - name: lang
        in: query
        required: false
        schema:
          type: string
          enum:
          - de
          - de-easy
          - en
          default: de
      responses:
        '200':
          description: Read the sealed figures in a chosen language.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SelfcareBill'
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /selfcare/bills/{id}/original:
    get:
      operationId: selfcareOriginal
      summary: Accessible original invoice. The private verification QR opens the account when an origin is configured.
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      - name: format
        in: query
        schema: { type: string, enum: [html, pdf], default: html }
        description: Accessible HTML reading or the exact first-rendered PDF from the document archive.
      responses:
        '200':
          description: Accessible original invoice. The private verification QR opens the account when an origin is configured.
          content:
            application/pdf:
              schema: { type: string, format: binary }
            text/html:
              schema:
                type: string
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /selfcare/bills/{id}/objections/{case_id}:
    put:
      operationId: selfcareObject
      summary: Record or replay a line objection and return its durable receipt.
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      - name: case_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - line
              - reason
              properties:
                line:
                  type: integer
                  minimum: 0
                reason:
                  type: string
                  minLength: 1
                  maxLength: 2000
      responses:
        '200':
          description: Record or replay a line objection and return its durable receipt.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SelfcareObjection'
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /selfcare/mailbox/{id}/read:
    put:
      operationId: selfcareRead
      summary: Mark an owned document read after opening it.
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      - name: version
        in: query
        schema: {type: string, enum: [issued, received, answered], default: issued}
      responses:
        '204':
          description: Mark an owned document read after opening it.
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /selfcare/preview:
    get:
      operationId: selfcarePreview
      summary: Compare a dated switch with the existing subscription, including its activation date and scheduled tariff slices.
      parameters:
      - name: subscription
        in: query
        required: true
        schema:
          type: string
          format: uuid
      - name: plan
        in: query
        required: true
        schema:
          type: string
      - name: from
        in: query
        required: true
        schema:
          type: string
          format: date
      responses:
        '200':
          description: Compare a dated switch with the existing subscription, including its activation date and scheduled tariff
            slices.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SelfcarePreview'
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /selfcare/bills/{id}/verification:
    post:
      operationId: selfcareVerifyShare
      summary: Issue a seven-day masked verification link. Replaces any previous link for this invoice.
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Issue a seven-day masked verification link. Replaces any previous link for this invoice.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SelfcareVerification'
        "410": { $ref: "#/components/responses/Problem" }
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
    delete:
      operationId: selfcareVerifyRevoke
      summary: Revoke the shared verification link.
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '204':
          description: Revoke the shared verification link.
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /billing-objections:
    get:
      operationId: billingObjections
      summary: Operator queue of sealed-line objections and answers.
      responses:
        '200':
          description: Operator queue of sealed-line objections and answers.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/SelfcareObjection'
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /billing-objections/{id}/decision:
    put:
      operationId: answerBillingObjection
      summary: Record an immutable answer to an objection. Any financial remedy is a separate authorized posting.
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - answer
              properties:
                answer:
                  type: string
                  minLength: 1
                  maxLength: 2000
                remedy_bill:
                  type: string
                  format: uuid
                  description: An issued credit note citing this invoice.
      responses:
        '204':
          description: Record an immutable answer to an objection. Any financial remedy is a separate authorized posting.
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /nachrechnen/{token}:
    get:
      operationId: verifyMaskedBill
      summary: Check each masked line against the original pinned books. HTML works without JavaScript.
      security: []
      parameters:
      - name: token
        in: path
        required: true
        schema:
          type: string
          pattern: ^[0-9a-f]{32}$
      responses:
        '200':
          description: Check each masked line against the original pinned books. HTML works without JavaScript.
          content:
            text/html:
              schema:
                type: string
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /nachrechnen/{token}/bundle:
    get:
      operationId: maskedReplayBundle
      summary: Portable anonymized rating inputs and operator-published tariff sources.
      security: []
      parameters:
      - name: token
        in: path
        required: true
        schema:
          type: string
          pattern: ^[0-9a-f]{32}$
      responses:
        '200':
          description: Portable anonymized rating inputs and operator-published tariff sources.
          content:
            application/json:
              schema:
                type: object
                required:
                - op
                - books
                - replay
                properties:
                  op:
                    const: verify
                  books:
                    type: object
                  replay:
                    type: object
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /nachrechnen/{token}/qr.svg:
    get:
      operationId: maskedReplayQr
      summary: Scannable verification link using the configured canonical portal origin.
      security: []
      parameters:
      - name: token
        in: path
        required: true
        schema:
          type: string
          pattern: ^[0-9a-f]{32}$
      responses:
        '200':
          description: Scannable verification link using the configured canonical portal origin.
          content:
            image/svg+xml:
              schema:
                type: string
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /nachrechnen/verify.js:
    get:
      operationId: maskedReplayClient
      summary: Browser-local replay of the same core rater.
      security: []
      responses:
        '200':
          description: Browser-local replay of the same core rater.
          content:
            text/javascript:
              schema:
                type: string
        default:
          description: RFC 9457 problem
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /agent/proposals:
    post:
      description: "Create or replay a proposal with immutable account-bound evidence. Credit lines use zero-based sealed totals indices. No business effect until review."
      requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/AgentProposal'}}}}
      responses: {'200': {description: Reviewed proposal, content: {application/json: {schema: {$ref: '#/components/schemas/AgentReview'}}}}, '403': {description: Credential outside scope}, '409': {description: Conflicting command or changed evidence}}
    get:
      description: "Review up to 100 proposals in descending business date and ID order."
      parameters:
        - {in: query, name: before, schema: {type: string, format: uuid}, description: Last proposal UUID on the preceding page}
        - {in: query, name: pending_only, schema: {type: boolean, default: false}, description: Only undecided proposals valid on the current business date}
      responses: {'200': {description: Review queue, content: {application/json: {schema: {type: array, items: {$ref: '#/components/schemas/AgentReview'}}}}}, '403': {description: Credential outside scope}, '409': {description: Conflicting command or changed evidence}}
  /agent/proposals/{id}:
    parameters: [{in: path, name: id, required: true, schema: {type: string, format: uuid}}]
    get:
      description: "Inspect the recorded evidence, decision and execution receipt."
      responses: {'200': {description: Reviewed proposal, content: {application/json: {schema: {$ref: '#/components/schemas/AgentReview'}}}}, '403': {description: Credential outside scope}, '409': {description: Conflicting command or changed evidence}}
  /agent/proposals/{id}/decision:
    parameters: [{in: path, name: id, required: true, schema: {type: string, format: uuid}}]
    put:
      description: "Named reviewer decision. Approval of a plan switch also requires a customer consent reference. The proposal is valid through the recorded expiry date (seven calendar days after creation)."
      requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/AgentDecision'}}}}
      responses: {'200': {description: Reviewed proposal, content: {application/json: {schema: {$ref: '#/components/schemas/AgentReview'}}}}, '403': {description: Credential outside scope}, '409': {description: Conflicting command or changed evidence}}
  /agent/dispatches:
    get:
      description: "Delivery credential only. Poll up to 100 reviewed replies; use each proposal ID as the transport idempotency key and deliver the retained text and marking verbatim."
      parameters:
        - {in: query, name: before, schema: {type: string, format: uuid}, description: Last proposal UUID on the preceding page}
        - {in: query, name: pending_only, schema: {type: boolean, default: false}, description: Only undecided proposals valid on the current business date}
      responses: {'200': {description: Success}, '403': {description: Credential outside scope}, '409': {description: Conflicting command or changed evidence}}
  /agent/dispatches/{id}/ack:
    parameters: [{in: path, name: id, required: true, schema: {type: string, format: uuid}}]
    put:
      description: "Record a delivery failure or a confirmed transport receipt for the exact recipient. Replaying the same receipt is safe."
      requestBody: {required: true, content: {application/json: {schema: {$ref: '#/components/schemas/DispatchAck'}}}}
      responses: {'200': {description: Success}, '403': {description: Credential outside scope}, '409': {description: Conflicting command or changed evidence}}
  /agent/mcp:
    post:
      description: "Authenticated stateless MCP for proposing a credit, plan switch or dispute answer. Available when TELCO_MCP is on."
      responses: {'200': {description: Success}, '403': {description: Credential outside scope}, '409': {description: Conflicting command or changed evidence}}
  /billing-accounts/{id}/agent-evidence:
    parameters: [{$ref: '#/components/parameters/id'}]
    post:
      summary: Capture the authenticated account's immutable bill or wallet evidence
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - {type: object, additionalProperties: false, required: [kind, bill], properties: {kind: {const: bill}, bill: {type: string, format: uuid}}}
                - {type: object, additionalProperties: false, required: [kind], properties: {kind: {const: wallet}}}
      responses:
        '201': {description: Source and available fields, content: {application/json: {schema: {$ref: '#/components/schemas/AgentEvidence'}}}}
        '404': {description: Evidence unavailable in this account}
        '503': {description: Accounting service unavailable}
  /billing-accounts/{id}/agent-answers:
    parameters: [{$ref: '#/components/parameters/id'}]
    post:
      summary: Check and retain a disclosed answer for an existing contact
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [contact_id, evidence, claims]
              properties:
                contact_id: {type: string, format: uuid}
                evidence: {type: string, format: uuid}
                claims: {type: array, minItems: 1, maxItems: 6, uniqueItems: true, items: {$ref: '#/components/schemas/AgentClaim'}}
      responses:
        '201': {description: Verified answer, content: {application/json: {schema: {$ref: '#/components/schemas/CheckedAnswer'}}}}
        '404': {description: Contact or evidence unavailable in this account}
        '422': {description: At least one claim could not be verified}
  /billing-accounts/{id}/agent-answers/{answer}:
    parameters:
      - {$ref: '#/components/parameters/id'}
      - {name: answer, required: true, in: path, schema: {type: string, format: uuid}}
    get:
      summary: Read the retained answer and its checked citations
      responses:
        '200': {description: Verified answer, content: {application/json: {schema: {$ref: '#/components/schemas/CheckedAnswer'}}}}
        '404': {description: Answer unavailable in this account}
  /agent/contacts/{id}:
    parameters: [{$ref: '#/components/parameters/id'}]
    put:
      operationId: openAgentContact
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [account]
              properties: {account: {type: string, format: uuid}}
      responses:
        '204': {description: Contact opened or already recorded for this account}
  /agent/contacts/{id}/outcome:
    parameters: [{$ref: '#/components/parameters/id'}]
    put:
      operationId: recordAgentContactOutcome
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - type: object
                  additionalProperties: false
                  required: [account, outcome, answer]
                  properties: {account: {type: string, format: uuid}, outcome: {const: confirmed}, answer: {type: string, format: uuid}}
                - type: object
                  additionalProperties: false
                  required: [account, outcome]
                  properties: {account: {type: string, format: uuid}, outcome: {type: string, enum: [handoff, reopened]}}
      responses:
        '204': {description: Outcome recorded}
  /agent/contact-metrics:
    get:
      operationId: agentContactMetrics
      parameters:
        - {in: query, name: month, schema: {type: string}, description: Calendar month in YYYY-MM format}
      responses:
        '200':
          description: Customer-confirmed outcomes by month of first contact
          content:
            application/json:
              schema: {$ref: '#/components/schemas/AgentContactMetrics'}
  /mcp/public:
    post:
      operationId: publicMcp
      summary: Check a published tariff or replay a redacted tariff receipt
      security: []
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, description: MCP JSON-RPC request, additionalProperties: true }
      responses:
        '200':
          description: Stateless MCP JSON-RPC response
        '202':
          description: Notification accepted
        '403':
          description: Host or Origin refused
        '413':
          description: Request exceeds 16 KiB
  /mobile/roaming-controls:
    post:
      summary: Commission a serving network's tested default data roaming spend control
      description: Operator only. The interval is inclusive and starts no earlier than the business date. Store references to three distinct witnessed tests. Reuse the same request to confirm the receipt.
      requestBody:
        required: true
        content:
          application/json: { schema: { $ref: "#/components/schemas/RoamingControl" } }
      responses:
        "200":
          description: Network control registered.
          content:
            application/json:
              schema:
                type: object
                required: [id, source, rule]
                properties: { id: { type: string, format: uuid }, source: { type: string }, rule: { type: string } }
        "409": { description: Changed or backdated commission. }
  /mobile/roaming-assessments:
    post:
      summary: Assess roaming evidence and calculate the minimum open-bundle volume
      description: Operator only. All monetary values exclude VAT. The assessment returns an advisory result and never adds a surcharge to an invoice.
      requestBody:
        required: true
        content:
          application/json: { schema: { $ref: "#/components/schemas/RoamingAssessment" } }
      responses:
        "200":
          description: Dated allowance and fair-use assessment.
          content:
            application/json: { schema: { $ref: "#/components/schemas/RoamingAssessmentResult" } }
  /mobile-measurements/{id}:
    get:
      operationId: mobileMeasurementEvidence
      summary: Read the retained pricing decision and disposition for one mobile container
      parameters: [{ $ref: "#/components/parameters/id" }]
      responses:
        "200":
          description: Operator evidence recorded on the measurement
          content:
            application/json:
              schema:
                type: object
                required: [id, source, record_id, subscription_id, used_on, rating_group, unit, quantity, status, reason]
                properties:
                  id: { type: string, format: uuid }
                  source: { type: string }
                  record_id: { type: string, format: uuid }
                  subscription_id: { type: string, format: uuid }
                  used_on: { type: string, format: date }
                  rating_group: { type: integer }
                  unit: { $ref: "#/components/schemas/MobileUnit" }
                  quantity: { type: string }
                  status: { type: string, enum: [accepted, held, excluded, reconciliation] }
                  reason: { type: string }
                  kind: { type: [string, "null"] }
                  zone: { type: [string, "null"] }
                  disposition:
                    type: [object, "null"]
                    required: [evidence, outcome, actor, decided_on]
                    properties:
                      evidence: { type: string, format: uuid }
                      outcome: { type: string, enum: [invalid-source, confirmed-duplicate, externally-settled] }
                      actor: { type: string }
                      decided_on: { type: string, format: date }
                  policy_revision: { type: [string, "null"] }
                  mapping_id: { type: [string, "null"], format: uuid }
                  book_version: { type: [string, "null"] }
                  book_hash: { type: [string, "null"] }
                  plan: { type: [string, "null"] }
                  bill_id: { type: [string, "null"], format: uuid }
        default: { $ref: "#/components/responses/Problem" }
  /tmf-api/productUsageManagement/v5/productUsage:
    get:
      operationId: listProductUsages
      summary: List accepted mobile measurements visible to this credential
      parameters:
        - { in: query, name: limit, schema: { type: integer, minimum: 1, maximum: 100, default: 50 } }
        - { in: query, name: offset, schema: { type: integer, minimum: 0, maximum: 4294967295, default: 0 } }
        - { in: query, name: product.id, schema: { type: string, format: uuid } }
      responses:
        "200": { $ref: "#/components/responses/TmfUsagePage" }
        "206": { $ref: "#/components/responses/TmfUsagePage" }
        default: { $ref: "#/components/responses/Problem" }
  /tmf-api/productUsageManagement/v5/productUsage/{id}:
    get:
      operationId: retrieveProductUsage
      summary: Retrieve an accepted mobile measurement within the caller's account scope
      parameters: [{ $ref: "#/components/parameters/id" }]
      responses:
        "200":
          description: TMF635 ProductUsage with its assigned bill after sealing
          content: { application/json: { schema: { $ref: "#/components/schemas/TmfProductUsage" } } }
        default: { $ref: "#/components/responses/Problem" }
  /tmf-api/customerBillManagement/v5/customerBill:
    get:
      operationId: listCustomerBills
      summary: List sealed invoices and credit notes visible to this credential
      parameters:
        - { in: query, name: limit, schema: { type: integer, minimum: 1, maximum: 100, default: 50 } }
        - { in: query, name: offset, schema: { type: integer, minimum: 0, maximum: 4294967295, default: 0 } }
        - { in: query, name: billingAccount.id, schema: { type: string, format: uuid } }
      responses:
        "200": { $ref: "#/components/responses/TmfBillPage" }
        "206": { $ref: "#/components/responses/TmfBillPage" }
        default: { $ref: "#/components/responses/Problem" }
  /tmf-api/customerBillManagement/v5/customerBill/{id}:
    get:
      operationId: retrieveCustomerBill
      summary: Retrieve a sealed bill by its UUID within the caller's scope
      parameters: [{ $ref: "#/components/parameters/id" }]
      responses:
        "200":
          description: Sealed TMF678 CustomerBill
          content: { application/json: { schema: { $ref: "#/components/schemas/TmfCustomerBill" } } }
        default: { $ref: "#/components/responses/Problem" }
  /health:
    get:
      operationId: health
      security: []
      description: "The detail for people and the Desk: clock, database, subscribers."
      responses: { "200": { $ref: "#/components/responses/Ok" } }
  /health/live:
    get:
      operationId: healthLive
      security: []
      description: "200 while the process serves. A platform restarts on this one only."
      responses: { "200": { $ref: "#/components/responses/Ok" } }
  /health/ready:
    get:
      operationId: healthReady
      security: []
      description: "200 when the database answers; 503 with fixed reason words (`database: unavailable`) otherwise. A platform routes on this one."
      responses:
        "200": { $ref: "#/components/responses/Ok" }
        "503": { description: "Not ready, with reasons", content: { application/json: { schema: { type: object } } } }
  /openapi.yaml:
    get:
      operationId: getOpenApi
      security: []
      description: This document.
      responses: { "200": { description: The OpenAPI 3.1 document, content: { application/yaml: { schema: { type: string } } } } }
  /event-types:
    get:
      operationId: listEventTypes
      security: []
      description: The CloudEvents types this service emits and consumes, each with its meaning, source and the JSON Schema of its data (also at `dataschema`). The types are a public contract — never renamed; `data` only gains optional fields.
      responses: { "200": { $ref: "#/components/responses/Ok" } }
  /inbox:
    post:
      operationId: receiveEvent
      security: []
      description: >-
        Contract facts arrive here as one CloudEvents 1.0 envelope (structured mode,
        application/cloudevents+json), signed per Standard Webhooks (webhook-id = the
        event id, webhook-timestamp, webhook-signature v1). billd reads the subject's
        current state from its source and replaces its projection. A redelivery answers
        `duplicate`; 401 for a bad signature, 503 when the source cannot be read (deliver
        again later).
      parameters:
        - { name: webhook-id, in: header, required: true, schema: { type: string } }
        - { name: webhook-timestamp, in: header, required: true, schema: { type: integer } }
        - { name: webhook-signature, in: header, required: true, schema: { type: string } }
      requestBody: { required: true, content: { application/cloudevents+json: { schema: { type: object, required: [specversion, id, source, type, subject], description: "A CloudEvents 1.0 envelope from the source (urn:telco:contractd or a replacement): de.telco.customer.*, billing-account.*, contract.*, subscription.*" } } } }
      responses:
        "200":
          description: Taken
          content:
            application/json:
              schema: { type: object, required: [outcome], properties: { outcome: { type: string, enum: [applied, ignored, gone, duplicate] } } }
        default: { $ref: "#/components/responses/Problem" }
  /mobile-batches/{id}:
    parameters: [{ $ref: "#/components/parameters/id" }]
    put:
      operationId: importMobileBatch
      description: Submit final usage as its named network source. Duplicate batch IDs replay the original receipt. Up to 1000 containers and 64 KiB.
      requestBody:
        required: true
        content: { application/json: { schema: { $ref: "#/components/schemas/MobileBatch" } } }
      responses:
        "200": { description: Immutable dispositions and quantities by unit, content: { application/json: { schema: { $ref: "#/components/schemas/MobileReceipt" } } } }
        default: { $ref: "#/components/responses/Problem" }
  /mobile-mappings/{id}:
    parameters: [{ $ref: "#/components/parameters/id" }]
    put:
      operationId: installMobileMapping
      description: An immutable operator mapping. The most recent start on or before the usage date applies.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [source, rating_group, unit, kind, from]
              properties:
                source: { type: string, maxLength: 32 }
                rating_group: { type: integer, minimum: 0, maximum: 4294967295 }
                unit: { $ref: "#/components/schemas/MobileUnit" }
                kind: { type: string, maxLength: 64 }
                from: { type: string, format: date }
      responses:
        "200": { description: Mapping installed or replayed }
        default: { $ref: "#/components/responses/Problem" }
  /mobile-holds:
    get:
      operationId: mobileHolds
      description: Receipt cohort metrics and held containers. Open scope spans all cohorts. Quantities in the queue are exact integer strings.
      parameters:
        - { name: cohort, in: query, schema: { type: string, format: date } }
        - { name: scope, in: query, schema: { type: string, enum: [cohort, open] } }
        - { name: after, in: query, schema: { type: string, format: uuid } }
        - { name: source, in: query, schema: { type: string } }
      responses:
        "200": { description: Current reconciled cohort and holds, content: { application/json: { schema: { $ref: "#/components/schemas/MobileHoldPage" } } } }
        default: { $ref: "#/components/responses/Problem" }
  /mobile-holds/{id}/disposition:
    parameters: [{ $ref: "#/components/parameters/id" }]
    put:
      operationId: excludeMobileHold
      description: Operator confirms source invalidation, independently evidenced duplication or external settlement for a closed period or known destination outside the tariff profile. Retains the external evidence reference and authenticated actor.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [outcome, evidence]
              properties:
                outcome: {type: string, enum: [invalid-source, confirmed-duplicate, externally-settled]}
                evidence: {type: string, format: uuid}
      responses:
        "200": {description: Excluded with evidence or identical decision replayed}
        default: { $ref: "#/components/responses/Problem" }
  /mobile-holds/{id}/retry:
    parameters: [{ $ref: "#/components/parameters/id" }]
    post:
      operationId: retryMobileHold
      description: Operator rechecks one held container against its event-date tariff and network evidence.
      responses:
        "200": { description: Current outcome, content: { application/json: { schema: { type: object, required: [id,status,reason], properties: { id: {type: string, format: uuid}, status: {type: string, enum: [held, accepted]}, reason: {type: string} } } } } }
        default: { $ref: "#/components/responses/Problem" }
  /classified-voice-batches/{id}:
    parameters: [{ $ref: "#/components/parameters/id" }]
    put:
      operationId: deliverClassifiedVoice
      summary: Commit redacted classified rows and their immutable outcomes
      description: Mediation only. Supply ascending switch row numbers. A retry with the same UUID and content returns the original results.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [source, rows]
              properties:
                source: { type: string, minLength: 1, maxLength: 128 }
                rows: { type: array, maxItems: 1000, items: { $ref: "#/components/schemas/ClassifiedVoiceRow" } }
      responses:
        "200":
          description: Per-row outcome in input order
          content: { application/json: { schema: { type: object, required: [rows], properties: { rows: { type: array, items: { $ref: "#/components/schemas/VoiceDisposition" } } } } } }
        default: { $ref: "#/components/responses/Problem" }
  /billing-objections/{id}/resolution:
    parameters: [{ $ref: "#/components/parameters/id" }]
    put:
      operationId: recordObjectionResolution
      summary: Attest final resolution or withdrawal of an objection
      description: Operator only. A reply alone leaves the evidence hold intact. Record the opaque reference of the final decision or withdrawal.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [reference]
              properties:
                reference: { type: string, minLength: 1, maxLength: 256 }
      responses:
        "204": { description: Final resolution is recorded. }
        default: { $ref: "#/components/responses/Problem" }
  /invoice-dispatches:
    get:
      operationId: reviewInvoiceDispatches
      summary: Export a closed seal month for dispatch reconciliation
      description: Operator only. One installation and one database snapshot. Includes zero invoices, final invoices and subsequently credited originals. Counts credit notes separately. The limit is 10000 eligible documents.
      parameters:
        - in: query
          name: seal_month
          required: true
          schema: { type: string, pattern: '^[0-9]{4}-[0-9]{2}$' }
      responses:
        "200":
          description: Private billing inventory. The quoted ETag is the lowercase SHA-256 of the exact body bytes.
          headers:
            ETag: { schema: { type: string } }
            Cache-Control: { schema: { const: "private, no-store" } }
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required: [format, estate, seal_month, from, until, captured_on, eligible_count, excluded_credit_count, invoices]
                properties:
                  format: { const: telco.dispatch-snapshot.v1 }
                  estate: { type: string, format: uuid }
                  seal_month: { type: string }
                  from: { type: string, format: date }
                  until: { type: string, format: date, description: Exclusive end of the seal month. }
                  captured_on: { type: string, format: date }
                  eligible_count: { type: integer, minimum: 0, maximum: 10000 }
                  excluded_credit_count: { type: integer, minimum: 0 }
                  invoices:
                    type: array
                    maxItems: 10000
                    items:
                      type: object
                      additionalProperties: false
                      required: [bill, kind, sealed_on, proof]
                      properties:
                        bill: { type: string, format: uuid }
                        kind: { type: string, enum: [invoice, final] }
                        sealed_on: { type: string, format: date }
                        proof:
                          type: [object, "null"]
                          additionalProperties: false
                          required: [reference, dispatched_on]
                          properties:
                            reference: { type: string, minLength: 1, maxLength: 256 }
                            dispatched_on: { type: string, format: date }
        default: { $ref: "#/components/responses/Problem" }
  /invoice-dispatches/{id}:
    parameters: [{ $ref: "#/components/parameters/id" }]
    put:
      operationId: recordInvoiceDispatch
      summary: Record proof of actual dispatch for a sealed invoice
      description: Operator only. Record the delivery system's opaque handoff reference. An identical command is replay-safe.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [reference, dispatched_on]
              properties:
                reference: { type: string, minLength: 1, maxLength: 256 }
                dispatched_on: { type: string, format: date }
      responses:
        "204": { description: Dispatch is recorded. }
        default: { $ref: "#/components/responses/Problem" }
  /voice-invoice-facts/{id}:
    parameters: [{ $ref: "#/components/parameters/id" }]
    get:
      operationId: getVoiceInvoiceFacts
      summary: Read sealed voice line contributions, dispatch and unresolved objection dates
      description: Mediation only. Includes zero-priced records and the opaque usage key for joining evidence.
      responses:
        "200": { description: Authoritative billing facts, content: { application/json: { schema: { $ref: "#/components/schemas/VoiceInvoiceFacts" } } } }
        default: { $ref: "#/components/responses/Problem" }
  /voice-invoice-facts/purge:
    post:
      operationId: purgeExpiredVoiceEvidence
      summary: Erase expired classified traffic and retire the affected invoice replays
      description: Mediation only. This operation also runs in billd at startup and hourly. The response counts deleted usage records.
      responses:
        "200": { description: Retention sweep result, content: { application/json: { schema: { type: object, required: [deleted], properties: { deleted: { type: integer, minimum: 0 } } } } } }
        default: { $ref: "#/components/responses/Problem" }
  /voice-invoice-facts/lookup:
    post:
      operationId: lookupVoiceInvoiceFacts
      summary: Resolve opaque call keys to their sealed invoice facts
      description: Mediation only. Returns only matching invoices and records.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [ids]
              properties:
                ids: { type: array, maxItems: 1000, items: { type: string, pattern: "^voice:[0-9a-f]{64}$" } }
      responses:
        "200": { description: Matching invoices, content: { application/json: { schema: { type: object, required: [invoices, expired], properties: { expired: { type: array, items: { type: string } }, invoices: { type: array, items: { $ref: "#/components/schemas/VoiceInvoiceFacts" } } } } } } }
        default: { $ref: "#/components/responses/Problem" }
  /subscriptions/{id}/usage:
    get:
      summary: List measured usage by month of use in ascending source ID order
      operationId: subscriptionUsage
      parameters:
        - { $ref: "#/components/parameters/id" }
        - { name: period, in: query, description: Defaults to the service clock month., schema: { type: string, pattern: "^[0-9]{4}-(0[1-9]|1[0-2])$" } }
        - { name: after, in: query, schema: { type: string, minLength: 1, maxLength: 128 } }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 50 } }
      responses:
        "200": { description: A month of subscription usage, content: { application/json: { schema: { $ref: "#/components/schemas/UsagePage" } } } }
        default: { $ref: "#/components/responses/Problem" }
  /bill-replays/{reference}:
    get:
      operationId: getBillReplay
      summary: Download the frozen rating case for an invoice or final bill (operator only)
      parameters:
        - { name: reference, in: path, required: true, schema: { type: string }, description: Invoice number or UUID. }
      responses:
        "200":
          description: Offline regression fixture. Preserve original JSON integer precision.
          content:
            application/json:
              schema:
                type: object
                required: [format, number, sealed_on, facts, expected]
                properties:
                  format: { const: telco.bill-replay.v1 }
                  number: { type: string }
                  sealed_on: { type: string, format: date }
                  facts:
                    type: object
                    required: [period, subscriptions, usage, billed_previous, books]
                    properties:
                      period: { type: string }
                      subscriptions: { type: array, items: { type: object } }
                      usage: { type: array, items: { type: object } }
                      billed_previous: { type: array, items: { type: object } }
                      books: { type: object, additionalProperties: { type: string } }
                  expected:
                    type: object
                    required: [period, prices, charges, totals]
                    properties:
                      period: { type: string }
                      prices: { enum: [net, gross] }
                      charges: { type: array, items: { type: object } }
                      totals: { type: object }
        "410": { $ref: "#/components/responses/Problem" }
        default: { $ref: "#/components/responses/Problem" }
  /prepaid/enrollments:
    post:
      summary: Start prepaid usage for the selected active subscriptions on a billing account
      description: Operator only. The service month must have no usage for those subscriptions. The response confirms durable enrollment. Wallet provisioning follows in account order.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [account, subscriptions, cap_cents]
              properties:
                account: { type: string, format: uuid }
                subscriptions:
                  type: array
                  minItems: 1
                  maxItems: 100
                  uniqueItems: true
                  items: { type: string, format: uuid }
                cap_cents: { type: integer, format: int64, minimum: 0 }
      responses:
        "202": { description: Enrollment accepted or exactly replayed }
        "409": { description: Ineligible account or conflicting enrollment }
  /prepaid/ratings/{id}:
    get:
      summary: Retrieve one immutable usage rating and its wallet receipt
      parameters:
        - { $ref: '#/components/parameters/id' }
      responses:
        "200":
          description: Evidence for operator and read roles with tariff hashes, source records, prices, funded and absorbed cents
          content: { application/json: { schema: { $ref: '#/components/schemas/PrepaidRating' } } }
        "404": { description: Rating unknown }
  /prepaid/rating-metrics:
    get:
      summary: Inspect outstanding wallet deliveries, source lag and posting latency
      responses:
        "200":
          description: Operator-only queue counts and cumulative posting p95 in seconds
          content: { application/json: { schema: { $ref: '#/components/schemas/PrepaidRatingMetrics' } } }
  /online-charging/entitlements:
    post:
      operationId: acquireOnlineEntitlement
      description: Claim an active prepaid subscription's clean calendar month and read its effective tariff window. Charging service only.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [account, subscription, day]
              properties:
                account: {type: string, format: uuid}
                subscription: {type: string, format: uuid}
                day: {type: string, format: date}
                claim: {type: boolean, default: true, description: Use false to preflight without transferring ownership.}
      responses:
        '200':
          description: Tariff slice and immutable book hash. The date range is inclusive.
          content:
            application/json:
              schema:
                type: object
                required: [account, subscription, book, book_hash, plan, start, from, through]
                properties:
                  account: {type: string, format: uuid}
                  subscription: {type: string, format: uuid}
                  book: {type: string}
                  book_hash: {type: string}
                  plan: {type: string}
                  start: {type: string, format: date}
                  from: {type: string, format: date}
                  through: {type: string, format: date}
        default: {$ref: '#/components/responses/Problem'}
  /online-charging/reports/{id}:
    parameters: [{$ref: '#/components/parameters/id'}]
    put:
      operationId: retainOnlineUsage
      description: Record settled or operator-covered delivered units once under the invocation's correlation UUID. Charging service only.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [subscription, day, kind, quantity]
              properties:
                subscription: {type: string, format: uuid}
                day: {type: string, format: date}
                kind: {type: string}
                quantity: {type: integer, format: int64, minimum: 1}
      responses:
        '204': {description: Report retained or exact replay}
        default: {$ref: '#/components/responses/Problem'}
  /online-charging/reconciliation:
    get:
      operationId: onlineReconciliation
      description: Full service-month counts. Operator responses include a page of secondary usage observations ordered by ingest sequence. The charging credential receives aggregate counts only.
      parameters:
        - {in: query, name: month, schema: {type: string}, description: YYYY-MM}
        - {in: query, name: after, schema: {type: integer, format: int64, minimum: 0}}
      responses:
        '200': {description: Reconciliation summary and observations, content: {application/json: {schema: {$ref: '#/components/schemas/OnlineReconciliation'}}}}
        default: {$ref: '#/components/responses/Problem'}
  /usage:
    post:
      parameters: [{ $ref: "#/components/parameters/idempotency" }]
      operationId: postUsage
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/UsageBatch" } } } }
      responses:
        '200':
          description: Mutually exclusive counts across the admitted records.
          content:
            application/json:
              schema:
                type: object
                required: [accepted, duplicates, reconciliation]
                properties:
                  accepted: {type: integer, minimum: 0, description: New offline usage admitted to rating.}
                  duplicates: {type: integer, minimum: 0, description: Exact replay of an existing record or copy.}
                  reconciliation: {type: integer, minimum: 0, description: Secondary evidence routed to online reconciliation.}
        default: {$ref: '#/components/responses/Problem'}
  /billing-accounts/{id}/open-bill:
    get:
      operationId: getOpenBill
      description: The bill the next seal would produce (default next month).
      parameters:
        - { $ref: "#/components/parameters/id" }
        - { name: period, in: query, schema: { type: string, pattern: "^[0-9]{4}-[0-9]{2}$" } }
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /billing-accounts/{id}/open-bill/html:
    get:
      operationId: getOpenBillPage
      description: The open month as the bill page, marked „Vorschau" — never stored, no number, no payment request, no GiroCode.
      parameters:
        - $ref: "#/components/parameters/id"
        - { name: period, in: query, schema: { type: string, pattern: "^[0-9]{4}-[0-9]{2}$" } }
      responses: { "200": { $ref: "#/components/responses/Html" }, default: { $ref: "#/components/responses/Problem" } }
  /billing-accounts/{id}/bills:
    get:
      operationId: listBills
      parameters: [{ $ref: "#/components/parameters/id" }]
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /billing-accounts/{id}/holds:
    get:
      operationId: listHolds
      description: The months that wait, each with its code, the failed e-invoice rules and `fix` — the one field to fix and the operation that fixes it. A month leaves the list when it is sealed.
      parameters: [{ $ref: "#/components/parameters/id" }]
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /billing-accounts/{id}/balance:
    get:
      operationId: getBalance
      description: The receivable, read from the ledger.
      parameters: [{ $ref: "#/components/parameters/id" }]
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /bills/{id}/investigation-evidence:
    get:
      description: Compare retained originals for consecutive months on one account using the configured pilot tariff versions. Line amounts follow the stated price basis. Positions in the tariff replay start at one.
      parameters: [{in: path, name: id, required: true, schema: {type: string, format: uuid}}]
      responses:
        '200':
          description: Sealed comparison or a reason for handoff.
          content:
            application/json:
              schema:
                type: object
                required: [current, number, seal, prices, changes, refusal, reconciliation]
                properties:
                  current: {type: string, format: uuid}
                  previous: {type: [string, 'null'], format: uuid}
                  number: {type: string}
                  previous_number: {type: [string, 'null']}
                  seal: {type: string}
                  previous_seal: {type: [string, 'null']}
                  prices: {enum: [gross, net]}
                  gross_delta: {type: [string, 'null']}
                  refusal: {enum: [null, first, cancelled, basis, retention, product, size, totals]}
                  reconciliation:
                    type: [object, 'null']
                    required: [previous_gross, current_gross, position_delta, additional_vat_delta]
                    properties:
                      previous_gross: {type: string}
                      current_gross: {type: string}
                      position_delta: {type: string}
                      additional_vat_delta: {type: [string, 'null']}
                  changes:
                    type: array
                    items:
                      type: object
                      required: [kind, label, before, after, delta, old_lines, new_lines, final_discount]
                      properties:
                        kind: {type: string}
                        label: {type: string}
                        before: {type: string}
                        after: {type: string}
                        delta: {type: string}
                        old_lines: {type: array, items: {type: integer}}
                        new_lines: {type: array, items: {type: integer}}
                        final_discount: {type: boolean}
        '404': {description: Unknown bill}
  /bills/{id}:
    get:
      operationId: getBill
      parameters: [{ $ref: "#/components/parameters/id" }]
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /bills/{id}/credit-note:
    post:
      operationId: issueCreditNote
      parameters: [{ $ref: "#/components/parameters/id" }, { $ref: "#/components/parameters/idempotency" }]
      requestBody: { required: true, content: { application/json: { schema: { $ref: "#/components/schemas/CreditNoteRequest" } } } }
      responses: { "201": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /bills/{id}/html:
    get:
      operationId: getBillHtml
      parameters: [{ $ref: "#/components/parameters/id" }]
      responses: { "200": { $ref: "#/components/responses/Html" }, default: { $ref: "#/components/responses/Problem" } }
  /bills/{id}/pdf:
    get:
      operationId: getBillPdf
      parameters: [{ $ref: "#/components/parameters/id" }]
      responses: { "200": { $ref: "#/components/responses/Pdf" }, default: { $ref: "#/components/responses/Problem" } }
  /bills/{id}/xml:
    get:
      operationId: getBillEInvoice
      description: The business bill's EN 16931 e-invoice — XRechnung (UBL) when the account has a Leitweg-ID, ZUGFeRD (CII) otherwise. Consumer bills answer 409 bill.no-einvoice.
      parameters: [{ $ref: "#/components/parameters/id" }]
      responses:
        "200": { description: "The e-invoice, stored at the first request", content: { application/xml: { schema: { type: string } } } }
        default: { $ref: "#/components/responses/Problem" }
  /price-books:
    get:
      operationId: listPriceBooks
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /webhooks:
    post:
      parameters: [{ $ref: "#/components/parameters/idempotency" }]
      operationId: createWebhook
      description: "Subscribe an endpoint to this service's events. The secret is answered once; deliveries are Standard Webhooks signed with it. An integration key's webhook gets only the types its key may see. The endpoint must be https on a public host outside development. Starts at the current end of the feed; replay reaches back."
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [name, url]
              properties:
                name: { type: string, pattern: "^[a-z][a-z0-9-]{0,31}$" }
                url: { type: string, format: uri }
                types: { type: array, maxItems: 20, items: { type: string }, description: "Type patterns; bill, contract.ended or de.telco.bill.* — empty means every type the key may see" }
      responses:
        "201": { description: "The webhook, with its secret (shown once)", content: { application/json: { schema: { type: object } } } }
        "409": { $ref: "#/components/responses/Problem" }
        "422": { $ref: "#/components/responses/Problem" }
        "503": { $ref: "#/components/responses/Problem" }
    get:
      operationId: listWebhooks
      description: "The webhooks the key may see — an integration key its own, an operator every one, the configured subscribers included — with their backlog. Never a secret."
      responses:
        "200": { $ref: "#/components/responses/Ok" }
  /webhooks/{name}:
    parameters:
      - { name: name, in: path, required: true, schema: { type: string } }
    get:
      operationId: getWebhook
      responses:
        "200": { $ref: "#/components/responses/Ok" }
        "404": { $ref: "#/components/responses/Problem" }
    delete:
      operationId: deleteWebhook
      responses:
        "204": { description: Deleted }
        "404": { $ref: "#/components/responses/Problem" }
        "409": { $ref: "#/components/responses/Problem" }
  /webhooks/{name}/test:
    parameters:
      - { name: name, in: path, required: true, schema: { type: string } }
    post:
      parameters: [{ $ref: "#/components/parameters/idempotency" }]
      operationId: testWebhook
      description: "Sends a de.telco.test.ping now and answers what the endpoint said: status, error kind, milliseconds."
      responses:
        "200": { $ref: "#/components/responses/Ok" }
        "404": { $ref: "#/components/responses/Problem" }
  /webhooks/{name}/deliveries:
    parameters:
      - { name: name, in: path, required: true, schema: { type: string } }
      - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 500 } }
    get:
      operationId: listWebhookDeliveries
      description: "The latest delivery attempts, newest first: sequence, type, time, status or error kind, milliseconds. Kept 30 days."
      responses:
        "200": { $ref: "#/components/responses/Ok" }
        "404": { $ref: "#/components/responses/Problem" }
  /webhooks/{name}/replay:
    parameters:
      - { name: name, in: path, required: true, schema: { type: string } }
    post:
      parameters: [{ $ref: "#/components/parameters/idempotency" }]
      operationId: replayWebhook
      description: "Moves the webhook back to after a sequence (0 for the beginning) and resumes it: everything since is delivered again, in order."
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, additionalProperties: false, required: [after], properties: { after: { type: integer, minimum: 0 } } }
      responses:
        "200": { $ref: "#/components/responses/Ok" }
        "404": { $ref: "#/components/responses/Problem" }
  /events:
    get:
      operationId: listEvents
      parameters:
        - { name: after, in: query, schema: { type: integer, minimum: 0 } }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 500 } }
        - { name: types, in: query, description: "Comma-separated type patterns, `*` any run of characters: de.telco.bill.*,de.telco.contract.ended", schema: { type: string } }
        - { name: subjects, in: query, description: "Comma-separated subjects, at most 50: contract/<id>,billing-account/<id>", schema: { type: string } }
      description: The event feed as CloudEvents 1.0 envelopes (structured JSON), oldest first. `next` is the cursor for the following page. Types are a public contract — never renamed; `data` only gains optional fields.
      responses:
        "200":
          description: A page of the feed
          content:
            application/json:
              schema:
                type: object
                required: [events, next]
                properties:
                  next: { type: integer }
                  events: { type: array, items: { $ref: "#/components/schemas/CloudEvent" } }
        default: { $ref: "#/components/responses/Problem" }
  /clock:
    get:
      operationId: getTestClock
      description: Test clock only.
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
    put:
      operationId: setTestClock
      description: Test clock only. Sets the date and runs the passes for it.
      requestBody:
        required: true
        content:
          application/json:
            schema: { type: object, additionalProperties: false, required: [today], properties: { today: { $ref: "#/components/schemas/Date" } } }
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /price-books/diff:
    get:
      operationId: diffPriceBooks
      description: What the new version does to the bills against the old — every plan's regular month and every golden test of the new book under both (the same function as telco price diff).
      parameters:
        - { name: old, in: query, required: true, schema: { type: string } }
        - { name: new, in: query, required: true, schema: { type: string } }
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /price-books/{ref}:
    get:
      operationId: getPriceBook
      description: A loaded book (id@version) with its plans' regular monthly gross and its golden tests, run now.
      parameters:
        - { name: ref, in: path, required: true, schema: { type: string } }
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /quote:
    get:
      operationId: quotePlan
      description: >-
        What a plan will cost from a day, before anyone signs: the first bill (the month
        service begins in, from the start day, with one-off charges) and the next, each line
        with its German explanation; every later monthly price step until the price settles
        (36 months at most); and one sentence a shop shows verbatim („Erste Rechnung 41,35 €,
        danach 29,97 € im Monat, ab März 2027 59,97 €."). The same composition a seal runs;
        it starts and stores nothing. Usage is not included.
      parameters:
        - { name: plan, in: query, required: true, description: "book@version/plan", schema: { type: string, examples: ["example-fibre@2026-11/glasfaser-1000"] } }
        - { name: start, in: query, description: The first day of service; default today, schema: { $ref: "#/components/schemas/Date" } }
      responses: { "200": { $ref: "#/components/responses/Ok" }, default: { $ref: "#/components/responses/Problem" } }
  /holds:
    get:
      operationId: listOpenHolds
      description: Read up to 50 open account-months ordered by hold date and fact sequence.
      parameters:
        - { name: after, in: query, description: Continuation returned in next., schema: { type: string, pattern: "^[1-9][0-9]*$" } }
      responses:
        "200":
          description: Matching rows and the continuation for the next page.
          content:
            application/json:
              schema:
                type: object
                required: [items, next]
                properties:
                  items: { type: array, items: { $ref: "#/components/schemas/OpenHold" } }
                  next: { type: [string, 'null'] }
        default: { $ref: "#/components/responses/Problem" }
  /subscriptions/{id}/mobile-meter:
    parameters:
      - { $ref: "#/components/parameters/id" }
      - { name: period, in: query, schema: { type: string, example: "2026-10" } }
    get:
      operationId: mobileDataMeter
      description: Per-slice agreed and consumed bytes as exact decimal strings, source recency, closing status and notice preference. A customer credential can read its own subscriptions.
      responses: { "200": { description: Success, content: { application/json: { schema: { $ref: "#/components/schemas/MobileMeter" } } } }, default: { $ref: "#/components/responses/Problem" } }
  /subscriptions/{id}/mobile-meter/html:
    parameters:
      - { $ref: "#/components/parameters/id" }
      - { name: period, in: query, schema: { type: string, example: "2026-10" } }
    get:
      operationId: mobileDataMeterHtml
      description: German customer view for the authenticated portal.
      responses: { "200": { description: Private customer meter, content: { text/html: { schema: { type: string } } } }, default: { $ref: "#/components/responses/Problem" } }
  /subscriptions/{id}/mobile-meter/preference:
    parameters: [ { $ref: "#/components/parameters/id" } ]
    put:
      operationId: setMobileAllowanceWarning
      description: Subscribe or unsubscribe from the free volume notice. Excessive-use warnings remain independent.
      requestBody:
        required: true
        content: { application/json: { schema: { type: object, required: [enabled], additionalProperties: false, properties: { enabled: { type: boolean } } } } }
      responses: { "200": { description: Success, content: { application/json: { schema: { type: object, required: [enabled], properties: { enabled: { type: boolean } } } } } }, default: { $ref: "#/components/responses/Problem" } }
  /mobile-warnings:
    get:
      operationId: mobileWarningQueue
      description: German warning messages with decision and delivery evidence. Supply the warning UUID to the downstream gateway as its deduplication key.
      parameters:
        - { name: state, in: query, schema: { type: string, enum: [outstanding, pending, failed, delivered, suppressed], default: outstanding } }
        - { name: after, in: query, schema: { type: string, format: uuid } }
        - { name: limit, in: query, schema: { type: integer, minimum: 1, maximum: 100, default: 50 } }
      responses: { "200": { description: Success, content: { application/json: { schema: { type: array, items: { $ref: "#/components/schemas/MobileWarning" } } } } }, default: { $ref: "#/components/responses/Problem" } }
  /mobile-warnings/{id}/delivery:
    parameters: [ { $ref: "#/components/parameters/id" } ]
    put:
      operationId: recordMobileWarningDelivery
      description: Record a gateway attempt using a stable opaque reference. An identical retry returns the same result.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [outcome, reference]
              properties:
                outcome: { type: string, enum: [delivered, failed] }
                reference: { type: string, minLength: 1, maxLength: 128, pattern: "^[A-Za-z0-9_.-]+$" }
      responses: { "204": { description: Delivery outcome recorded }, default: { $ref: "#/components/responses/Problem" } }
  /subscriptions/{id}/mobile-meter/coverage:
    parameters: [ { $ref: "#/components/parameters/id" } ]
    put:
      operationId: confirmDailyMeterCoverage
      description: The operator attests all source feeds for a subscription and usage day, including days with no activity. An earlier gap or unresolved record keeps later days provisional.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: false
              required: [day, reference]
              properties:
                day: { type: string, format: date }
                reference: { type: string, maxLength: 128, pattern: "^[A-Za-z0-9_.-]+$" }
      responses: { "204": { description: Confirmation recorded }, default: { $ref: "#/components/responses/Problem" } }
