openapi: 3.0.3
info:
  title: SpamAPI
  version: 1.0.0
  description: REST API for spam detection and dashboard management.
servers:
- url: https://api.spamapi.de
  description: Public API (/api/v1) and Stripe webhooks
- url: https://app.spamapi.de
  description: Dashboard, auth and admin APIs used by the dashboard
paths:
  /api/v1/training/participation:
    post:
      summary: Explicitly configure installation contributions (free or paid)
      description: Requires the configured policy version to enable. Disabling withdraws stored sources and advances the participation version. Authenticated site URL changes use the expected version, withdraw old-site sources and reset contributor trust. API keys and checks never enroll installations automatically.
      security: [{ApiKeyHeader: []}]
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/TrainingParticipationRequest'}
      responses:
        '200':
          description: Durable participation setting
          content:
            application/json:
              schema: {$ref: '#/components/schemas/TrainingInstallation'}
        '400': {description: Invalid or oversized JSON}
        '401': {description: Authentication required}
        '403': {description: Disabled policy or installation access denied}
        '409': {description: Version or installation conflict}
        '429': {description: Independent contribution resource budget exceeded}
        '503': {description: Storage or independent withdrawal ledger unavailable; retry the same setting}
  /api/v1/training/participation/{installation}:
    get:
      summary: Read an owned installation's contribution status
      security: [{ApiKeyHeader: []}]
      parameters:
      - in: path
        name: installation
        required: true
        schema: {type: string, format: uuid}
      responses:
        '200':
          description: Current participation and contributor review state
          content:
            application/json:
              schema: {$ref: '#/components/schemas/TrainingInstallation'}
        '401': {description: Authentication required}
        '403': {description: Installation access denied}
  /api/v1/training/contributions:
    post:
      summary: Durably ingest a bounded batch of versioned comment assertions
      description: Maximum 256 KiB and 20 events. Receipts are idempotent per installation/event ID; newer item revisions supersede older labels. Withdrawal-only batches remain available during collection pauses or policy changes using the installation's recorded policy and participation version. Manual provenance is an assertion, and new contributors remain quarantined. No check quota is consumed. Legacy feedback never enrolls or trains.
      security: [{ApiKeyHeader: []}]
      requestBody:
        required: true
        content:
          application/json:
            schema: {$ref: '#/components/schemas/TrainingBatch'}
      responses:
        '202':
          description: SQL ingestion and independent revision ledger are durable; eligibility/training are separate
          content:
            application/json:
              schema:
                type: object
                required: [status, receipts]
                properties:
                  status: {type: string, enum: [durable]}
                  receipts:
                    type: array
                    items:
                      type: object
                      required: [event_id, status]
                      properties:
                        event_id: {type: string, format: uuid}
                        status: {type: string, enum: [accepted, duplicate, stale]}
        '400': {description: Invalid or oversized JSON}
        '401': {description: Authentication required}
        '403': {description: Participation, prediction linkage or installation access denied}
        '409': {description: Conflicting event/revision, invalid fields or expired event}
        '429':
          description: Independent contribution budget exceeded
          headers:
            Retry-After: {schema: {type: integer}, description: Remaining rolling-budget window in seconds; resource-capacity limits may omit this header}
        '503': {description: Storage or independent ledger unavailable; retry identical event IDs}
  /admin/api/users/{id}/entitlements:
    get:
      summary: Inspect API credit and complimentary history
      tags:
      - Admin
      security:
      - SessionAuth: []
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      - name: limit
        in: query
        schema:
          type: integer
          minimum: 1
          maximum: 100
      - name: credits_offset
        in: query
        schema:
          type: integer
          minimum: 0
          maximum: 1000000
      - name: overrides_offset
        in: query
        schema:
          type: integer
          minimum: 0
          maximum: 1000000
      responses:
        '200':
          description: Bounded target-scoped histories.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminEntitlementHistory'
        '400':
          description: Invalid action, reason, interval, limit or pagination.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Authentication required.
        '403':
          description: Current admin authority or session has been lost.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: User or referenced grant not found for this target.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Local persistence unavailable. Retry an ambiguous command with the identical command ID and
            payload.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
    post:
      summary: Apply an atomic local entitlement command
      tags:
      - Admin
      security:
      - SessionAuth: []
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      description: Requires current account version and a unique command UUID. Identical retries return the original
        receipt after current authorization; reuse with changed actor, target or payload conflicts. Credits expire
        at UTC month end. Reversals cannot exceed the original unreversed grant or invalidate used or reserved capacity.
        Complimentary grants require start and expiry, disallow overlap or an ongoing paid subscription, and preserve
        prior usage/reservations on expiry or revoke. Ledger/override, deduplication receipt, account version and
        audit commit together. No Stripe writes, refunds or billing credits.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminEntitlementRequest'
      responses:
        '200':
          description: Applied or safely replayed command.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminEntitlementResult'
        '409':
          description: version_conflict, command_conflict, credit_bounds, quota_month_changed, complimentary_overlap or subscription_conflict.
            Reload detail before creating a changed command.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '400':
          description: Invalid action, reason, interval, limit or pagination.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Authentication required.
        '403':
          description: Current admin authority or session has been lost.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: User or referenced grant not found for this target.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Local persistence unavailable. Retry an ambiguous command with the identical command ID and
            payload.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
  /admin/api/users/{id}/actions:
    post:
      summary: Apply local account action
      description: Local action; current version, reason and current authority checked
        in the shared transaction. Role changes require a proof bound to the exact intent.
        Self-demotion/suspension and closed accounts are rejected. No automatic retries.
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminActionRequest'
      responses:
        '200':
          description: Applied result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminActionResult'
        '400':
          description: Invalid action, extra fields or invalid identity input
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Session unavailable
        '404':
          description: User or target API key unavailable
        '403':
          description: admin_permission_lost redirects out of admin. reauth_required,
            invalid_password and self_access_change are action-specific and preserve
            admin navigation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: version_conflict requires reloading the target detail. username_exists
            and last_admin allow correcting the input or retrying after the condition
            changes. Never retry automatically.
        '429':
          description: Rate limit or one-minute password-reset cooldown
        '500':
          description: Transaction failed and rolled back; a commit acknowledgement
            can be ambiguous, so refresh before any manual retry.
        '202':
          description: Password-reset request accepted, never a delivery receipt. No
            automatic retry.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminActionResult'
  /admin/api/users/{id}/reauthenticate:
    post:
      summary: Reauthenticate for a role change
      description: Sessionless password check for a role-change intent; five-minute
        single-use proof bound to actor, session, actor version, target and parameters.
        Replaces the prior proof for this actor/session. Does not create a session or
        change last-login.
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminReauthRequest'
      responses:
        '200':
          description: Proof issued
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminReauthResult'
        '400':
          description: Invalid action, extra fields or invalid identity input
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Session unavailable
        '404':
          description: User or target API key unavailable
        '403':
          description: admin_permission_lost redirects out of admin. reauth_required,
            invalid_password and self_access_change are action-specific and preserve
            admin navigation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: version_conflict requires reloading the target detail. username_exists
            and last_admin allow correcting the input or retrying after the condition
            changes. Never retry automatically.
        '429':
          description: Rate limit or one-minute password-reset cooldown
        '500':
          description: Transaction failed and rolled back; a commit acknowledgement
            can be ambiguous, so refresh before any manual retry.
  /admin/api/users:
    get:
      summary: Search users
      security:
      - SessionAuth: []
      parameters:
      - in: query
        name: limit
        schema:
          type: integer
          minimum: 1
          maximum: 100
      - in: query
        name: offset
        schema:
          type: integer
          minimum: 0
          maximum: 1000000
      - in: query
        name: q
        schema:
          type: string
          maxLength: 200
        description: Literal case-insensitive substring of email or username, up to 200 Unicode code points after trimming whitespace.
      responses:
        '200':
          description: Read-only result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminListResponse'
        '401':
          description: Invalid session or blocked account
        '403':
          description: admin_permission_lost; remove admin cache and exit /admin, preserving
            a valid normal session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '400':
          description: Invalid pagination/search/cursor
        '404':
          description: Unknown user
        '500':
          description: Local read failure
  /admin/api/users/{id}:
    get:
      summary: Inspect user identity, access, usage and local billing projection
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      - in: query
        name: keys_limit
        schema:
          type: integer
          minimum: 1
          maximum: 100
          default: 25
        description: Maximum active API keys in the embedded page.
      - in: query
        name: keys_offset
        schema:
          type: integer
          minimum: 0
          maximum: 1000000
          default: 0
        description: Active-key page offset; ordered by created_at descending, then ID descending.
      responses:
        '200':
          description: Read-only result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminDetailResponse'
        '401':
          description: Invalid session or blocked account
        '403':
          description: admin_permission_lost; remove admin cache and exit /admin, preserving
            a valid normal session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '400':
          description: Invalid pagination/search/cursor
        '404':
          description: Unknown user
        '500':
          description: Local read failure
    delete:
      summary: Request separate staged permanent deletion of a closed account
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminDeletionCommand'
      responses:
        '200':
          description: Durable lifecycle result; available after identity erasure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminDeletion'
        '202':
          description: Durable lifecycle result; available after identity erasure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminDeletion'
        '400':
          description: Malformed intent
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Invalid session
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '403':
          description: Administrative access lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: Unknown account or closure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: Version, policy or intent conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Persistence failure; retry the same command
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '503':
          description: Lifecycle service unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
  /admin/api/users/{id}/deletion:
    get:
      summary: Inspect retention, cooling-off, eligibility and durable erasure progress
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Durable lifecycle result; available after identity erasure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminDeletionPreview'
        '400':
          description: Malformed intent
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Invalid session
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '403':
          description: Administrative access lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: Unknown account or closure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: Version, policy or intent conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Persistence failure; retry the same command
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '503':
          description: Lifecycle service unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
  /admin/api/users/{id}/deletion/reauthenticate:
    post:
      summary: Reauthenticate for the exact generation, deletion intent and retention policy
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminDeletionReauthRequest'
      responses:
        '200':
          description: Durable lifecycle result; available after identity erasure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminReauthResult'
        '400':
          description: Malformed intent
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Invalid session
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '403':
          description: Administrative access lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: Unknown account or closure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: Version, policy or intent conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Persistence failure; retry the same command
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '503':
          description: Lifecycle service unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
  /admin/api/users/{id}/deletion/review:
    post:
      summary: Renew deletion consent before erasure with an operation-version CAS
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminDeletionReviewCommand'
      responses:
        '200':
          description: Durable lifecycle result; available after identity erasure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminDeletion'
        '202':
          description: Renewed durable deletion intent awaiting eligibility
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminDeletion'
        '400':
          description: Malformed intent
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Invalid session
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '403':
          description: Administrative access lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: Unknown account or closure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: Version, policy or intent conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Persistence failure; retry the same command
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '503':
          description: Lifecycle service unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
  /admin/api/users/{id}/sites:
    get:
      summary: Inspect observed sites
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      - in: query
        name: limit
        schema:
          type: integer
          minimum: 1
          maximum: 100
      - in: query
        name: offset
        schema:
          type: integer
          minimum: 0
          maximum: 1000000
      responses:
        '200':
          description: Read-only result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DashboardSitesResponse'
        '401':
          description: Invalid session or blocked account
        '403':
          description: admin_permission_lost; remove admin cache and exit /admin, preserving
            a valid normal session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '400':
          description: Invalid pagination/search/cursor
        '404':
          description: Unknown user
        '500':
          description: Local read failure
  /admin/api/users/{id}/audit:
    get:
      summary: Inspect audit history
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      - in: query
        name: limit
        schema:
          type: integer
          minimum: 1
          maximum: 100
      - in: query
        name: offset
        schema:
          type: integer
          minimum: 0
          maximum: 1000000
      responses:
        '200':
          description: Read-only result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminAuditResponse'
        '401':
          description: Invalid session or blocked account
        '403':
          description: admin_permission_lost; remove admin cache and exit /admin, preserving
            a valid normal session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '400':
          description: Invalid pagination/search/cursor
        '404':
          description: Unknown user
        '500':
          description: Local read failure
  /admin/api/users/{id}/billing:
    get:
      summary: Inspect live Stripe subscription and invoices without writes
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      - in: query
        name: starting_after
        schema:
          type: string
          maxLength: 100
        description: Opaque Stripe invoice cursor, scoped by the stored customer ID.
      responses:
        '200':
          description: Read-only result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminInspection'
        '401':
          description: Invalid session or blocked account, including original-session revocation or expiry during Stripe inspection; no billing data is returned. Middleware rejects invalid sessions as plain text; the final inspection recheck returns AdminError JSON.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
            text/plain:
              schema:
                type: string
        '403':
          description: admin_permission_lost; remove admin cache and exit /admin, preserving
            a valid normal session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '400':
          description: Invalid pagination/search/cursor
        '404':
          description: Unknown user
        '500':
          description: Local read failure
        '502':
          description: Stripe inspection failed; local projection remains available.
        '503':
          description: Live billing inspection is not configured.
  /api/v1/verify-key:
    post:
      summary: Verify API key
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/VerifyKeyRequest"
      responses:
        "200":
          description: Verification result
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/VerifyKeyResponse"
        "400":
          $ref: "#/components/responses/BadRequestError"
        "429":
          $ref: "#/components/responses/RateLimitError"
        "503":
          description: Entitlement lookup failed; quota_unavailable.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /api/v1/pricing:
    get:
      summary: Public plans and prices
      description: |
        No authentication. Lists the plans with their monthly check quotas and, for Pro and Business, the configured Stripe prices that Checkout charges. Prices are read from Stripe and reused for up to five minutes; responses may be cached for 60 seconds.
        If either configured price cannot be read or is not a fixed recurring amount, the response is 503 pricing_unavailable. No partial, default or outdated prices are returned.
      responses:
        "200":
          description: Current plans and prices
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PublicPricing"
        "503":
          description: Pricing is unavailable; pricing_unavailable.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /api/v1/check:
    post:
      summary: Check content for spam
      description: |
        A metered attempt reserves capacity before classification. Successful usage, site statistics and the log commit atomically before a decision is returned.
        Usage belongs to the UTC admission month, including a completion after month end. Guaranteed-Spam and Test-Ham remain unmetered but still require available quota.
        X-Request-ID is caller-controlled correlation, not an idempotency key. Every HTTP attempt receives a new internal UUID; retrying a lost response can charge a second attempt.
      security:
        - ApiKeyHeader: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CheckRequest"
      responses:
        "200":
          description: Check result
          headers:
            X-SpamAPI-Pro-Tip:
              schema:
                type: string
            X-SpamAPI-Request-ID:
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/CheckResponse"
        "400":
          $ref: "#/components/responses/BadRequestError"
        "401":
          $ref: "#/components/responses/AuthError"
        "403":
          description: Account access was removed before classification completion; no result writes are committed.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              example:
                error: account_unavailable
                message: account access unavailable
        "429":
          $ref: "#/components/responses/RateLimitError"
        "500":
          description: Classification failed; no decision is returned and the reservation is released when possible.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              example:
                error: detection_error
                message: failed to analyze content
        "503":
          description: Classification provider or quota persistence is unavailable. No decision is returned. An ambiguous usage commit may have charged this attempt; recovery reconciles it by internal UUID. A new HTTP retry is a new attempt.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              example:
                error: detection_unavailable
                message: spam classification is temporarily unavailable
  /api/v1/submit-spam:
    post:
      summary: Report false negative (spam)
      security:
        - ApiKeyHeader: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/FeedbackRequest"
      responses:
        "200":
          description: Feedback accepted
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/FeedbackResponse"
        "400":
          $ref: "#/components/responses/BadRequestError"
        "401":
          $ref: "#/components/responses/AuthError"
        "429":
          $ref: "#/components/responses/RateLimitError"
        "500":
          description: Feedback could not be stored; feedback_error or usage_error.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /api/v1/submit-ham:
    post:
      summary: Report false positive (ham)
      security:
        - ApiKeyHeader: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/FeedbackRequest"
      responses:
        "200":
          description: Feedback accepted
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/FeedbackResponse"
        "400":
          $ref: "#/components/responses/BadRequestError"
        "401":
          $ref: "#/components/responses/AuthError"
        "429":
          $ref: "#/components/responses/RateLimitError"
        "500":
          description: Feedback could not be stored; feedback_error or usage_error.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /api/v1/usage:
    get:
      summary: Get usage summary
      security:
        - ApiKeyHeader: []
      responses:
        "200":
          description: Usage summary
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UsageResponse"
        "401":
          $ref: "#/components/responses/AuthError"
        "429":
          $ref: "#/components/responses/RateLimitError"
        "403":
          description: Account is unavailable; account_unavailable.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
        "503":
          description: Entitlement lookup failed; quota_unavailable.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /api/v1/sites:
    get:
      summary: List sites
      security:
        - ApiKeyHeader: []
      parameters:
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
            minimum: 0
            maximum: 100
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
            minimum: 0
      responses:
        "200":
          description: Site list
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SitesResponse"
        "401":
          $ref: "#/components/responses/AuthError"
        "429":
          $ref: "#/components/responses/RateLimitError"
        "500":
          description: Sites could not be read; sites_error.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
  /dashboard/api/account:
    get:
      summary: Get account details
      security:
        - SessionAuth: []
      responses:
        "200":
          description: Account details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AccountResponse"
    patch:
      summary: Initiate email address change
      security:
        - SessionAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AccountUpdateRequest"
      responses:
        "200":
          description: Current account; the new email takes effect after confirmation.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AccountResponse"
  /dashboard/api/api-keys:
    get:
      summary: List API keys
      security:
        - SessionAuth: []
      responses:
        "200":
          description: API keys
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/APIKeyListResponse"
    post:
      summary: Create API key
      security:
        - SessionAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/APIKeyCreateRequest"
      responses:
        "200":
          description: Created API key
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/APIKeyCreateResponse"
  /dashboard/api/api-keys/{id}:
    delete:
      summary: Delete API key
      security:
        - SessionAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        "204":
          description: Deleted
  /dashboard/api/usage/summary:
    get:
      summary: Dashboard usage summary
      security:
        - SessionAuth: []
      responses:
        "200":
          description: Usage summary
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DashboardUsageSummary"
  /dashboard/api/usage/history:
    get:
      summary: Dashboard usage history
      security:
        - SessionAuth: []
      parameters:
        - in: query
          name: months
          schema:
            type: integer
            default: 6
            minimum: 1
            maximum: 24
      responses:
        "200":
          description: Usage history
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UsageHistoryResponse"
  /dashboard/api/sites:
    get:
      summary: Dashboard sites list
      security:
        - SessionAuth: []
      parameters:
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
            minimum: 0
            maximum: 100
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
            minimum: 0
      responses:
        "200":
          description: Sites
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DashboardSitesResponse"
  /dashboard/api/billing/subscription:
    get:
      summary: Billing subscription
      security:
        - SessionAuth: []
      responses:
        "200":
          description: Subscription
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BillingSubscription"
  /dashboard/api/billing/checkout:
    post:
      summary: Create checkout session
      security:
        - SessionAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BillingCheckoutRequest"
      responses:
        "200":
          description: Checkout URL. Prices include VAT; Checkout collects the billing address and an optional business tax ID, and Stripe Tax shows the VAT or reverse charge.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BillingCheckoutResponse"
        "503":
          description: Billing identity cutover required (billing_cutover_required), or Stripe Tax is not ready to split VAT out of the prices (billing_tax_unavailable).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
      parameters:
      - in: header
        name: Idempotency-Key
        required: true
        schema:
          type: string
          format: uuid
        description: Stable Checkout command ID. Reuse for identical retries; unresolved commands block conflicting
          Checkout.
  /dashboard/api/billing/portal:
    post:
      summary: Create portal session
      security:
        - SessionAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BillingPortalRequest"
      responses:
        "200":
          description: Portal URL
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BillingPortalResponse"
  /auth/register:
    post:
      summary: Register account
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AuthRegisterRequest"
      responses:
        "201":
          description: Auth result
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AuthResult"
  /auth/login:
    post:
      summary: Login
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AuthLoginRequest"
      responses:
        "200":
          description: Auth result
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AuthResult"
  /auth/logout:
    post:
      summary: Logout
      security:
        - SessionAuth: []
      responses:
        "204":
          description: Logged out
  /auth/me:
    get:
      summary: Current user
      security:
        - SessionAuth: []
      responses:
        "200":
          description: Current user
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AuthMeResponse"
  /auth/verify:
    post:
      summary: Verify email address
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AuthTokenRequest"
      responses:
        "200":
          description: Verified user
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AccountResponse"
  /auth/confirm-email-change:
    post:
      summary: Confirm email address change
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AuthTokenRequest"
      responses:
        "200":
          description: Updated user
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AccountResponse"
  /auth/forgot:
    post:
      summary: Request password reset email
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AuthForgotRequest"
      responses:
        "202":
          description: Password reset request accepted
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AuthForgotResponse"
  /auth/reset:
    post:
      summary: Reset password
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AuthResetRequest"
      responses:
        "200":
          description: User with updated password
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserPublic"
  /webhooks/stripe:
    post:
      summary: Stripe webhook
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        "200":
          description: Accepted
        "400":
          description: Missing or invalid signature, malformed payload or incompatible API version
        "409":
          description: Another webhook changed the billing record during processing; Stripe retries the event
        "413":
          description: Payload larger than 1 MiB
        "500":
          description: The verified event could not be processed; Stripe retries the event
  /admin/api/users/{id}/billing/credits:
    get:
      summary: Read current monetary invoice balance and paginated immutable Stripe credit history
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      - in: query
        name: customer
        required: false
        description: Optional retained customer binding; defaults to the current binding.
        schema:
          type: string
          pattern: ^cus_
          maxLength: 255
      - in: query
        name: cursor
        required: false
        schema:
          type: string
          pattern: ^cbtxn_
          maxLength: 255
      responses:
        '200':
          description: Authorized result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminBillingCreditHistory'
        '400':
          description: Invalid action-specific request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Original session invalid or lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '403':
          description: admin_permission_lost, reauth_required, or invalid_password
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: Unknown user, preview, or operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: Stale preview/version, ownership conflict, unsupported configuration, or unresolved billing
            command
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Local transaction/read failure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '502':
          description: Stripe read unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '503':
          description: Verified billing scope or authority cutover required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
      description: Reads only a verified current or retained historical customer binding for this target. Negative
        amounts are credits; entries also show Stripe application/adjustment history. No reversal command is
        exposed.
  /admin/api/users/{id}/billing/preview:
    post:
      summary: Preview a scoped subscription or financial effect without mutation
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Authorized result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminBillingPreview'
        '400':
          description: Invalid action-specific request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Original session invalid or lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '403':
          description: admin_permission_lost, reauth_required, or invalid_password
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: Unknown user, preview, or operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: Stale preview/version, ownership conflict, unsupported configuration, or unresolved billing
            command
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Local transaction/read failure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '502':
          description: Stripe read unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '503':
          description: Verified billing scope or authority cutover required (billing_cutover_required), or Stripe Tax is not ready for Checkout (billing_tax_unavailable)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminBillingPreviewRequest'
  /admin/api/users/{id}/billing/reauthenticate:
    post:
      summary: Verify the administrator password for this exact billing command
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Authorized result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminReauthResult'
        '400':
          description: Invalid action-specific request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Original session invalid or lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '403':
          description: admin_permission_lost, reauth_required, or invalid_password
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: Unknown user, preview, or operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: Stale preview/version, ownership conflict, unsupported configuration, or unresolved billing
            command
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Local transaction/read failure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '502':
          description: Stripe read unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '503':
          description: Verified billing scope or authority cutover required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminBillingReauthRequest'
  /admin/api/users/{id}/billing/operations:
    post:
      summary: Persist an audited, idempotent subscription command before Stripe effects
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Authorized result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminBillingOperation'
        '202':
          description: Durable command accepted. Identical command IDs return the existing operation; conflicting
            payloads return 409. Poll the operation resource.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminBillingOperation'
        '400':
          description: Invalid action-specific request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Original session invalid or lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '403':
          description: admin_permission_lost, reauth_required, or invalid_password
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: Unknown user, preview, or operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: Stale preview/version, ownership conflict, unsupported configuration, or unresolved billing
            command
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Local transaction/read failure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '502':
          description: Stripe read unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '503':
          description: Verified billing scope or authority cutover required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AdminBillingCommand'
  /admin/api/users/{id}/billing/operations/{operation}:
    get:
      summary: Read the safe durable operation status and customer Checkout handoff
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      - in: path
        name: operation
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Authorized result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminBillingOperation'
        '400':
          description: Invalid action-specific request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Original session invalid or lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '403':
          description: admin_permission_lost, reauth_required, or invalid_password
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: Unknown user, preview, or operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: Stale preview/version, ownership conflict, unsupported configuration, or unresolved billing
            command
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Local transaction/read failure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '502':
          description: Stripe read unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '503':
          description: Verified billing scope or authority cutover required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
  /admin/api/users/{id}/billing/operations/{operation}/reconcile:
    post:
      summary: Reconcile a recorded step without issuing a new Stripe mutation
      security:
      - SessionAuth: []
      parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      - in: path
        name: operation
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: Authorized result
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminBillingOperation'
        '400':
          description: Invalid action-specific request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '401':
          description: Original session invalid or lost
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '403':
          description: admin_permission_lost, reauth_required, or invalid_password
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '404':
          description: Unknown user, preview, or operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '409':
          description: Stale preview/version, ownership conflict, unsupported configuration, or unresolved billing
            command
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '500':
          description: Local transaction/read failure
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '502':
          description: Stripe read unavailable
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
        '503':
          description: Verified billing scope or authority cutover required
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdminError'
components:
  securitySchemes:
    ApiKeyHeader:
      type: apiKey
      in: header
      name: X-API-Key
    SessionAuth:
      type: http
      scheme: bearer
  responses:
    AuthError:
      description: Authentication error
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    BadRequestError:
      description: Invalid JSON or a missing or invalid field; invalid_json, validation_error, invalid_request or missing_api_key.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
    RateLimitError:
      description: Too many requests in a minute (rate_limit_exceeded, with Retry-After) or, for checks, the monthly quota is used up (usage_limit_exceeded).
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
  schemas:
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
        request_id:
          type: string
      required: [error, message]
    VerifyKeyRequest:
      type: object
      properties:
        api_key:
          type: string
        blog:
          type: string
      required: [api_key]
    VerifyKeyResponse:
      type: object
      properties:
        training_policy:
          type: object
          required: [enabled, policy_version, policy_url, retention_days]
          properties:
            enabled: {type: boolean}
            policy_version: {type: string}
            policy_url: {type: string, format: uri}
            retention_days: {type: integer, minimum: 8, maximum: 365}
        valid:
          type: boolean
        plan:
          type: string
        usage:
          $ref: "#/components/schemas/UsageInfo"
      required: [valid]
    TrainingParticipationRequest:
      type: object
      additionalProperties: false
      required: [installation_id, site, enabled, policy_version, expected_version]
      properties:
        installation_id: {type: string, format: uuid}
        site: {type: string, format: uri, maxLength: 2048}
        enabled: {type: boolean}
        policy_version: {type: string, maxLength: 100}
        expected_version: {type: integer, minimum: 0}
    TrainingInstallation:
      type: object
      required: [installation_id, site, enabled, policy_version, version, activated_at, trust]
      properties:
        installation_id: {type: string, format: uuid}
        site: {type: string, format: uri}
        enabled: {type: boolean}
        policy_version: {type: string}
        version: {type: integer, minimum: 1}
        activated_at: {type: integer, description: Server receipt time in Unix microseconds}
        trust: {type: string, enum: [quarantine, reviewed, excluded]}
    TrainingBatch:
      type: object
      additionalProperties: false
      required: [schema_version, installation_id, policy_version, participation_version, minimizer_version, events]
      properties:
        schema_version: {type: integer, enum: [1]}
        installation_id: {type: string, format: uuid}
        policy_version: {type: string}
        participation_version: {type: integer, minimum: 1}
        minimizer_version: {type: string, enum: [wordpress-min-v1]}
        events:
          type: array
          minItems: 1
          maxItems: 20
          items: {$ref: '#/components/schemas/TrainingContribution'}
    TrainingContribution:
      type: object
      additionalProperties: false
      required: [event_id, item_id, revision, content_revision, label, provenance, content, language, occurred_at]
      properties:
        event_id: {type: string, format: uuid}
        item_id: {type: string, format: uuid}
        revision: {type: integer, minimum: 1, maximum: 9007199254740992}
        content_revision: {type: string, pattern: '^[a-f0-9]{64}$', description: SHA-256 of the source content revision}
        label: {type: string, enum: [spam, ham, withdrawn]}
        provenance: {type: string, enum: [manual, automatic, import, edit]}
        content: {type: string, maxLength: 32768, description: UTF-8 minimized text; 32768-byte server limit}
        language: {type: string, maxLength: 35}
        prediction_ref: {type: string, format: uuid}
        occurred_at: {type: integer, description: Unix microseconds; new events must be no older than seven days}
    StatisticalDiagnostics:
      type: object
      required: [model_id, feature_version, threshold_version, score, discard_threshold, enforced, status]
      properties:
        model_id: {type: string}
        feature_version: {type: string}
        threshold_version: {type: string}
        score: {type: number, minimum: 0, maximum: 1}
        discard_threshold: {type: number}
        enforced: {type: boolean}
        status: {type: string, enum: [unavailable, invalidated, scored]}
    CheckRequest:
      type: object
      properties:
        installation_id:
          type: string
          format: uuid
          description: Optional registered installation; ownership and site are verified independently of contribution participation.
        api_key:
          type: string
        blog:
          type: string
        user_ip:
          type: string
        user_agent:
          type: string
        referrer:
          type: string
        permalink:
          type: string
        comment_type:
          type: string
        comment_author:
          type: string
        comment_author_email:
          type: string
        comment_author_url:
          type: string
        comment_content:
          type: string
        comment_date_gmt:
          type: string
        blog_lang:
          type: string
        blog_charset:
          type: string
        user_role:
          type: string
        is_test:
          type: boolean
        recheck_reason:
          type: string
        honeypot_field_name:
          type: string
        honeypot_field_value:
          type: string
      required: [blog, user_ip]
    CheckResponse:
      type: object
      properties:
        prediction_ref:
          type: string
          format: uuid
          description: Persisted check reference authorized by account and site. Absent for overrides; request_id is a tracing ID.
        statistical:
          $ref: '#/components/schemas/StatisticalDiagnostics'
        is_spam:
          type: boolean
        score:
          type: number
          format: float
        recommendation:
          type: string
          enum: [allow, review, discard]
        reasons:
          type: array
          items:
            type: string
        request_id:
          type: string
      required: [is_spam, score, recommendation, request_id]
    FeedbackRequest:
      type: object
      properties:
        api_key:
          type: string
        blog:
          type: string
        user_ip:
          type: string
          description: Client IPv4 or IPv6 address.
        user_agent:
          type: string
        comment_type:
          type: string
        comment_author:
          type: string
        comment_author_email:
          type: string
        comment_content:
          type: string
      required: [blog, user_ip]
    FeedbackResponse:
      type: object
      properties:
        status:
          type: string
          enum: [ok]
      required: [status]
    PublicPricing:
      type: object
      properties:
        livemode:
          type: boolean
          description: False for Stripe sandbox prices, which are never production prices.
        quota_period:
          type: string
          enum: [utc_calendar_month]
          description: Checks count toward the UTC calendar month in which they were admitted, independent of billing dates.
        quota_exceeded:
          type: string
          enum: [rejected]
          description: Checks over the quota get HTTP 429 usage_limit_exceeded; there are no overage charges.
        plans:
          type: array
          description: Free, Pro, Business and Enterprise, in that order.
          items:
            $ref: "#/components/schemas/PublicPlan"
      required: [livemode, quota_period, quota_exceeded, plans]
    PublicPlan:
      type: object
      properties:
        id:
          type: string
          enum: [free, pro, business, enterprise]
        name:
          type: string
        monthly_checks:
          type: integer
          minimum: 1
          nullable: true
          description: Null for Enterprise, which is unlimited under its separate agreement.
        purchase:
          type: string
          enum: [signup, checkout, contact]
          description: signup is a free account without payment details; checkout is Stripe Checkout from the dashboard; contact is a separate agreement, never self-service.
        price:
          $ref: "#/components/schemas/PublicPrice"
      required: [id, name, monthly_checks, purchase, price]
    PublicPrice:
      type: object
      nullable: true
      description: The Stripe price Checkout charges; set exactly for checkout plans, null for the others.
      properties:
        currency:
          type: string
          description: Lowercase ISO 4217 code.
        unit_amount:
          type: integer
          minimum: 1
          description: Amount per interval in the currency's minor unit, e.g. cents.
        interval:
          type: string
          enum: [day, week, month, year]
        interval_count:
          type: integer
          minimum: 1
        tax_behavior:
          type: string
          enum: [inclusive, exclusive, unspecified]
          description: Stripe's tax behavior. unspecified states nothing about VAT; Stripe Checkout shows the final amount.
      required: [currency, unit_amount, interval, interval_count, tax_behavior]
    UsageInfo:
      type: object
      properties:
        reserved:
          type: integer
          minimum: 0
          description: Live pending classification attempts in this UTC month.
        remaining:
          type: integer
          minimum: 0
          description: Capacity after used and reserved checks; zero for unlimited plans.
        limit:
          type: integer
        used:
          type: integer
        percentage:
          type: string
        resets_at:
          type: string
          format: date-time
      required: [reserved, remaining, limit, used, percentage, resets_at]
    UsageResponse:
      type: object
      properties:
        reserved:
          type: integer
          minimum: 0
          description: Live pending classification attempts in this UTC month.
        remaining:
          type: integer
          minimum: 0
          description: Capacity after used and reserved checks; zero for unlimited plans.
        limit:
          type: integer
        used:
          type: integer
        percentage:
          type: string
        resets_at:
          type: string
          format: date-time
        throttled:
          type: boolean
      required: [reserved, remaining, limit, used, percentage, resets_at, throttled]
    UsageHistoryResponse:
      type: object
      properties:
        history:
          type: array
          items:
            $ref: "#/components/schemas/UsageHistoryItem"
      required: [history]
    UsageHistoryItem:
      type: object
      properties:
        month:
          type: string
          format: date-time
        spam_checks:
          type: integer
        spam_detected:
          type: integer
        ham_detected:
          type: integer
        submit_spam:
          type: integer
        submit_ham:
          type: integer
      required: [month, spam_checks, spam_detected, ham_detected, submit_spam, submit_ham]
    SitesResponse:
      type: object
      properties:
        total:
          type: integer
        sites:
          type: array
          items:
            $ref: "#/components/schemas/SiteInfo"
        limit:
          type: integer
        offset:
          type: integer
      required: [sites, total, limit, offset]
    SiteInfo:
      type: object
      properties:
        site:
          type: string
        api_calls:
          type: integer
        spam:
          type: integer
        ham:
          type: integer
        missed_spam:
          type: integer
        false_positives:
          type: integer
        first_seen:
          type: string
          format: date-time
        last_seen:
          type: string
          format: date-time
      required: [site, api_calls, spam, ham, missed_spam, false_positives, first_seen, last_seen]
    DashboardSitesResponse:
      type: object
      properties:
        total:
          type: integer
        sites:
          type: array
          items:
            $ref: "#/components/schemas/DashboardSiteInfo"
        limit:
          type: integer
        offset:
          type: integer
      required: [sites, total, limit, offset]
    DashboardSiteInfo:
      type: object
      properties:
        blog_url:
          type: string
        total_checks:
          type: integer
        total_spam:
          type: integer
        total_ham:
          type: integer
        first_seen_at:
          type: string
          format: date-time
        last_seen_at:
          type: string
          format: date-time
      required: [blog_url, total_checks, total_spam, total_ham, first_seen_at, last_seen_at]
    AccountResponse:
      type: object
      properties:
        user:
          $ref: "#/components/schemas/UserPublic"
      required: [user]
    UserPublic:
      type: object
      properties:
        id:
          type: string
        email:
          type: string
        username:
          type: string
        role:
          type: string
        is_verified:
          type: boolean
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        verified_at:
          type: string
          format: date-time
        last_login_at:
          type: string
          format: date-time
      required: [id, email, username, role, is_verified, created_at, updated_at]
    AccountUpdateRequest:
      type: object
      properties:
        email:
          type: string
        password:
          type: string
          writeOnly: true
      required: [email, password]
    APIKeyCreateRequest:
      type: object
      properties:
        name:
          type: string
      required: [name]
    APIKeyCreateResponse:
      type: object
      properties:
        key:
          type: string
          description: Complete API key, returned only during creation.
        api_key:
          $ref: "#/components/schemas/APIKey"
      required: [key, api_key]
    APIKeyListResponse:
      type: object
      properties:
        keys:
          type: array
          items:
            $ref: "#/components/schemas/APIKey"
      required: [keys]
    APIKey:
      type: object
      properties:
        id:
          type: string
        name:
          type: string
        prefix:
          type: string
        created_at:
          type: string
          format: date-time
        last_used_at:
          type: string
          format: date-time
        revoked_at:
          type: string
          format: date-time
      required: [id, name, prefix, created_at]
    DashboardUsageSummary:
      type: object
      properties:
        reserved:
          type: integer
          minimum: 0
          description: Live pending classification attempts in this UTC month.
        remaining:
          type: integer
          minimum: 0
          description: Capacity after used and reserved checks; zero for unlimited plans.
        plan:
          type: string
        status:
          type: string
        limit:
          type: integer
        used:
          type: integer
        percentage:
          type: string
        resets_at:
          type: string
          format: date-time
      required: [reserved, remaining, plan, status, limit, used, percentage, resets_at]
    BillingSubscription:
      type: object
      properties:
        subscription:
          $ref: "#/components/schemas/SubscriptionInfo"
      required: [subscription]
    SubscriptionInfo:
      type: object
      properties:
        plan:
          type: string
        status:
          type: string
        api_calls_limit:
          type: integer
        current_period_start:
          type: string
          format: date-time
        current_period_end:
          type: string
          format: date-time
        cancel_at:
          type: string
          format: date-time
          description: Scheduled end of an ongoing subscription, which keeps its status until then; absent when no cancellation is scheduled.
        stripe_customer_id:
          type: string
        stripe_subscription_id:
          type: string
      required: [plan, status, api_calls_limit, current_period_start, current_period_end]
    BillingCheckoutRequest:
      type: object
      properties:
        plan:
          type: string
        success_url:
          type: string
          format: uri
          description: Redirect URL on the application's origin.
        cancel_url:
          type: string
          format: uri
          description: Redirect URL on the application's origin.
      required: [plan, success_url, cancel_url]
    BillingCheckoutResponse:
      type: object
      properties:
        url:
          type: string
      required: [url]
    BillingPortalRequest:
      type: object
      properties:
        return_url:
          type: string
          format: uri
          description: Redirect URL on the application's origin.
      required: [return_url]
    BillingPortalResponse:
      type: object
      properties:
        url:
          type: string
      required: [url]
    AuthRegisterRequest:
      type: object
      properties:
        email:
          type: string
        username:
          type: string
        password:
          type: string
      required: [email, username, password]
    AuthLoginRequest:
      type: object
      properties:
        email:
          type: string
        password:
          type: string
      required: [email, password]
    AuthTokenRequest:
      type: object
      properties:
        token:
          type: string
      required: [token]
    AuthForgotRequest:
      type: object
      properties:
        email:
          type: string
      required: [email]
    AuthResetRequest:
      type: object
      properties:
        token:
          type: string
        new_password:
          type: string
          writeOnly: true
      required: [token, new_password]
    AuthResult:
      type: object
      properties:
        user:
          $ref: "#/components/schemas/UserPublic"
        token:
          type: string
          description: Session token for Authorization Bearer authentication.
        session:
          $ref: "#/components/schemas/SessionPublic"
      required: [user, token, session]
    SessionPublic:
      type: object
      properties:
        id:
          type: string
        user_id:
          type: string
        user_agent:
          type: string
        ip:
          type: string
        expires_at:
          type: string
          format: date-time
        created_at:
          type: string
          format: date-time
        revoked:
          type: boolean
      required: [id, user_id, user_agent, ip, expires_at, created_at, revoked]
    AuthMeResponse:
      type: object
      properties:
        user:
          $ref: "#/components/schemas/UserPublic"
        session:
          $ref: "#/components/schemas/SessionPublic"
      required: [user, session]
    AuthForgotResponse:
      type: object
      properties:
        status:
          type: string
          enum: [email_sent]
      required: [status]
    AdminUser:
      type: object
      properties:
        id:
          type: string
        email:
          type: string
        username:
          type: string
        role:
          type: string
        is_verified:
          type: boolean
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        verified_at:
          type: string
          format: date-time
        last_login_at:
          type: string
          format: date-time
        state:
          type: string
          enum:
          - active
          - suspended
          - closed
        version:
          type: integer
      required:
      - id
      - email
      - username
      - role
      - is_verified
      - created_at
      - updated_at
      - state
      - version
    AdminListResponse:
      type: object
      properties:
        users:
          type: array
          items:
            $ref: '#/components/schemas/AdminUser'
        total:
          type: integer
        limit:
          type: integer
        offset:
          type: integer
      required:
      - users
      - total
      - limit
      - offset
    AdminDetailResponse:
      type: object
      properties:
        entitlement:
          $ref: "#/components/schemas/Entitlement"
        user:
          $ref: '#/components/schemas/AdminUser'
        keys:
          type: array
          maxItems: 100
          description: Bounded page of active keys; credential hashes are never selected.
          items:
            $ref: '#/components/schemas/APIKey'
        keys_total:
          type: integer
          minimum: 0
        keys_limit:
          type: integer
          minimum: 1
          maximum: 100
        keys_offset:
          type: integer
          minimum: 0
          maximum: 1000000
        active_sessions:
          type: integer
        usage:
          type: array
          items:
            $ref: '#/components/schemas/UsageHistoryItem'
        subscription:
          $ref: '#/components/schemas/SubscriptionInfo'
        projection_updated_at:
          type: string
          format: date-time
          nullable: true
        effective_plan:
          type: string
        effective_limit:
          type: integer
      required:
      - entitlement
      - user
      - keys
      - keys_total
      - keys_limit
      - keys_offset
      - active_sessions
      - usage
      - subscription
      - projection_updated_at
      - effective_plan
      - effective_limit
    Entitlement:
      type: object
      additionalProperties: false
      properties:
        eligible:
          type: boolean
        account_state:
          type: string
          enum:
          - active
          - suspended
          - closed
        projection_updated_at:
          type: string
          format: date-time
          nullable: true
        subscription_plan:
          type: string
        subscription_limit:
          type: integer
          minimum: 0
          maximum: 2147483647
        ongoing_subscription:
          type: boolean
        complimentary:
          $ref: '#/components/schemas/ComplimentaryEntitlement'
        source:
          type: string
          enum:
          - subscription
          - complimentary
          - admin
        base_limit:
          type: integer
          minimum: 0
          maximum: 2147483647
        api_credits:
          type: integer
          minimum: 0
          maximum: 2147483647
        plan:
          type: string
        status:
          type: string
        limit:
          type: integer
          minimum: 0
          maximum: 2147483647
        unlimited:
          type: boolean
        used:
          type: integer
          minimum: 0
          maximum: 2147483647
        reserved:
          type: integer
          minimum: 0
          maximum: 2147483647
        remaining:
          type: integer
          minimum: 0
          maximum: 2147483647
        month:
          type: string
          format: date-time
        resets_at:
          type: string
          format: date-time
        revision:
          type: string
      required:
      - eligible
      - account_state
      - projection_updated_at
      - subscription_plan
      - subscription_limit
      - ongoing_subscription
      - complimentary
      - source
      - base_limit
      - api_credits
      - plan
      - status
      - limit
      - unlimited
      - used
      - reserved
      - remaining
      - month
      - resets_at
      - revision
      description: 'Shared service entitlement: eligible subscription or Free fallback, then temporary complimentary
        entitlement, then current UTC-month net API credits on finite allowance. Admin accounts have unlimited
        allowance regardless of subscription or grants. Zero retains the unlimited sentinel.
        Finite allowance is capped at 2147483647. Subscription fields describe billing independently of complimentary
        entitlement and credits.'
    AdminAuditEvent:
      type: object
      properties:
        id:
          type: string
        actor_id:
          type: string
        target_id:
          type: string
        action:
          type: string
        reason:
          type: string
        request_id:
          type: string
        before:
          type: object
          additionalProperties: true
          nullable: true
        after:
          type: object
          additionalProperties: true
          nullable: true
        created_at:
          type: string
          format: date-time
      required:
      - id
      - actor_id
      - target_id
      - action
      - reason
      - request_id
      - before
      - after
      - created_at
    AdminAuditResponse:
      type: object
      properties:
        events:
          type: array
          items:
            $ref: '#/components/schemas/AdminAuditEvent'
        limit:
          type: integer
        offset:
          type: integer
        has_more:
          type: boolean
          description: Whether another audit page exists beyond this page.
      required:
      - events
      - limit
      - offset
      - has_more
    AdminInspectedSubscription:
      type: object
      properties:
        id:
          type: string
        status:
          type: string
        cancel_at:
          type: string
          format: date-time
          nullable: true
        plan:
          type: string
        price_id:
          type: string
        period_end:
          type: integer
          description: Unix seconds (UTC).
        pending_until:
          type: integer
          description: Unix seconds (UTC).
        cancel_at_period_end:
          type: boolean
        pending_payment:
          type: boolean
      required:
      - id
      - status
      - cancel_at
    AdminInspectedInvoice:
      type: object
      properties:
        id:
          type: string
        number:
          type: string
        status:
          type: string
        currency:
          type: string
        total:
          type: integer
        amount_paid:
          type: integer
        amount_due:
          type: integer
        created_at:
          type: string
          format: date-time
      required:
      - id
      - number
      - status
      - currency
      - total
      - amount_paid
      - amount_due
      - created_at
    AdminInspection:
      type: object
      properties:
        bound:
          type: boolean
        livemode:
          type: boolean
        subscription:
          type: object
          properties:
            id:
              type: string
            status:
              type: string
            cancel_at:
              type: string
              format: date-time
              nullable: true
            plan:
              type: string
            price_id:
              type: string
            period_end:
              type: integer
              description: Unix seconds (UTC).
            pending_until:
              type: integer
              description: Unix seconds (UTC).
            cancel_at_period_end:
              type: boolean
            pending_payment:
              type: boolean
          required:
          - id
          - status
          - cancel_at
          nullable: true
        invoices:
          type: array
          items:
            $ref: '#/components/schemas/AdminInspectedInvoice'
        has_more:
          type: boolean
        next_cursor:
          type: string
        authority:
          type: string
          enum:
          - shadow
          - bindings
        management_ready:
          type: boolean
        binding_id:
          type: string
        revision:
          type: string
        operations:
          type: array
          maxItems: 25
          items:
            $ref: '#/components/schemas/AdminBillingOperation'
        schedule:
          type: object
          additionalProperties: false
          properties:
            id:
              type: string
            status:
              type: string
            end_behavior:
              type: string
            phases:
              type: array
              items:
                type: object
                properties:
                  starts_at:
                    type: integer
                  ends_at:
                    type: integer
                  plan:
                    type: string
                  price_id:
                    type: string
                required:
                - starts_at
                - ends_at
                - plan
                - price_id
          required:
          - id
          - status
          - end_behavior
          - phases
      required:
      - bound
      - livemode
      - subscription
      - invoices
      - has_more
      - next_cursor
      - management_ready
    AdminError:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
          required:
          - code
          - message
      required:
      - error
    AdminActionRequest:
      oneOf:
      - $ref: '#/components/schemas/AdminUsernameAction'
      - $ref: '#/components/schemas/AdminSimpleAction'
      - $ref: '#/components/schemas/AdminRevokeKeyAction'
      - $ref: '#/components/schemas/AdminRoleAction'
      - $ref: '#/components/schemas/AdminCloseAction'
      discriminator:
        propertyName: action
        mapping:
          username: '#/components/schemas/AdminUsernameAction'
          suspend: '#/components/schemas/AdminSimpleAction'
          restore: '#/components/schemas/AdminSimpleAction'
          revoke_sessions: '#/components/schemas/AdminSimpleAction'
          password_reset: '#/components/schemas/AdminSimpleAction'
          revoke_key: '#/components/schemas/AdminRevokeKeyAction'
          role: '#/components/schemas/AdminRoleAction'
          close: '#/components/schemas/AdminCloseAction'
    AdminActionVersion:
      type: integer
      minimum: 1
    AdminActionReason:
      type: string
      minLength: 3
      maxLength: 500
      description: 3–500 Unicode code points, with at least 3 after trimming surrounding whitespace.
    AdminActionRole:
      type: string
      enum:
      - user
      - admin
    AdminUsernameAction:
      type: object
      additionalProperties: false
      properties:
        action:
          type: string
          enum:
          - username
        expected_version:
          $ref: '#/components/schemas/AdminActionVersion'
        reason:
          $ref: '#/components/schemas/AdminActionReason'
        username:
          type: string
          minLength: 3
          maxLength: 30
      required:
      - action
      - expected_version
      - reason
      - username
    AdminSimpleAction:
      type: object
      additionalProperties: false
      properties:
        action:
          type: string
          enum:
          - suspend
          - restore
          - revoke_sessions
          - password_reset
        expected_version:
          $ref: '#/components/schemas/AdminActionVersion'
        reason:
          $ref: '#/components/schemas/AdminActionReason'
      required:
      - action
      - expected_version
      - reason
    AdminRevokeKeyAction:
      type: object
      additionalProperties: false
      properties:
        action:
          type: string
          enum:
          - revoke_key
        expected_version:
          $ref: '#/components/schemas/AdminActionVersion'
        reason:
          $ref: '#/components/schemas/AdminActionReason'
        key_id:
          type: string
          format: uuid
      required:
      - action
      - expected_version
      - reason
      - key_id
    AdminRoleAction:
      type: object
      additionalProperties: false
      properties:
        action:
          type: string
          enum:
          - role
        expected_version:
          $ref: '#/components/schemas/AdminActionVersion'
        reason:
          $ref: '#/components/schemas/AdminActionReason'
        role:
          $ref: '#/components/schemas/AdminActionRole'
        proof:
          type: string
          format: uuid
          writeOnly: true
      required:
      - action
      - expected_version
      - reason
      - role
      - proof
    AdminRoleIntent:
      type: object
      additionalProperties: false
      properties:
        action:
          type: string
          enum:
          - role
        expected_version:
          $ref: '#/components/schemas/AdminActionVersion'
        reason:
          $ref: '#/components/schemas/AdminActionReason'
        role:
          $ref: '#/components/schemas/AdminActionRole'
      required:
      - action
      - expected_version
      - reason
      - role
    AdminCloseIntent:
      type: object
      additionalProperties: false
      properties:
        action:
          type: string
          enum: [close]
        expected_version:
          $ref: '#/components/schemas/AdminActionVersion'
        reason:
          $ref: '#/components/schemas/AdminActionReason'
      required: [action, expected_version, reason]
    AdminCloseAction:
      type: object
      additionalProperties: false
      properties:
        action:
          type: string
          enum: [close]
        expected_version:
          $ref: '#/components/schemas/AdminActionVersion'
        reason:
          $ref: '#/components/schemas/AdminActionReason'
        proof:
          type: string
          format: uuid
          writeOnly: true
      required: [action, expected_version, reason, proof]
    AdminActionResult:
      type: object
      properties:
        status:
          type: string
          enum:
          - applied
          - request_accepted
        user:
          $ref: '#/components/schemas/AdminUser'
      required:
      - status
      - user
    AdminReauthRequest:
      type: object
      additionalProperties: false
      properties:
        password:
          type: string
          writeOnly: true
          minLength: 1
          maxLength: 1024
        intent:
          oneOf:
          - $ref: '#/components/schemas/AdminRoleIntent'
          - $ref: '#/components/schemas/AdminCloseIntent'
          discriminator:
            propertyName: action
            mapping:
              role: '#/components/schemas/AdminRoleIntent'
              close: '#/components/schemas/AdminCloseIntent'
      required:
      - password
      - intent
    AdminReauthResult:
      type: object
      properties:
        proof:
          type: string
          format: uuid
        expires_at:
          type: string
          format: date-time
      required:
      - proof
      - expires_at
    ComplimentaryEntitlement:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
        command_id:
          type: string
          format: uuid
        user_id:
          type: string
          format: uuid
        actor_id:
          type: string
        plan:
          type: string
          enum:
          - free
          - pro
          - business
          - enterprise
          - custom
        limit:
          type: integer
          minimum: 0
          maximum: 2147483647
        version:
          type: integer
          minimum: 1
        starts_at:
          type: string
          format: date-time
        expires_at:
          type: string
          format: date-time
        reason:
          type: string
        created_at:
          type: string
          format: date-time
        ended_at:
          type: string
          format: date-time
          nullable: true
        ended_by:
          type: string
        end_reason:
          type: string
        end_kind:
          type: string
      required:
      - id
      - command_id
      - user_id
      - actor_id
      - plan
      - limit
      - version
      - starts_at
      - expires_at
      - reason
      - created_at
      - ended_at
      - ended_by
      - end_reason
      - end_kind
      nullable: true
    QuotaAdjustment:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
        command_id:
          type: string
          format: uuid
        user_id:
          type: string
          format: uuid
        actor_id:
          type: string
        month:
          type: string
          format: date-time
        amount:
          type: integer
          minimum: -2147483647
          maximum: 2147483647
          description: 'Nonzero signed append-only entry: positive grant or negative reversal.'
        reversal_of:
          type: string
          format: uuid
          nullable: true
        reversed:
          type: integer
          minimum: 0
          maximum: 2147483647
        reason:
          type: string
        created_at:
          type: string
          format: date-time
      required:
      - id
      - command_id
      - user_id
      - actor_id
      - month
      - amount
      - reversal_of
      - reversed
      - reason
      - created_at
    AdminEntitlementHistory:
      type: object
      additionalProperties: false
      properties:
        credits:
          type: array
          items:
            $ref: '#/components/schemas/QuotaAdjustment'
          maxItems: 100
        credits_has_more:
          type: boolean
        overrides:
          type: array
          items:
            $ref: '#/components/schemas/ComplimentaryEntitlement'
          maxItems: 100
        overrides_has_more:
          type: boolean
        limit:
          type: integer
          minimum: 1
          maximum: 100
        credits_offset:
          type: integer
          minimum: 0
        overrides_offset:
          type: integer
          minimum: 0
      required:
      - credits
      - credits_has_more
      - overrides
      - overrides_has_more
      - limit
      - credits_offset
      - overrides_offset
    AdminEntitlementRequest:
      oneOf:
      - $ref: '#/components/schemas/AdminCreditGrant'
      - $ref: '#/components/schemas/AdminCreditReverse'
      - $ref: '#/components/schemas/AdminComplimentaryGrant'
      - $ref: '#/components/schemas/AdminComplimentaryRevoke'
      discriminator:
        propertyName: action
        mapping:
          credit_grant: '#/components/schemas/AdminCreditGrant'
          credit_reverse: '#/components/schemas/AdminCreditReverse'
          complimentary_grant: '#/components/schemas/AdminComplimentaryGrant'
          complimentary_revoke: '#/components/schemas/AdminComplimentaryRevoke'
    AdminCreditGrant:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        month:
          type: string
          pattern: ^\d{4}-(0[1-9]|1[0-2])$
          description: Reviewed UTC month (YYYY-MM). Must equal the database current month for a new command; never
            rolls over.
        amount:
          type: integer
          minimum: 1
          maximum: 2147483647
        action:
          type: string
          enum:
          - credit_grant
      required:
      - command_id
      - expected_version
      - reason
      - month
      - amount
      - action
    AdminCreditReverse:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        month:
          type: string
          pattern: ^\d{4}-(0[1-9]|1[0-2])$
          description: Reviewed UTC month (YYYY-MM). Must equal the database current month for a new command; never
            rolls over.
        amount:
          type: integer
          minimum: 1
          maximum: 2147483647
        action:
          type: string
          enum:
          - credit_reverse
        grant_id:
          type: string
          format: uuid
      required:
      - command_id
      - expected_version
      - reason
      - month
      - amount
      - action
      - grant_id
    AdminComplimentaryGrant:
      oneOf:
      - $ref: '#/components/schemas/AdminComplimentaryPlanGrant'
      - $ref: '#/components/schemas/AdminComplimentaryCustomGrant'
    AdminComplimentaryPlanGrant:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        starts_at:
          type: string
          format: date-time
        expires_at:
          type: string
          format: date-time
          description: Required exclusive expiry after start. A past start is clamped to database now; expiry must remain
            in the future.
        unlimited:
          type: boolean
          description: Must explicitly be true for Enterprise or a custom zero/unlimited limit; false or omitted for
            finite plans.
        action:
          type: string
          enum:
          - complimentary_grant
        plan:
          type: string
          enum:
          - free
          - pro
          - business
          - enterprise
      required:
      - command_id
      - expected_version
      - reason
      - action
      - plan
      - starts_at
      - expires_at
    AdminComplimentaryCustomGrant:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        starts_at:
          type: string
          format: date-time
        expires_at:
          type: string
          format: date-time
          description: Required exclusive expiry after start. A past start is clamped to database now; expiry must remain
            in the future.
        unlimited:
          type: boolean
          description: Must explicitly be true for Enterprise or a custom zero/unlimited limit; false or omitted for
            finite plans.
        action:
          type: string
          enum:
          - complimentary_grant
        plan:
          type: string
          enum:
          - custom
        limit:
          type: integer
          minimum: 0
          maximum: 2147483647
      required:
      - command_id
      - expected_version
      - reason
      - action
      - plan
      - limit
      - starts_at
      - expires_at
    AdminComplimentaryRevoke:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        action:
          type: string
          enum:
          - complimentary_revoke
        override_id:
          type: string
          format: uuid
        override_version:
          type: integer
          minimum: 1
      required:
      - command_id
      - expected_version
      - reason
      - action
      - override_id
      - override_version
    AdminEntitlementResult:
      type: object
      additionalProperties: false
      properties:
        status:
          type: string
          enum:
          - applied
        replayed:
          type: boolean
        command_id:
          type: string
          format: uuid
        result_id:
          type: string
          format: uuid
        applied_version:
          type: integer
          minimum: 1
        user:
          $ref: '#/components/schemas/AdminUser'
      required:
      - status
      - replayed
      - command_id
      - result_id
      - applied_version
      - user
    AdminBillingPreview:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
        plan:
          type: string
        revision:
          type: string
        after_release_revision:
          type: string
        customer_id:
          type: string
        subscription_id:
          type: string
        schedule_id:
          type: string
        item_id:
          type: string
        price_id:
          type: string
        previous_price_id:
          type: string
        currency:
          type: string
        effect:
          type: string
        action:
          type: string
          enum:
          - checkout
          - upgrade
          - downgrade
          - cancel_period_end
          - undo_cancel
          - cancel_now
          - discard_schedule
          - reconcile
          - refund
          - billing_credit
        period_start:
          type: integer
        period_end:
          type: integer
        proration_date:
          type: integer
        effective_at:
          type: integer
        amount_due:
          type: integer
        tax:
          type: integer
        proration:
          type: integer
        allowance:
          type: integer
        expires_at:
          type: integer
          description: Exclusive UTC expiry in Unix microseconds. Amounts use currency minor units; period/effective/proration
            dates use Unix seconds.
        financial:
          $ref: '#/components/schemas/AdminFinancialPreview'
        financial_results:
          type: array
          items:
            $ref: '#/components/schemas/AdminFinancialResult'
        refund_writes_stopped:
          type: boolean
      required:
      - id
      - plan
      - revision
      - after_release_revision
      - customer_id
      - subscription_id
      - schedule_id
      - item_id
      - price_id
      - previous_price_id
      - currency
      - effect
      - action
      - period_start
      - period_end
      - proration_date
      - effective_at
      - amount_due
      - tax
      - proration
      - allowance
      - expires_at
    AdminBillingOperation:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
        user_id:
          type: string
        actor_id:
          type: string
        binding_id:
          type: string
        reason:
          type: string
        step:
          type: string
        customer_id:
          type: string
        subscription_id:
          type: string
        schedule_id:
          type: string
        checkout_id:
          type: string
        error_code:
          type: string
        action:
          type: string
          enum:
          - checkout
          - upgrade
          - downgrade
          - cancel_period_end
          - undo_cancel
          - cancel_now
          - discard_schedule
          - reconcile
          - refund
          - billing_credit
        state:
          type: string
          enum:
          - queued
          - executing
          - needs_reconciliation
          - pending
          - succeeded
          - failed
          - paused
          - manual_review
        customer_initiated:
          type: boolean
        version:
          type: integer
        attempts:
          type: integer
          description: Attempts since the write boundary, last confirmed pending observation or step transition.
        created_at:
          type: integer
        updated_at:
          type: integer
        step_started_at:
          type: integer
        pending_until:
          type: integer
        next_run_at:
          type: integer
        checkout_url:
          type: string
          format: uri
          description: Ephemeral customer Checkout URL, retrieved on an authorized operation read; never stored
            in audit.
        financial:
          $ref: '#/components/schemas/AdminFinancialPreview'
        results:
          type: array
          items:
            $ref: '#/components/schemas/AdminFinancialResult'
      required:
      - id
      - user_id
      - actor_id
      - binding_id
      - reason
      - step
      - customer_id
      - subscription_id
      - schedule_id
      - checkout_id
      - error_code
      - action
      - state
      - customer_initiated
      - version
      - attempts
      - created_at
      - updated_at
      - step_started_at
      - pending_until
      - next_run_at
    AdminBillingCheckoutIntent:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - checkout
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
    AdminBillingCheckoutCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - checkout
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
        proof:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
      - proof
    AdminBillingUpgradeIntent:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - upgrade
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
    AdminBillingUpgradeCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - upgrade
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
        proof:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
      - proof
    AdminBillingDowngradeIntent:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - downgrade
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
    AdminBillingDowngradeCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - downgrade
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
        proof:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
      - proof
    AdminBillingCancelPeriodEndIntent:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - cancel_period_end
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
    AdminBillingCancelPeriodEndCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - cancel_period_end
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
        proof:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
      - proof
    AdminBillingUndoCancelIntent:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - undo_cancel
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
    AdminBillingUndoCancelCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - undo_cancel
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
        proof:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
      - proof
    AdminBillingCancelNowIntent:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - cancel_now
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
        confirm_immediate:
          type: boolean
          enum:
          - true
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
      - confirm_immediate
    AdminBillingCancelNowCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - cancel_now
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
        confirm_immediate:
          type: boolean
          enum:
          - true
        proof:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
      - confirm_immediate
      - proof
    AdminBillingDiscardScheduleIntent:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - discard_schedule
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
    AdminBillingDiscardScheduleCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - discard_schedule
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
        proof:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
      - proof
    AdminBillingReconcileCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - reconcile
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
      required:
      - command_id
      - action
      - expected_version
      - reason
    AdminBillingCommand:
      oneOf:
      - $ref: '#/components/schemas/AdminBillingCheckoutCommand'
      - $ref: '#/components/schemas/AdminBillingUpgradeCommand'
      - $ref: '#/components/schemas/AdminBillingDowngradeCommand'
      - $ref: '#/components/schemas/AdminBillingCancelPeriodEndCommand'
      - $ref: '#/components/schemas/AdminBillingUndoCancelCommand'
      - $ref: '#/components/schemas/AdminBillingCancelNowCommand'
      - $ref: '#/components/schemas/AdminBillingDiscardScheduleCommand'
      - $ref: '#/components/schemas/AdminBillingReconcileCommand'
      - $ref: '#/components/schemas/AdminBillingRefundCommand'
      - $ref: '#/components/schemas/AdminBillingCreditCommand'
    AdminBillingPreviewRequest:
      oneOf:
      - type: object
        additionalProperties: false
        properties:
          action:
            type: string
            enum:
            - checkout
          plan:
            type: string
            enum:
            - pro
            - business
        required:
        - action
        - plan
      - type: object
        additionalProperties: false
        properties:
          action:
            type: string
            enum:
            - upgrade
          plan:
            type: string
            enum:
            - pro
            - business
        required:
        - action
        - plan
      - type: object
        additionalProperties: false
        properties:
          action:
            type: string
            enum:
            - downgrade
          plan:
            type: string
            enum:
            - pro
            - business
        required:
        - action
        - plan
      - type: object
        additionalProperties: false
        properties:
          action:
            type: string
            enum:
            - cancel_period_end
        required:
        - action
      - type: object
        additionalProperties: false
        properties:
          action:
            type: string
            enum:
            - undo_cancel
        required:
        - action
      - type: object
        additionalProperties: false
        properties:
          action:
            type: string
            enum:
            - cancel_now
        required:
        - action
      - type: object
        additionalProperties: false
        properties:
          action:
            type: string
            enum:
            - discard_schedule
        required:
        - action
      - type: object
        additionalProperties: false
        properties:
          action:
            type: string
            enum:
            - refund
          invoice_id:
            type: string
            pattern: ^in_
            maxLength: 255
          refund_mode:
            type: string
            enum:
            - full
        required:
        - action
        - invoice_id
        - refund_mode
      - type: object
        additionalProperties: false
        properties:
          action:
            type: string
            enum:
            - refund
          invoice_id:
            type: string
            pattern: ^in_
            maxLength: 255
          refund_mode:
            type: string
            enum:
            - partial
          amount:
            type: integer
            minimum: 1
            maximum: 99999999
        required:
        - action
        - invoice_id
        - refund_mode
        - amount
      - type: object
        additionalProperties: false
        properties:
          action:
            type: string
            enum:
            - billing_credit
          amount:
            type: integer
            minimum: 1
            maximum: 99999999
          currency:
            type: string
            pattern: ^[a-z]{3}$
            minLength: 3
            maxLength: 3
        required:
        - action
        - amount
        - currency
    AdminBillingReauthRequest:
      type: object
      additionalProperties: false
      properties:
        password:
          type: string
          minLength: 1
          maxLength: 1024
        intent:
          oneOf:
          - $ref: '#/components/schemas/AdminBillingCheckoutIntent'
          - $ref: '#/components/schemas/AdminBillingUpgradeIntent'
          - $ref: '#/components/schemas/AdminBillingDowngradeIntent'
          - $ref: '#/components/schemas/AdminBillingCancelPeriodEndIntent'
          - $ref: '#/components/schemas/AdminBillingUndoCancelIntent'
          - $ref: '#/components/schemas/AdminBillingCancelNowIntent'
          - $ref: '#/components/schemas/AdminBillingDiscardScheduleIntent'
          - $ref: '#/components/schemas/AdminBillingRefundIntent'
          - $ref: '#/components/schemas/AdminBillingCreditIntent'
      required:
      - password
      - intent
    AdminFinancialResult:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
        kind:
          type: string
        charge_id:
          type: string
        payment_intent_id:
          type: string
        amount:
          type: integer
        currency:
          type: string
        status:
          type: string
        failure_reason:
          type: string
        created_at:
          type: integer
          description: Observed Stripe receipt timestamp in Unix seconds. Refund status can change after success.
      required:
      - id
      - kind
      - charge_id
      - payment_intent_id
      - amount
      - currency
      - status
      - failure_reason
      - created_at
    AdminRefundPayment:
      type: object
      additionalProperties: false
      properties:
        charge_id:
          type: string
        payment_intent_id:
          type: string
        invoice_payment_ids:
          type: array
          items:
            type: string
        paid:
          type: integer
        captured:
          type: integer
        refundable:
          type: integer
        amount:
          type: integer
        revision:
          type: string
        refunds:
          type: array
          items:
            $ref: '#/components/schemas/AdminFinancialResult'
      required:
      - charge_id
      - payment_intent_id
      - invoice_payment_ids
      - paid
      - captured
      - refundable
      - amount
      - revision
      - refunds
    AdminFinancialPreview:
      type: object
      additionalProperties: false
      properties:
        invoice_id:
          type: string
        invoice_revision:
          type: string
        refund_mode:
          type: string
        currency:
          type: string
        amount:
          type: integer
        refundable:
          type: integer
        tax:
          type: integer
        balance_before:
          type: integer
        payments:
          type: array
          items:
            $ref: '#/components/schemas/AdminRefundPayment'
      required:
      - invoice_id
      - invoice_revision
      - refund_mode
      - currency
      - amount
      - refundable
      - tax
      - balance_before
      - payments
      description: Reviewed integer currency minor units. Refunds return gross captured money without modifying
        invoice tax or subscription access; credits adjust future invoice balance.
    AdminBillingCreditEntry:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
        amount:
          type: integer
        currency:
          type: string
        ending_balance:
          type: integer
        type:
          type: string
        reason:
          type: string
        invoice_id:
          type: string
        operation_id:
          type: string
        created_at:
          type: integer
      required:
      - id
      - amount
      - currency
      - ending_balance
      - type
      - reason
      - invoice_id
      - operation_id
      - created_at
    AdminBillingCreditHistory:
      type: object
      additionalProperties: false
      properties:
        customer_id:
          type: string
        currency:
          type: string
        balance:
          type: integer
        entries:
          type: array
          items:
            $ref: '#/components/schemas/AdminBillingCreditEntry'
        has_more:
          type: boolean
        next_cursor:
          type: string
        reversal_supported:
          type: boolean
          description: 'Always false: an opposite adjustment can race consumption and create debt.'
        reversal_reason:
          type: string
      required:
      - customer_id
      - currency
      - balance
      - entries
      - has_more
      - next_cursor
      - reversal_supported
      - reversal_reason
    AdminBillingRefundIntent:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - refund
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
    AdminBillingRefundCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - refund
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 500
        preview_id:
          type: string
          format: uuid
        proof:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
      - proof
    AdminBillingCreditIntent:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - billing_credit
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 350
        preview_id:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
    AdminBillingCreditCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        action:
          type: string
          enum:
          - billing_credit
        expected_version:
          type: integer
          minimum: 1
        reason:
          type: string
          minLength: 3
          maxLength: 350
        preview_id:
          type: string
          format: uuid
        proof:
          type: string
          format: uuid
      required:
      - command_id
      - action
      - expected_version
      - reason
      - preview_id
      - proof
    AdminDeletionIntent:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        expected_version:
          $ref: '#/components/schemas/AdminActionVersion'
        generation:
          type: string
          format: uuid
        reason:
          $ref: '#/components/schemas/AdminActionReason'
        review_version:
          type: integer
          minimum: 1
          description: Existing operation version when explicitly renewing consent
      required: [command_id, expected_version, generation, reason]
    AdminDeletionCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        expected_version:
          $ref: '#/components/schemas/AdminActionVersion'
        generation:
          type: string
          format: uuid
        reason:
          $ref: '#/components/schemas/AdminActionReason'
        proof:
          type: string
          format: uuid
          writeOnly: true
      required: [command_id, expected_version, generation, reason, proof]
    AdminDeletionReviewCommand:
      type: object
      additionalProperties: false
      properties:
        command_id:
          type: string
          format: uuid
        expected_version:
          $ref: '#/components/schemas/AdminActionVersion'
        generation:
          type: string
          format: uuid
        reason:
          $ref: '#/components/schemas/AdminActionReason'
        proof:
          type: string
          format: uuid
          writeOnly: true
        review_version:
          type: integer
          minimum: 1
      required: [command_id, expected_version, generation, reason, proof, review_version]
    AdminDeletionReauthRequest:
      type: object
      additionalProperties: false
      properties:
        password:
          type: string
          writeOnly: true
          minLength: 1
          maxLength: 1024
        intent:
          $ref: '#/components/schemas/AdminDeletionIntent'
      required: [password, intent]
    AdminRetentionPolicy:
      type: object
      additionalProperties: false
      properties:
        id:
          type: string
        financial_days:
          type: integer
          minimum: 0
        audit_days:
          type: integer
          minimum: 0
        backup_days:
          type: integer
          minimum: 0
        log_days:
          type: integer
          minimum: 0
      required: [id, financial_days, audit_days, backup_days, log_days]
    AdminClosure:
      type: object
      additionalProperties: false
      nullable: true
      properties:
        user_id:
          type: string
          format: uuid
        generation:
          type: string
          format: uuid
        closed_at:
          type: integer
          description: UTC Unix microseconds
        eligible_at:
          type: integer
          description: Earliest erasure, 30 days after closure; UTC Unix microseconds
      required: [user_id, generation, closed_at, eligible_at]
    AdminDeletion:
      type: object
      nullable: true
      additionalProperties: false
      properties:
        id:
          type: string
          format: uuid
        user_id:
          type: string
          format: uuid
        generation:
          type: string
          format: uuid
        state:
          type: string
          enum: [waiting, blocked, erasing, completed]
        stage:
          type: string
        version:
          type: integer
          minimum: 1
        attempts:
          type: integer
          minimum: 0
        error_code:
          type: string
        next_run_at:
          type: integer
        created_at:
          type: integer
        started_at:
          type: integer
        completed_at:
          type: integer
        policy:
          $ref: '#/components/schemas/AdminRetentionPolicy'
      required: [id, user_id, generation, state, stage, version, attempts, error_code, next_run_at, created_at, started_at, completed_at, policy]
    AdminDeletionPreview:
      type: object
      additionalProperties: false
      properties:
        policy_configured:
          type: boolean
        policy:
          $ref: '#/components/schemas/AdminRetentionPolicy'
        closure:
          $ref: '#/components/schemas/AdminClosure'
        operation:
          $ref: '#/components/schemas/AdminDeletion'
        eligible:
          type: boolean
        blockers:
          type: array
          items:
            type: string
        inventory:
          type: object
          additionalProperties: true
          description: Counts of each explicitly erased data family; no personal records
      required: [policy_configured, policy, closure, operation, eligible, blockers, inventory]
