{
  "openapi": "3.1.0",
  "info": {
    "title": "PolicyGrain & CheckMyDPDP API",
    "version": "0.9.3",
    "description": "The OpenAPI 3.1.0 specification GET /v1/openapi.json serves: identity, documents, sites, evidence, usage, scanner, verify, billing, rights, and status."
  },
  "servers": [
    {
      "url": "https://api.policygrain.com",
      "description": "Production API (AWS Mumbai ap-south-1)"
    },
    {
      "url": "https://staging.policygrain.com",
      "description": "Staging API"
    }
  ],
  "tags": [
    {
      "name": "meta",
      "description": "Health, operational status, and API discovery"
    },
    {
      "name": "rights",
      "description": "Public DPDP Act ss.11-14 & Rules 2025 Rule 14 Data Principal rights and grievance intake"
    },
    {
      "name": "identity",
      "description": "Accounts, API keys, and sessions"
    },
    {
      "name": "documents"
    },
    {
      "name": "sites"
    },
    {
      "name": "evidence"
    },
    {
      "name": "usage"
    },
    {
      "name": "scans"
    },
    {
      "name": "verify",
      "description": "Live site verification and drift monitoring on verified domains"
    },
    {
      "name": "billing",
      "description": "Plans, Razorpay subscriptions, entitlements, GST tax invoices, and signed webhooks"
    }
  ],
  "paths": {
    "/healthz": {
      "get": {
        "tags": [
          "meta"
        ],
        "operationId": "getHealth",
        "summary": "Liveness and optional ?deep=1 database migration readiness check",
        "security": [],
        "parameters": [
          {
            "name": "deep",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "1"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Healthy"
          },
          "503": {
            "description": "Unhealthy database or pending migrations"
          }
        }
      }
    },
    "/v1/status": {
      "get": {
        "tags": [
          "meta"
        ],
        "operationId": "getOperationalStatus",
        "summary": "Public operational status for /status and /trust pages (zero secrets)",
        "security": [],
        "responses": {
          "200": {
            "description": "Operational subsystem status",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OperationalStatus"
                }
              }
            }
          },
          "503": {
            "description": "Degraded database or pending migrations",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OperationalStatus"
                }
              }
            }
          }
        }
      }
    },
    "/v1/openapi.json": {
      "get": {
        "tags": [
          "meta"
        ],
        "operationId": "getOpenApiSpec",
        "summary": "Merged OpenAPI 3.1.0 specification for all mounted PolicyGrain API routes",
        "security": [],
        "responses": {
          "200": {
            "description": "OpenAPI 3.1.0 JSON document"
          }
        }
      }
    },
    "/v1/public/sites/{siteId}/rights-form": {
      "get": {
        "tags": [
          "rights"
        ],
        "operationId": "getSiteRightsForm",
        "summary": "Render zero-JS progressive-enhancement DPDP Rights & Grievance HTML form",
        "security": [],
        "parameters": [
          {
            "name": "siteId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Accessible HTML rights & grievance request form"
          },
          "404": {
            "description": "Site not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/public/sites/{siteId}/rights-requests": {
      "post": {
        "tags": [
          "rights"
        ],
        "operationId": "submitSiteRightsRequest",
        "summary": "Submit a DPDP Act ss.11-14 rights or grievance request and receive a Rule 14 receipt",
        "security": [],
        "parameters": [
          {
            "name": "siteId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RightsRequestInput"
              }
            },
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/RightsRequestInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Acknowledgement receipt with Rule 14 deadline and SHA-256 digest",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RightsReceipt"
                }
              }
            }
          },
          "400": {
            "description": "Validation error or rejected honeypot",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing or invalid form CSRF token",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Site not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys": {
      "post": {
        "tags": [
          "identity"
        ],
        "operationId": "createApiKey",
        "summary": "Issue a new API key (public email signup or authenticated scoped key)",
        "security": [],
        "responses": {
          "200": {
            "description": "Agent email signup result (key returned once for a new email)"
          },
          "201": {
            "description": "Issued API key (plaintext shown once)"
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "Rate limited",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "identity"
        ],
        "operationId": "listApiKeys",
        "summary": "List this account's API keys (requires keys scope)",
        "responses": {
          "200": {
            "description": "Active and revoked API keys (without secrets)"
          }
        }
      }
    },
    "/v1/keys/{id}": {
      "delete": {
        "tags": [
          "identity"
        ],
        "operationId": "revokeApiKey",
        "summary": "Revoke one API key (requires keys scope)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Revoked"
          },
          "404": {
            "description": "Not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/keys/{id}/keep": {
      "post": {
        "tags": [
          "identity"
        ],
        "operationId": "keepApiKey",
        "summary": "Confirm ownership of an unverified agent-requested API key",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Confirmed"
          }
        }
      }
    },
    "/v1/account": {
      "get": {
        "tags": [
          "identity"
        ],
        "operationId": "getAccount",
        "summary": "Read the authenticated account summary",
        "responses": {
          "200": {
            "description": "Account details"
          }
        }
      },
      "delete": {
        "tags": [
          "identity"
        ],
        "operationId": "deleteAccount",
        "summary": "Unpublish and purge hosted pages, then permanently delete the authenticated account",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "confirm_email": {
                    "type": "string",
                    "format": "email"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Published pages purged and account deleted"
          },
          "400": {
            "description": "Confirmation email mismatch or invalid body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing keys scope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Hosted page deletion or CDN purge failed; account was not deleted",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/sign-in": {
      "get": {
        "tags": [
          "identity"
        ],
        "operationId": "beginSignIn",
        "summary": "Begin browser sign-in flow when WorkOS is configured",
        "security": [],
        "responses": {
          "302": {
            "description": "Redirect to identity provider"
          },
          "503": {
            "description": "Sign-in not configured"
          }
        }
      }
    },
    "/v1/auth/code": {
      "post": {
        "tags": [
          "identity"
        ],
        "operationId": "exchangeSignInCode",
        "summary": "Exchange a sign-in code for a session",
        "security": [],
        "responses": {
          "200": {
            "description": "Session issued"
          },
          "503": {
            "description": "Sign-in not configured"
          }
        }
      }
    },
    "/v1/auth/refresh": {
      "post": {
        "tags": [
          "identity"
        ],
        "operationId": "refreshSession",
        "summary": "Rotate the browser refresh session",
        "security": [],
        "responses": {
          "200": {
            "description": "Refreshed session"
          }
        }
      },
      "delete": {
        "tags": [
          "identity"
        ],
        "operationId": "signOut",
        "summary": "Revoke the browser refresh session",
        "security": [],
        "responses": {
          "204": {
            "description": "Signed out"
          }
        }
      }
    },
    "/v1/questions": {
      "get": {
        "tags": [
          "documents"
        ],
        "operationId": "getQuestions",
        "summary": "The questionnaire as data",
        "security": [
          {}
        ],
        "parameters": [
          {
            "name": "tier",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "1",
                "2"
              ]
            }
          },
          {
            "name": "document",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "A document type from `documents[].id`: only the questions that change it and the fields it prints (plus the required fields)."
          }
        ],
        "responses": {
          "200": {
            "description": "The questionnaire",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Questionnaire"
                }
              }
            }
          },
          "400": {
            "description": "invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles": {
      "post": {
        "tags": [
          "documents"
        ],
        "operationId": "createProfile",
        "summary": "Create a profile: answers stored once, used in every document",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255,
              "pattern": "^[\\x21-\\x7e]+$"
            },
            "description": "Retry safely: the same key and body replay the stored response for 24 hours (header `Idempotent-Replayed: true`); the same key with another body is 409. Keys are per account."
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProfileInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "400": {
            "description": "invalid_body, invalid_answers (with problems), field_too_long, unknown_document, not_for_document, nothing_to_confirm, invalid_idempotency_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "conflict (two answers contradict), idempotency_key_reused, idempotency_in_progress",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large (64 KB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "documents"
        ],
        "operationId": "listProfiles",
        "summary": "This account's profiles, oldest first",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "The profiles",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProfileList"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/profiles/{id}": {
      "get": {
        "tags": [
          "documents"
        ],
        "operationId": "getProfile",
        "summary": "One profile",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The profile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "profile_not_found (also another account's profile)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "documents"
        ],
        "operationId": "updateProfile",
        "summary": "Merge answers into a profile; null removes one; confirm inferred values (people only)",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ProfileInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Profile"
                }
              }
            }
          },
          "400": {
            "description": "invalid_body, invalid_answers (with problems), field_too_long, unknown_document, not_for_document, nothing_to_confirm, invalid_idempotency_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope, key_suspended, confirm_needs_person",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "profile_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "conflict, profile_busy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large (64 KB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/generations": {
      "post": {
        "tags": [
          "documents"
        ],
        "operationId": "createGeneration",
        "summary": "Generate a profile's documents (a job: 202, then poll)",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255,
              "pattern": "^[\\x21-\\x7e]+$"
            },
            "description": "Retry safely: the same key and body replay the stored response for 24 hours (header `Idempotent-Replayed: true`); the same key with another body is 409. Keys are per account."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/GenerationInput"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Queued. Poll the Location every poll_after_ms.",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              },
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generation"
                }
              }
            }
          },
          "400": {
            "description": "invalid_body, unknown_document, invalid_idempotency_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "profile_not_found (field profile_id)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "idempotency_key_reused, idempotency_in_progress",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large (8 KB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/generations/{id}": {
      "get": {
        "tags": [
          "documents"
        ],
        "operationId": "getGeneration",
        "summary": "Poll a generation",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The job; Retry-After while it runs",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Generation"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "generation_not_found (also another account's)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/documents": {
      "get": {
        "tags": [
          "documents"
        ],
        "operationId": "listDocuments",
        "summary": "Every document type of a profile",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "profile_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The documents",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentList"
                }
              }
            }
          },
          "400": {
            "description": "invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "profile_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/documents/{id}": {
      "get": {
        "tags": [
          "documents"
        ],
        "operationId": "getDocument",
        "summary": "One document and its versions",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The document",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Document"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "document_not_found (also another account's)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/documents/{id}/versions/{n}": {
      "get": {
        "tags": [
          "documents"
        ],
        "operationId": "getDocumentVersion",
        "summary": "One version, by number or latest",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "n",
            "in": "path",
            "required": true,
            "schema": {
              "oneOf": [
                {
                  "type": "integer",
                  "minimum": 1
                },
                {
                  "type": "string",
                  "enum": [
                    "latest"
                  ]
                }
              ]
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "html",
                "md",
                "docx",
                "pdf"
              ],
              "default": "json"
            },
            "description": "docx and pdf answer 400 format_not_available until their emitters ship (plan T-11)"
          }
        ],
        "responses": {
          "200": {
            "description": "The version. ETag is its content hash; X-Document-Version its number.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/DocumentVersion"
                }
              },
              "text/html": {
                "schema": {
                  "type": "string"
                }
              },
              "text/markdown": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "format_not_available (docx, pdf), invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "document_not_found, version_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/documents/{id}/publication": {
      "get": {
        "tags": [
          "documents"
        ],
        "operationId": "getPublication",
        "summary": "Whether and where the document is published on pages.policygrain.com",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The publication; state none until a first publish",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Publication"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "document_not_found (also another account's)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": [
          "documents"
        ],
        "operationId": "publishDocument",
        "summary": "Publish the newest version at pages.policygrain.com/{slug}. Idempotent: the same request again changes nothing",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "slug": {
                    "type": "string",
                    "pattern": "^[a-z0-9]([a-z0-9-]{0,62}[a-z0-9])?$",
                    "description": "Needed on the first publish only; it can't change afterwards. Reserved: s, api, assets, healthz, static, www"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Published, and the static page already shows it",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Publication"
                }
              }
            }
          },
          "202": {
            "description": "Published; the static page updates within seconds (synced: false until then)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Publication"
                }
              }
            }
          },
          "400": {
            "description": "slug_required, invalid_slug, invalid_body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "document_not_found (also another account's)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "draft_not_publishable, document_stale, nothing_to_publish, slug_taken, slug_fixed, publication_busy",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "documents"
        ],
        "operationId": "unpublishDocument",
        "summary": "Take the document off pages.policygrain.com (its pages become 404 and are purged from the CDN). The slug stays this document's",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Not published (already, or the static pages already match)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Publication"
                }
              }
            }
          },
          "202": {
            "description": "Unpublished; the static pages are removed within seconds",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Publication"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `documents` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "document_not_found (also another account's)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites": {
      "post": {
        "tags": [
          "sites"
        ],
        "operationId": "createSite",
        "summary": "A site, with its notice profile and domains",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 255
            },
            "description": "Retry-safe POST: the same key and body within 24 hours replays the first response"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SiteInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Site"
                }
              }
            }
          },
          "400": {
            "description": "invalid_body, invalid_domain, unknown_profile, invalid_idempotency_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "limit_reached (50 sites per account), idempotency_key_reused, idempotency_in_progress",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "sites"
        ],
        "operationId": "listSites",
        "summary": "This account's sites, oldest first",
        "security": [
          {
            "bearer": []
          }
        ],
        "responses": {
          "200": {
            "description": "The sites",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "sites"
                  ],
                  "properties": {
                    "sites": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Site"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}": {
      "get": {
        "tags": [
          "sites"
        ],
        "operationId": "getSite",
        "summary": "One site",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Site"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found (also another account's site)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "patch": {
        "tags": [
          "sites"
        ],
        "operationId": "updateSite",
        "summary": "Rename a site or set its notice profile",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SitePatch"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The site",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Site"
                }
              }
            }
          },
          "400": {
            "description": "invalid_body, unknown_profile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found (also another account's site)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/domains": {
      "get": {
        "tags": [
          "sites"
        ],
        "operationId": "listDomains",
        "summary": "The site's domains, by name",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The domains",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "domains"
                  ],
                  "properties": {
                    "domains": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Domain"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found (also another account's site)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "sites"
        ],
        "operationId": "addDomain",
        "summary": "Add a domain (verified later, C2)",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 255
            },
            "description": "Retry-safe POST: the same key and body within 24 hours replays the first response"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "domain"
                ],
                "properties": {
                  "domain": {
                    "type": "string",
                    "description": "A hostname: example.in, shop.example.in"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The domain",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Domain"
                }
              }
            }
          },
          "400": {
            "description": "invalid_body, invalid_domain, invalid_idempotency_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found (also another account's site)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "domain_exists, limit_reached (20 per site), idempotency_key_reused, idempotency_in_progress",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/domains/{domain}": {
      "delete": {
        "tags": [
          "sites"
        ],
        "operationId": "removeDomain",
        "summary": "Remove a domain",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "domain",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Removed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "domain",
                    "removed"
                  ],
                  "properties": {
                    "domain": {
                      "type": "string"
                    },
                    "removed": {
                      "type": "boolean",
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found (also another account's site), domain_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/domains/{domain}/verify": {
      "post": {
        "tags": [
          "sites"
        ],
        "operationId": "verifyDomain",
        "summary": "Verify a domain",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "domain",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Verified",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Domain"
                    },
                    {
                      "type": "object",
                      "required": [
                        "method"
                      ],
                      "properties": {
                        "method": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "enum": [
                            "dns",
                            "file",
                            null
                          ],
                          "description": "How it was verified by this call; null when it already was"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found (also another account's site), domain_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "domain_not_verified: neither holds the challenge yet; the body's `verification` says what to publish",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    {
                      "$ref": "#/components/schemas/Error"
                    },
                    {
                      "type": "object",
                      "properties": {
                        "verification": {
                          "$ref": "#/components/schemas/DomainVerification"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "413": {
            "description": "body_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited: the domain was checked in the last 10 s; see Retry-After",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "verification_unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "description": "Checks the domain's challenge as a DNS TXT record at `_policygrain.{domain}` and as the body of `https://{domain}/.well-known/policygrain-verify.txt`; either is enough. A verified domain stays verified and isn't checked again (`method: null`). Receipts from a verified domain, or a host under it, are `origin_ok`."
      }
    },
    "/v1/sites/{id}/configs": {
      "get": {
        "tags": [
          "sites"
        ],
        "operationId": "listConfigs",
        "summary": "The site's banner config versions, newest first",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The versions",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "configs"
                  ],
                  "properties": {
                    "configs": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ConfigSummary"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found (also another account's site)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "sites"
        ],
        "operationId": "createConfig",
        "summary": "A new draft version, built from the notice profile and these settings",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 255
            },
            "description": "Retry-safe POST: the same key and body within 24 hours replays the first response"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ConfigInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The draft",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Config"
                }
              }
            }
          },
          "400": {
            "description": "invalid_body, low_contrast, invalid_idempotency_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found (also another account's site)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "no_notice_profile, banner_not_ready (with problems), site_busy, idempotency_key_reused, idempotency_in_progress",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/configs/{ref}": {
      "get": {
        "tags": [
          "sites"
        ],
        "operationId": "getConfig",
        "summary": "One version: a number, latest, or live",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "A version number, latest, or live"
          }
        ],
        "responses": {
          "200": {
            "description": "The version",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Config"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found (also another account's site), config_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/configs/{ref}/publish": {
      "post": {
        "tags": [
          "sites"
        ],
        "operationId": "publishConfig",
        "summary": "Publish a version: draft or failed → uploading; the publish job makes it live",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "ref",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            },
            "description": "The version to publish"
          },
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 255
            },
            "description": "Retry-safe POST: the same key and body within 24 hours replays the first response"
          }
        ],
        "responses": {
          "200": {
            "description": "Already live",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Config"
                }
              }
            }
          },
          "202": {
            "description": "Uploading",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Config"
                }
              }
            }
          },
          "400": {
            "description": "invalid_idempotency_key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required, invalid_credential, key_revoked",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "missing_scope (needs the `sites:write` scope), key_suspended",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found (also another account's site), config_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "config_stale, config_not_publishable, older_than_live, idempotency_key_reused, idempotency_in_progress",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/receipts": {
      "post": {
        "tags": [
          "evidence"
        ],
        "operationId": "postReceipt",
        "summary": "One consent receipt from the banner (public, no key; any origin, CORS)",
        "description": "The body is JSON whatever the Content-Type: the banner sends text/plain so no preflight is needed, and fetch keepalive works on unload. Every receipt is stored with a trust class; only origin_ok receipts are counted.",
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ReceiptInput"
              }
            },
            "text/plain": {
              "schema": {
                "$ref": "#/components/schemas/ReceiptInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A retry: the receipt stored before with this client_event_id",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "201": {
            "description": "Stored",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Receipt"
                }
              }
            }
          },
          "400": {
            "description": "invalid_receipt",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large (8 KB)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited: one address far past any visitor (Retry-After)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "options": {
        "tags": [
          "evidence"
        ],
        "operationId": "preflightReceipt",
        "summary": "CORS preflight",
        "security": [],
        "responses": {
          "204": {
            "description": "Any origin may POST with Content-Type"
          }
        }
      }
    },
    "/v1/sites/{id}/receipts": {
      "get": {
        "tags": [
          "evidence"
        ],
        "operationId": "listSiteReceipts",
        "summary": "List stored consent receipts for a site, limit-aware (scope: evidence:read)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "consent",
                "reject",
                "withdraw",
                "reconsent",
                "notice_shown"
              ]
            }
          },
          {
            "name": "trust",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "origin_ok",
                "origin_unexpected",
                "config_mismatch",
                "rate_flagged"
              ]
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated site receipts",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReceiptList"
                }
              }
            }
          },
          "400": {
            "description": "invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/consent-events": {
      "get": {
        "tags": [
          "evidence"
        ],
        "operationId": "listSiteConsentEvents",
        "summary": "List stored consent events for a site (SDK alias for /v1/sites/{id}/receipts)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "consent",
                "reject",
                "withdraw",
                "reconsent",
                "notice_shown"
              ]
            }
          },
          {
            "name": "trust",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "origin_ok",
                "origin_unexpected",
                "config_mismatch",
                "rate_flagged"
              ]
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated site consent events",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReceiptList"
                }
              }
            }
          },
          "400": {
            "description": "invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/receipts/export": {
      "get": {
        "tags": [
          "evidence"
        ],
        "operationId": "exportSiteReceipts",
        "summary": "Export in-limit consent receipts for a site as JSON or CSV (C6 #102, N11)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "json",
                "csv"
              ],
              "default": "json"
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "date-time"
            }
          },
          {
            "name": "kind",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "consent",
                "reject",
                "withdraw",
                "reconsent",
                "notice_shown"
              ]
            }
          },
          {
            "name": "trust",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "origin_ok",
                "origin_unexpected",
                "config_mismatch",
                "rate_flagged"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "In-limit consent receipt export (JSON or CSV)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ReceiptExport"
                }
              },
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/seal": {
      "get": {
        "tags": [
          "evidence"
        ],
        "operationId": "getSiteSeal",
        "summary": "How far a site's receipts are sealed by Ed25519-signed daily Merkle roots (G13)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Seal state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Seal"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope or account_unverified",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "seal_unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/evidence-packs": {
      "post": {
        "tags": [
          "evidence"
        ],
        "operationId": "createEvidencePack",
        "summary": "Build an evidence pack for a UTC date range: in-limit origin_ok receipts, signed roots, inclusion proofs, an offline verifier and a BSA 2023 s.63 template (G12)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EvidencePackRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The pack, ready to download",
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EvidencePack"
                }
              }
            }
          },
          "400": {
            "description": "invalid_range or invalid_request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "insufficient_scope or account_unverified",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "seal_unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/evidence-packs/{id}": {
      "get": {
        "tags": [
          "evidence"
        ],
        "operationId": "getEvidencePack",
        "summary": "An evidence pack's status, counts and download link (G12)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^epk_[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]{22}$"
            },
            "description": "The pack id POST /v1/sites/{id}/evidence-packs returned"
          }
        ],
        "responses": {
          "200": {
            "description": "The pack",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EvidencePack"
                }
              }
            }
          },
          "404": {
            "description": "evidence_pack_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "evidence_pack_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "seal_unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/evidence-packs/{id}/download": {
      "get": {
        "tags": [
          "evidence"
        ],
        "operationId": "downloadEvidencePack",
        "summary": "Download an evidence pack as a .zip (or its files as JSON)",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^epk_[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]{22}$"
            },
            "description": "The pack id POST /v1/sites/{id}/evidence-packs returned"
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "zip",
                "json"
              ],
              "default": "zip"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The pack: pack.json, receipts.json, receipts.csv, roots.json, merkle-proofs.json, VERIFY.md, verify.mjs, BSA-2023-Section-63-TEMPLATE.md and SHA256SUMS",
            "content": {
              "application/zip": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EvidencePackFiles"
                }
              }
            }
          },
          "400": {
            "description": "invalid_query",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "evidence_pack_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "evidence_pack_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "seal_unavailable",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/usage": {
      "get": {
        "tags": [
          "usage"
        ],
        "operationId": "getUsage",
        "summary": "Monthly trusted receipt usage for the account (or one site via ?site_id=)",
        "parameters": [
          {
            "name": "period",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
            },
            "description": "UTC month (YYYY-MM); defaults to the current UTC month"
          },
          {
            "name": "site_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Limit the response to one site owned by this account"
          }
        ],
        "responses": {
          "200": {
            "description": "Monthly usage summary",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/AccountUsage"
                    },
                    {
                      "$ref": "#/components/schemas/SiteUsage"
                    }
                  ]
                }
              }
            }
          },
          "400": {
            "description": "invalid_period",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/usage": {
      "get": {
        "tags": [
          "usage"
        ],
        "operationId": "getSiteUsage",
        "summary": "One site's monthly trusted receipt count against the 10,000/month free limit",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "period",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^\\d{4}-(0[1-9]|1[0-2])$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Monthly site usage",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SiteUsage"
                }
              }
            }
          },
          "400": {
            "description": "invalid_period",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "site_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/scans": {
      "post": {
        "tags": [
          "scans"
        ],
        "operationId": "createScan",
        "summary": "Queue a scan of one public page",
        "security": [
          {},
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 255,
              "pattern": "^[\\x21-\\x7e]+$"
            },
            "description": "Retry safely: the same key and URL return the same scan (200); the same key with another URL is 409. Keys are per caller (IP or account)."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "url"
                ],
                "properties": {
                  "url": {
                    "type": "string",
                    "maxLength": 2048,
                    "examples": [
                      "https://example.in"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "An Idempotency-Key replay: the earlier scan.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Scan"
                }
              }
            }
          },
          "202": {
            "description": "Queued. Poll GET /v1/scans/{id} every poll_after_ms.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Scan"
                }
              }
            },
            "headers": {
              "Location": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "invalid_body | invalid_url (field url) | url_not_allowed (field url) | invalid_idempotency_key (field Idempotency-Key)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required | invalid_credential, key_revoked, key_suspended, session_expired (a header that doesn't work is refused, not ignored)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "idempotency_key_reused (another URL), idempotency_key_expired (its scan has expired)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "413": {
            "description": "body_too_large",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "scan_limit_reached: 3 keyless scans per IP per UTC day, 2,000 keyless a day across all callers, 50 per account; rate_limited: more than 30 new addresses an hour from one network (120 for an account)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait."
              }
            }
          },
          "503": {
            "description": "scan_queue_full | module_disabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait."
              }
            }
          }
        }
      }
    },
    "/v1/scans/{id}": {
      "get": {
        "tags": [
          "scans"
        ],
        "operationId": "getScan",
        "summary": "Read a scan. The id is the capability; no auth.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The scan.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Scan"
                }
              }
            }
          },
          "404": {
            "description": "scan_not_found (unknown and expired alike; scans are deleted after 7 days)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "module_disabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/scans/{id}/handoff": {
      "post": {
        "tags": [
          "scans"
        ],
        "operationId": "createHandoff",
        "summary": "A single-use, 24-hour link that carries a completed scan into the caller's PolicyGrain account",
        "security": [
          {
            "bearer": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "201": {
            "description": "The link.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Handoff"
                }
              }
            }
          },
          "401": {
            "description": "auth_required | invalid_credential, key_revoked, key_suspended, session_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "scan_not_found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "scan_not_ready",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "handoff_limit_reached: 20 per account per hour",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait."
              }
            }
          },
          "503": {
            "description": "module_disabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/handoffs/redeem": {
      "post": {
        "tags": [
          "scans"
        ],
        "operationId": "redeemHandoff",
        "summary": "Use a handoff link, in the account it was made for",
        "security": [
          {
            "bearer": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "token"
                ],
                "properties": {
                  "token": {
                    "type": "string",
                    "maxLength": 512
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The scan and the answers it suggests.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Redeemed"
                }
              }
            }
          },
          "400": {
            "description": "invalid_body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "auth_required | invalid_credential, key_revoked, key_suspended, session_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "handoff_not_found (also another account's token)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "410": {
            "description": "handoff_used | handoff_expired | scan_expired",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "429": {
            "description": "rate_limited (failed link attempts)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            },
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait."
              }
            }
          },
          "503": {
            "description": "module_disabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/verify": {
      "post": {
        "tags": [
          "verify"
        ],
        "operationId": "triggerSiteVerify",
        "summary": "Queue a live verification run on a verified domain for this site",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerifyStartInput"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Verification check queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Verification"
                }
              }
            }
          },
          "400": {
            "description": "Invalid JSON or disallowed URL",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Site or verified domain not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Browser sandbox unavailable or verify module disabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/verifications": {
      "post": {
        "tags": [
          "verify"
        ],
        "operationId": "createSiteVerification",
        "summary": "Queue a live verification run on a verified domain for this site",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/VerifyStartInput"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Verification check queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Verification"
                }
              }
            }
          },
          "503": {
            "description": "Browser sandbox unavailable or verify module disabled",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      },
      "get": {
        "tags": [
          "verify"
        ],
        "operationId": "listSiteVerifications",
        "summary": "List verification checks for one site, newest first",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Site verification checks",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerificationList"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/verifications/{verificationId}": {
      "get": {
        "tags": [
          "verify"
        ],
        "operationId": "getSiteVerification",
        "summary": "Read one verification check belonging to a site",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "verificationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Verification check",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Verification"
                }
              }
            }
          },
          "404": {
            "description": "Verification check not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/sites/{id}/verifications/{verificationId}/diff": {
      "get": {
        "tags": [
          "verify"
        ],
        "operationId": "getSiteVerificationDiff",
        "summary": "Read deterministic changes since the previous completed verification check for this site",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "verificationId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deterministic drift diff",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerificationDiff"
                }
              }
            }
          },
          "404": {
            "description": "Verification check not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Verification check has not finished yet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/verifications/{id}": {
      "get": {
        "tags": [
          "verify"
        ],
        "operationId": "getVerification",
        "summary": "Read one verification check by id",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Verification check",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Verification"
                }
              }
            }
          },
          "404": {
            "description": "Verification check not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/verifications/{id}/diff": {
      "get": {
        "tags": [
          "verify"
        ],
        "operationId": "getVerificationDiff",
        "summary": "Read deterministic changes since the previous completed verification check",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Deterministic drift diff",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VerificationDiff"
                }
              }
            }
          },
          "404": {
            "description": "Verification check not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "409": {
            "description": "Verification check has not finished yet",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/plans": {
      "get": {
        "tags": [
          "billing"
        ],
        "operationId": "getBillingPlans",
        "summary": "Public catalog of plans with transparent INR/paise pricing and Indian 18% GST rules",
        "security": [],
        "responses": {
          "200": {
            "description": "Plan catalog and GST breakdown rules",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingPlansCatalog"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/entitlements": {
      "get": {
        "tags": [
          "billing"
        ],
        "operationId": "getBillingEntitlements",
        "summary": "Current account plan, max_sites, monthly receipt export allowance, and subscription state",
        "responses": {
          "200": {
            "description": "Effective account billing entitlements",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingEntitlements"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/subscriptions": {
      "post": {
        "tags": [
          "billing"
        ],
        "operationId": "createBillingSubscription",
        "summary": "Create a Razorpay subscription checkout record in created state (never grants entitlement until verified webhook)",
        "parameters": [
          {
            "name": "Idempotency-Key",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSubscriptionInput"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Checkout subscription created in created state",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubscriptionCheckoutResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid plan, billing cycle, GSTIN, or state code",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Billing provider not configured",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/subscriptions/cancel": {
      "post": {
        "tags": [
          "billing"
        ],
        "operationId": "cancelBillingSubscription",
        "summary": "Schedule cancellation of the account's active subscription at period end",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CancelSubscriptionInput"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated subscription record",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubscriptionEnvelope"
                }
              }
            }
          },
          "404": {
            "description": "No active subscription found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Billing provider not configured",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/invoices": {
      "get": {
        "tags": [
          "billing"
        ],
        "operationId": "listBillingInvoices",
        "summary": "List sequential FY Indian GST tax invoices for the authenticated account",
        "responses": {
          "200": {
            "description": "Account GST invoices",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingInvoiceList"
                }
              }
            }
          },
          "401": {
            "description": "Authentication required",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/invoices/{id}": {
      "get": {
        "tags": [
          "billing"
        ],
        "operationId": "getBillingInvoice",
        "summary": "Fetch one Indian GST tax invoice as JSON",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "GST tax invoice JSON",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BillingInvoice"
                }
              }
            }
          },
          "404": {
            "description": "Invoice not found on this account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/invoices/{id}/html": {
      "get": {
        "tags": [
          "billing"
        ],
        "operationId": "getBillingInvoiceHtml",
        "summary": "Render one printable, zero-JS, zero-inline-style semantic HTML GST tax invoice",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Semantic HTML GST tax invoice",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Invoice not found on this account",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/v1/billing/webhooks/razorpay": {
      "post": {
        "tags": [
          "billing"
        ],
        "operationId": "receiveRazorpayWebhook",
        "summary": "Receive an HMAC-SHA256 signed Razorpay subscription webhook (idempotent replay)",
        "security": [],
        "parameters": [
          {
            "name": "X-Razorpay-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "X-Razorpay-Event-Id",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook verified and processed (or idempotently acknowledged on replay)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WebhookAck"
                }
              }
            }
          },
          "401": {
            "description": "Invalid or missing X-Razorpay-Signature",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "503": {
            "description": "Webhook secret not configured",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Scoped PolicyGrain API key (`pgk_...`) or 15-minute web session (`pgs_...`)."
      },
      "bearer": {
        "type": "http",
        "scheme": "bearer",
        "description": "Scoped PolicyGrain API key (`pgk_...`) or 15-minute web session (`pgs_...`)."
      }
    },
    "schemas": {
      "OperationalStatus": {
        "type": "object",
        "required": [
          "status",
          "api",
          "database",
          "sandbox_configured",
          "sandbox_enabled",
          "corpus_commit",
          "region",
          "version",
          "disabled_modules",
          "checked_at"
        ],
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degraded"
            ]
          },
          "api": {
            "type": "string",
            "enum": [
              "ok"
            ]
          },
          "database": {
            "type": "string",
            "enum": [
              "ok",
              "degraded",
              "not_configured"
            ]
          },
          "sandbox_configured": {
            "type": "boolean"
          },
          "sandbox_enabled": {
            "type": "boolean"
          },
          "corpus_commit": {
            "type": [
              "string",
              "null"
            ]
          },
          "region": {
            "type": "string"
          },
          "version": {
            "type": "string"
          },
          "disabled_modules": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "checked_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "RightsRequestInput": {
        "type": "object",
        "required": [
          "request_type",
          "requester_email",
          "description"
        ],
        "properties": {
          "request_type": {
            "type": "string",
            "enum": [
              "access",
              "correction",
              "erasure",
              "grievance",
              "nomination"
            ]
          },
          "requester_email": {
            "type": "string",
            "format": "email",
            "maxLength": 254
          },
          "description": {
            "type": "string",
            "minLength": 10,
            "maxLength": 2000
          },
          "csrf_token": {
            "type": "string"
          }
        }
      },
      "RightsReceipt": {
        "type": "object",
        "required": [
          "reference_id",
          "site_id",
          "organisation",
          "request_type",
          "request_label",
          "statutory_citation",
          "submitted_at",
          "response_days",
          "deadline_at",
          "statutory_ceiling_at",
          "rule_14_citation",
          "receipt_sha256",
          "email_dispatched",
          "grievance_officer_configured",
          "grievance_officer_name",
          "grievance_officer_email",
          "delivery_note"
        ],
        "properties": {
          "reference_id": {
            "type": "string"
          },
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "organisation": {
            "type": "string"
          },
          "request_type": {
            "type": "string",
            "enum": [
              "access",
              "correction",
              "erasure",
              "grievance",
              "nomination"
            ]
          },
          "request_label": {
            "type": "string"
          },
          "statutory_citation": {
            "type": "string"
          },
          "submitted_at": {
            "type": "string",
            "format": "date-time"
          },
          "response_days": {
            "type": "integer",
            "minimum": 1,
            "maximum": 90
          },
          "deadline_at": {
            "type": "string",
            "format": "date-time"
          },
          "statutory_ceiling_at": {
            "type": "string",
            "format": "date-time"
          },
          "rule_14_citation": {
            "type": "string"
          },
          "receipt_sha256": {
            "type": "string"
          },
          "email_dispatched": {
            "type": "boolean"
          },
          "grievance_officer_configured": {
            "type": "boolean"
          },
          "grievance_officer_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "grievance_officer_email": {
            "type": [
              "string",
              "null"
            ]
          },
          "delivery_note": {
            "type": "string"
          }
        }
      },
      "Error": {
        "type": "object",
        "required": [
          "code",
          "message",
          "fix"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "field": {
            "type": "string"
          },
          "fix": {
            "type": "string"
          },
          "problems": {
            "type": "array",
            "description": "invalid_answers only: every problem, each {code, field, message, fix}",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "Condition": {
        "description": "A corpus condition: {q,is} | {q,has} | {field} | {within:{from?,until?}} | {not} | {all:[]} | {any:[]}",
        "type": "object"
      },
      "Question": {
        "type": "object",
        "required": [
          "id",
          "text",
          "type",
          "tier",
          "options",
          "shows",
          "default",
          "default_from",
          "fed_by",
          "same_as",
          "fills",
          "fixed",
          "review_flag",
          "affects"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "text": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "yes_no",
              "single",
              "multi",
              "text",
              "none"
            ]
          },
          "tier": {
            "type": "integer",
            "enum": [
              1,
              2
            ]
          },
          "options": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "shows": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Condition"
              },
              {
                "type": "null"
              }
            ]
          },
          "default": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              {
                "type": "null"
              }
            ]
          },
          "default_from": {
            "type": [
              "string",
              "null"
            ]
          },
          "fed_by": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "same_as": {
            "type": [
              "string",
              "null"
            ]
          },
          "fills": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "fixed": {
            "type": "boolean"
          },
          "review_flag": {
            "type": "boolean"
          },
          "affects": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Field": {
        "type": "object",
        "required": [
          "id",
          "tier",
          "required",
          "default",
          "default_from",
          "min",
          "max",
          "set_by",
          "used_by"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "tier": {
            "type": "integer",
            "enum": [
              1,
              2
            ]
          },
          "required": {
            "type": "boolean"
          },
          "default": {
            "type": [
              "string",
              "null"
            ]
          },
          "default_from": {
            "type": [
              "string",
              "null"
            ]
          },
          "min": {
            "type": [
              "number",
              "null"
            ]
          },
          "max": {
            "type": [
              "number",
              "null"
            ]
          },
          "set_by": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "fixed",
              "library_wording",
              null
            ]
          },
          "used_by": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "DocumentType": {
        "type": "object",
        "required": [
          "id",
          "title",
          "signoff",
          "approved",
          "generated_when"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "signoff": {
            "type": "integer"
          },
          "approved": {
            "type": "boolean"
          },
          "generated_when": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Condition"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "Questionnaire": {
        "type": "object",
        "required": [
          "version",
          "corpus_commit",
          "questions",
          "fields",
          "required_fields",
          "documents"
        ],
        "properties": {
          "version": {
            "type": "string"
          },
          "corpus_commit": {
            "type": "string"
          },
          "questions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Question"
            }
          },
          "fields": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Field"
            }
          },
          "required_fields": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentType"
            }
          }
        }
      },
      "ProfileInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "answers": {
            "type": "object",
            "additionalProperties": {
              "oneOf": [
                {
                  "oneOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  ]
                },
                {
                  "type": "object",
                  "required": [
                    "value",
                    "source"
                  ],
                  "properties": {
                    "value": {
                      "oneOf": [
                        {
                          "type": "string"
                        },
                        {
                          "type": "array",
                          "items": {
                            "type": "string"
                          }
                        }
                      ]
                    },
                    "source": {
                      "type": "string",
                      "enum": [
                        "owner",
                        "agent_inferred"
                      ]
                    }
                  }
                },
                {
                  "type": "null"
                }
              ],
              "description": "A plain value (the owner's from a signed-in person, agent_inferred from an API key), {value, source} (a key sending source owner asserts it is the owner's, recorded with the key id), or null to remove it"
            },
            "description": "Question id → answer"
          },
          "fields": {
            "type": "object",
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "string",
                  "maxLength": 4000
                },
                {
                  "type": "object",
                  "required": [
                    "value",
                    "source"
                  ],
                  "properties": {
                    "value": {
                      "type": "string",
                      "maxLength": 4000
                    },
                    "source": {
                      "type": "string",
                      "enum": [
                        "owner",
                        "agent_inferred"
                      ]
                    }
                  }
                },
                {
                  "type": "null"
                }
              ],
              "description": "A plain value (the owner's from a signed-in person, agent_inferred from an API key), {value, source} (a key sending source owner asserts it is the owner's, recorded with the key id), or null to remove it"
            },
            "description": "Field id → value. Fields with set_by are refused."
          },
          "document_answers": {
            "type": "object",
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "object",
                  "additionalProperties": {
                    "oneOf": [
                      {
                        "oneOf": [
                          {
                            "type": "string"
                          },
                          {
                            "type": "array",
                            "items": {
                              "type": "string"
                            }
                          }
                        ]
                      },
                      {
                        "type": "object",
                        "required": [
                          "value",
                          "source"
                        ],
                        "properties": {
                          "value": {
                            "oneOf": [
                              {
                                "type": "string"
                              },
                              {
                                "type": "array",
                                "items": {
                                  "type": "string"
                                }
                              }
                            ]
                          },
                          "source": {
                            "type": "string",
                            "enum": [
                              "owner",
                              "agent_inferred"
                            ]
                          }
                        }
                      },
                      {
                        "type": "null"
                      }
                    ],
                    "description": "A plain value (the owner's from a signed-in person, agent_inferred from an API key), {value, source} (a key sending source owner asserts it is the owner's, recorded with the key id), or null to remove it"
                  }
                },
                {
                  "type": "null"
                }
              ]
            },
            "description": "Document type → Tier 2 answers for that document only"
          },
          "confirm": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Ids from `unconfirmed` to mark as the owner's (sessions only): M-04, org.legal_name, terms/TC-10"
          }
        }
      },
      "Profile": {
        "type": "object",
        "required": [
          "id",
          "question_set_version",
          "answers",
          "fields",
          "document_answers",
          "unconfirmed",
          "answers_sha256",
          "revision",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "question_set_version": {
            "type": "string"
          },
          "answers": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "required": [
                "value",
                "source"
              ],
              "properties": {
                "value": {
                  "oneOf": [
                    {
                      "type": "string"
                    },
                    {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  ]
                },
                "source": {
                  "type": "string",
                  "enum": [
                    "owner",
                    "agent_inferred"
                  ]
                },
                "asserted_by_key": {
                  "type": "string",
                  "format": "uuid",
                  "description": "The API key that asserted source owner. Absent when a signed-in person gave or confirmed the value (and on values keys sent before 20 Nov 2026)"
                }
              }
            }
          },
          "fields": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "required": [
                "value",
                "source"
              ],
              "properties": {
                "value": {
                  "type": "string"
                },
                "source": {
                  "type": "string",
                  "enum": [
                    "owner",
                    "agent_inferred"
                  ]
                },
                "asserted_by_key": {
                  "type": "string",
                  "format": "uuid",
                  "description": "The API key that asserted source owner. Absent when a signed-in person gave or confirmed the value (and on values keys sent before 20 Nov 2026)"
                }
              }
            }
          },
          "document_answers": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "required": [
                  "value",
                  "source"
                ],
                "properties": {
                  "value": {
                    "oneOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "array",
                        "items": {
                          "type": "string"
                        }
                      }
                    ]
                  },
                  "source": {
                    "type": "string",
                    "enum": [
                      "owner",
                      "agent_inferred"
                    ]
                  },
                  "asserted_by_key": {
                    "type": "string",
                    "format": "uuid",
                    "description": "The API key that asserted source owner. Absent when a signed-in person gave or confirmed the value (and on values keys sent before 20 Nov 2026)"
                  }
                }
              }
            }
          },
          "unconfirmed": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "answers_sha256": {
            "type": "string"
          },
          "revision": {
            "type": "integer"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ProfileList": {
        "type": "object",
        "required": [
          "profiles"
        ],
        "properties": {
          "profiles": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Profile"
            }
          }
        }
      },
      "OutcomeProblem": {
        "type": "object",
        "required": [
          "code",
          "target",
          "message",
          "fix",
          "waits_for"
        ],
        "properties": {
          "code": {
            "type": "string"
          },
          "target": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "fix": {
            "type": "string"
          },
          "waits_for": {
            "type": "string",
            "enum": [
              "answers",
              "library"
            ],
            "description": "library: the clause library has no approved text for it yet; no answer fixes it"
          }
        }
      },
      "DocumentOutcome": {
        "type": "object",
        "required": [
          "doc_type",
          "title",
          "outcome",
          "document_id",
          "version",
          "problems"
        ],
        "properties": {
          "doc_type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "outcome": {
            "type": "string",
            "enum": [
              "new_version",
              "unchanged",
              "not_applicable",
              "blocked"
            ]
          },
          "document_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "version": {
            "type": [
              "integer",
              "null"
            ]
          },
          "problems": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/OutcomeProblem"
            }
          }
        }
      },
      "Generation": {
        "type": "object",
        "required": [
          "id",
          "profile_id",
          "status",
          "requested",
          "documents",
          "new_versions",
          "failure_reason",
          "attempts",
          "progress",
          "answers_sha256",
          "created_at",
          "started_at",
          "finished_at",
          "poll_after_ms"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "profile_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "done",
              "failed"
            ]
          },
          "requested": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "string"
            }
          },
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DocumentOutcome"
            },
            "description": "One per document type once done; empty before"
          },
          "new_versions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "failure_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "attempts": {
            "type": "integer"
          },
          "progress": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/GenerationProgress"
              },
              {
                "type": "null"
              }
            ],
            "description": "Stage-named progress while queued, rendering, or settled"
          },
          "answers_sha256": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "started_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "finished_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "poll_after_ms": {
            "type": [
              "integer",
              "null"
            ]
          }
        }
      },
      "GenerationProgress": {
        "type": "object",
        "required": [
          "stage"
        ],
        "additionalProperties": false,
        "properties": {
          "stage": {
            "type": "string"
          },
          "completed": {
            "type": "integer",
            "minimum": 0
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "detail": {
            "type": "string"
          }
        }
      },
      "GenerationInput": {
        "type": "object",
        "required": [
          "profile_id"
        ],
        "additionalProperties": false,
        "properties": {
          "profile_id": {
            "type": "string",
            "format": "uuid"
          },
          "documents": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "description": "Document types; leave out for every type"
          }
        }
      },
      "VersionSummary": {
        "type": "object",
        "required": [
          "n",
          "created_at",
          "content_sha256",
          "generation_id"
        ],
        "properties": {
          "n": {
            "type": "integer",
            "minimum": 1
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "content_sha256": {
            "type": "string"
          },
          "generation_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      },
      "Document": {
        "type": "object",
        "required": [
          "id",
          "profile_id",
          "doc_type",
          "title",
          "state",
          "stale_reason",
          "draft_reasons",
          "waiting_on",
          "current_version",
          "versions"
        ],
        "properties": {
          "id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "Null while the type has no version"
          },
          "profile_id": {
            "type": "string",
            "format": "uuid"
          },
          "doc_type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "final",
              "draft",
              "stale",
              "not_generated"
            ],
            "description": "stale: the newest version no longer matches the answers; generate again"
          },
          "stale_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "answers_changed",
              "not_applicable",
              "blocked",
              null
            ],
            "description": "Why the document is stale: the answers changed since it was generated, or the latest generation found it not applicable or blocked"
          },
          "draft_reasons": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "type_not_approved",
                "unconfirmed_answers"
              ]
            }
          },
          "waiting_on": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Agent-inferred values it uses, for PATCH /v1/profiles/{id} confirm"
          },
          "current_version": {
            "type": [
              "integer",
              "null"
            ]
          },
          "versions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VersionSummary"
            },
            "description": "Newest first"
          }
        }
      },
      "DocumentList": {
        "type": "object",
        "required": [
          "profile_id",
          "documents",
          "formats"
        ],
        "properties": {
          "profile_id": {
            "type": "string",
            "format": "uuid"
          },
          "documents": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Document"
            },
            "description": "Every document type, in the corpus's order"
          },
          "formats": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Formats a version can be fetched in now"
          }
        }
      },
      "BlockProvenance": {
        "type": "object",
        "required": [
          "block",
          "ref",
          "status",
          "source",
          "source_sha256",
          "date",
          "approved_by",
          "approval",
          "cites"
        ],
        "properties": {
          "block": {
            "type": "string"
          },
          "ref": {
            "type": "string",
            "description": "The clause or purpose id"
          },
          "status": {
            "type": "string",
            "enum": [
              "drafted",
              "approved"
            ]
          },
          "source": {
            "type": "string"
          },
          "source_sha256": {
            "type": "string"
          },
          "date": {
            "type": "string"
          },
          "approved_by": {
            "type": [
              "string",
              "null"
            ]
          },
          "approval": {
            "type": [
              "string",
              "null"
            ]
          },
          "cites": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "row",
                "source",
                "ref"
              ],
              "properties": {
                "row": {
                  "type": "string"
                },
                "source": {
                  "type": "string"
                },
                "ref": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "DocumentVersion": {
        "type": "object",
        "required": [
          "document_id",
          "profile_id",
          "doc_type",
          "n",
          "current",
          "created_at",
          "title",
          "draft",
          "draft_reasons",
          "waiting_on",
          "stale_reason",
          "content_sha256",
          "generation_id",
          "inputs",
          "notice",
          "html",
          "markdown",
          "provenance",
          "review_flags",
          "purposes"
        ],
        "properties": {
          "document_id": {
            "type": "string",
            "format": "uuid"
          },
          "profile_id": {
            "type": "string",
            "format": "uuid"
          },
          "doc_type": {
            "type": "string"
          },
          "n": {
            "type": "integer"
          },
          "current": {
            "type": "boolean"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "title": {
            "type": "string"
          },
          "draft": {
            "type": "boolean"
          },
          "draft_reasons": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "type_not_approved",
                "unconfirmed_answers"
              ]
            }
          },
          "waiting_on": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "stale_reason": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "answers_changed",
              "not_applicable",
              "blocked",
              null
            ],
            "description": "For the current version, why the document no longer matches the answers; null for older versions and while it matches"
          },
          "content_sha256": {
            "type": "string"
          },
          "generation_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "inputs": {
            "type": "object",
            "description": "Every render input (C11): corpus_commit, format_version, renderer, question_set_version, doc_type, as_of, answers_sha256"
          },
          "notice": {
            "type": "string",
            "description": "The not-a-law-firm notice, also printed in the document"
          },
          "html": {
            "type": "string"
          },
          "markdown": {
            "type": "string"
          },
          "provenance": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BlockProvenance"
            }
          },
          "review_flags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "purposes": {
            "type": "array",
            "items": {
              "type": "string"
            }
          }
        }
      },
      "Publication": {
        "type": "object",
        "required": [
          "document_id",
          "state",
          "slug",
          "url",
          "current_version",
          "versions",
          "synced"
        ],
        "properties": {
          "document_id": {
            "type": "string",
            "format": "uuid"
          },
          "state": {
            "type": "string",
            "enum": [
              "none",
              "published",
              "unpublished"
            ]
          },
          "slug": {
            "type": [
              "string",
              "null"
            ]
          },
          "url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "pages.policygrain.com/{slug}: where it is, or was, public"
          },
          "current_version": {
            "type": [
              "integer",
              "null"
            ],
            "description": "The version /{slug} shows; null unless published"
          },
          "versions": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "n",
                "published_at",
                "url"
              ],
              "properties": {
                "n": {
                  "type": "integer"
                },
                "published_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "url": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "format": "uri"
                }
              }
            },
            "description": "Every version ever published, oldest first"
          },
          "synced": {
            "type": "boolean",
            "description": "False while the static pages and the CDN still show the previous state"
          }
        }
      },
      "BannerConfig": {
        "type": "object",
        "required": [
          "format",
          "site_id",
          "version",
          "material_version",
          "languages",
          "position",
          "colors",
          "withdraw",
          "notice_url",
          "material_change",
          "purposes",
          "strings"
        ],
        "description": "The published document (format 1); config_sha256 is the sha256 of its canonical JSON (keys sorted at every level, no whitespace)",
        "properties": {
          "format": {
            "type": "integer",
            "const": 1
          },
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer",
            "minimum": 1
          },
          "material_version": {
            "type": "integer",
            "minimum": 1,
            "description": "Newest live version published with material_change=true (or the first version)"
          },
          "languages": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "position": {
            "type": "string",
            "enum": [
              "bottom",
              "bottom_left",
              "bottom_right",
              "center"
            ]
          },
          "colors": {
            "$ref": "#/components/schemas/Colors"
          },
          "withdraw": {
            "type": "string",
            "enum": [
              "floating",
              "footer_link"
            ]
          },
          "notice_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "material_change": {
            "type": "boolean"
          },
          "purposes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Purpose"
            }
          },
          "strings": {
            "$ref": "#/components/schemas/BannerStrings"
          }
        }
      },
      "BannerStrings": {
        "type": "object",
        "required": [
          "plain",
          "rich",
          "optional"
        ],
        "description": "All 27 non-bundled roles from clauses/banner-strings.yaml rendered with the profile's answers",
        "properties": {
          "plain": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "rich": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/RichText"
            }
          },
          "optional": {
            "type": "object",
            "additionalProperties": {
              "$ref": "#/components/schemas/RichText"
            }
          }
        }
      },
      "RichText": {
        "type": "array",
        "items": {
          "oneOf": [
            {
              "type": "string"
            },
            {
              "type": "object",
              "required": [
                "href",
                "text"
              ],
              "properties": {
                "href": {
                  "type": "string",
                  "format": "uri"
                },
                "text": {
                  "type": "string"
                }
              }
            }
          ]
        }
      },
      "Colors": {
        "type": "object",
        "required": [
          "background",
          "text",
          "button",
          "button_text"
        ],
        "properties": {
          "background": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$"
          },
          "text": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$"
          },
          "button": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$"
          },
          "button_text": {
            "type": "string",
            "pattern": "^#[0-9a-fA-F]{6}$"
          }
        },
        "description": "text on background and button_text on button need 4.5:1 contrast (WCAG 2.2 AA); accept and reject share the button colours"
      },
      "Config": {
        "type": "object",
        "required": [
          "site_id",
          "version",
          "state",
          "live",
          "material_change",
          "config_sha256",
          "failure_reason",
          "created_at",
          "publish_requested_at",
          "live_at",
          "profile_id",
          "answers_sha256",
          "config"
        ],
        "properties": {
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "version": {
            "type": "integer"
          },
          "state": {
            "type": "string",
            "enum": [
              "draft",
              "uploading",
              "live",
              "failed"
            ]
          },
          "live": {
            "type": "boolean",
            "description": "This version is what visitors get"
          },
          "material_change": {
            "type": "boolean"
          },
          "config_sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "failure_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "publish_requested_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "live_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "profile_id": {
            "type": "string",
            "format": "uuid"
          },
          "answers_sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "config": {
            "$ref": "#/components/schemas/BannerConfig"
          }
        }
      },
      "ConfigInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "position": {
            "type": "string",
            "enum": [
              "bottom",
              "bottom_left",
              "bottom_right",
              "center"
            ],
            "default": "bottom"
          },
          "colors": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "background": {
                "type": "string",
                "pattern": "^#[0-9a-fA-F]{6}$"
              },
              "text": {
                "type": "string",
                "pattern": "^#[0-9a-fA-F]{6}$"
              },
              "button": {
                "type": "string",
                "pattern": "^#[0-9a-fA-F]{6}$"
              },
              "button_text": {
                "type": "string",
                "pattern": "^#[0-9a-fA-F]{6}$"
              }
            },
            "description": "Any you leave out keep the defaults (#ffffff, #1a1a1a, #1a1a1a, #ffffff)"
          },
          "withdraw": {
            "type": "string",
            "enum": [
              "floating",
              "footer_link"
            ],
            "default": "floating"
          },
          "notice_url": {
            "type": [
              "string",
              "null"
            ],
            "format": "uri",
            "description": "https only"
          },
          "material_change": {
            "type": "boolean",
            "default": false,
            "description": "Ask visitors again even if the purposes didn't change"
          }
        }
      },
      "ConfigSummary": {
        "type": "object",
        "required": [
          "version",
          "state",
          "live",
          "material_change",
          "config_sha256",
          "failure_reason",
          "created_at",
          "publish_requested_at",
          "live_at"
        ],
        "properties": {
          "version": {
            "type": "integer"
          },
          "state": {
            "type": "string",
            "enum": [
              "draft",
              "uploading",
              "live",
              "failed"
            ]
          },
          "live": {
            "type": "boolean",
            "description": "This version is what visitors get"
          },
          "material_change": {
            "type": "boolean"
          },
          "config_sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "failure_reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "publish_requested_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "live_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Domain": {
        "type": "object",
        "required": [
          "domain",
          "verified",
          "verified_at",
          "challenge",
          "verification",
          "created_at"
        ],
        "properties": {
          "domain": {
            "type": "string"
          },
          "verified": {
            "type": "boolean"
          },
          "verified_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "challenge": {
            "type": "string",
            "description": "The token that proves the domain (C2)"
          },
          "verification": {
            "$ref": "#/components/schemas/DomainVerification"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Purpose": {
        "type": "object",
        "required": [
          "id",
          "category",
          "optional",
          "text",
          "data",
          "recipients"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "category": {
            "type": "string",
            "enum": [
              "strictly_necessary",
              "functional",
              "analytics",
              "preferences",
              "security",
              "advertising"
            ]
          },
          "optional": {
            "type": "boolean",
            "description": "Needs consent: a toggle, off by default"
          },
          "text": {
            "type": "string",
            "description": "The approved notice line"
          },
          "data": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Itemised personal data used for this purpose (Rule 3(b))"
          },
          "recipients": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Itemised recipients for this purpose (Rule 3(b))"
          }
        }
      },
      "Site": {
        "type": "object",
        "required": [
          "id",
          "name",
          "notice_profile_id",
          "live_config_version",
          "domains",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "notice_profile_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "live_config_version": {
            "type": [
              "integer",
              "null"
            ],
            "description": "The version visitors get; moves forward only"
          },
          "domains": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Domain"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SiteInput": {
        "type": "object",
        "required": [
          "name"
        ],
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "notice_profile_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid",
            "description": "The profile (GET /v1/profiles) whose answers give the banner its purposes"
          },
          "domains": {
            "type": "array",
            "maxItems": 20,
            "items": {
              "type": "string"
            }
          }
        }
      },
      "SitePatch": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "notice_profile_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      },
      "DomainVerification": {
        "type": "object",
        "required": [
          "dns",
          "file"
        ],
        "description": "What to publish to verify the domain, either way (C2)",
        "properties": {
          "dns": {
            "type": "object",
            "required": [
              "type",
              "name",
              "value"
            ],
            "properties": {
              "type": {
                "type": "string",
                "const": "TXT"
              },
              "name": {
                "type": "string",
                "description": "_policygrain.{domain}"
              },
              "value": {
                "type": "string",
                "description": "The challenge"
              }
            }
          },
          "file": {
            "type": "object",
            "required": [
              "url",
              "content"
            ],
            "properties": {
              "url": {
                "type": "string",
                "format": "uri",
                "description": "https://{domain}/.well-known/policygrain-verify.txt"
              },
              "content": {
                "type": "string",
                "description": "The challenge, the file's whole body"
              }
            }
          }
        }
      },
      "Receipt": {
        "type": "object",
        "required": [
          "id",
          "site_id",
          "seq",
          "trust",
          "counted",
          "duplicate",
          "received_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "seq": {
            "type": "integer",
            "description": "Per site, from 1, in arrival order"
          },
          "trust": {
            "type": "string",
            "enum": [
              "origin_ok",
              "origin_unexpected",
              "config_mismatch",
              "rate_flagged"
            ]
          },
          "counted": {
            "type": "boolean",
            "description": "Counts towards the site's monthly receipts (origin_ok only)"
          },
          "duplicate": {
            "type": "boolean"
          },
          "received_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "StoredReceipt": {
        "type": "object",
        "required": [
          "id",
          "site_id",
          "seq",
          "received_at",
          "client_ts",
          "client_event_id",
          "kind",
          "consent_id",
          "choices",
          "config_version",
          "config_sha256",
          "client_config_sha256",
          "notice_version",
          "notice_sha256",
          "language",
          "origin",
          "trust",
          "counted",
          "over_limit",
          "prev_hash",
          "hash"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "seq": {
            "type": "integer",
            "minimum": 1
          },
          "received_at": {
            "type": "string",
            "format": "date-time"
          },
          "client_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "client_event_id": {
            "type": "string",
            "format": "uuid"
          },
          "kind": {
            "type": "string",
            "enum": [
              "consent",
              "reject",
              "withdraw",
              "reconsent",
              "notice_shown"
            ]
          },
          "consent_id": {
            "type": "string",
            "format": "uuid"
          },
          "choices": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "enum": [
                "granted",
                "denied"
              ]
            }
          },
          "config_version": {
            "type": "integer",
            "minimum": 1
          },
          "config_sha256": {
            "type": [
              "string",
              "null"
            ]
          },
          "client_config_sha256": {
            "type": [
              "string",
              "null"
            ]
          },
          "notice_version": {
            "type": [
              "integer",
              "null"
            ]
          },
          "notice_sha256": {
            "type": [
              "string",
              "null"
            ]
          },
          "language": {
            "type": "string"
          },
          "origin": {
            "type": [
              "string",
              "null"
            ]
          },
          "trust": {
            "type": "string",
            "enum": [
              "origin_ok",
              "origin_unexpected",
              "config_mismatch",
              "rate_flagged"
            ]
          },
          "counted": {
            "type": "boolean"
          },
          "over_limit": {
            "type": "boolean"
          },
          "prev_hash": {
            "type": [
              "string",
              "null"
            ]
          },
          "hash": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ReceiptList": {
        "type": "object",
        "required": [
          "site_id",
          "receipts",
          "events",
          "total",
          "limit",
          "counted_this_month",
          "over_limit_count",
          "next_cursor"
        ],
        "properties": {
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "receipts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StoredReceipt"
            }
          },
          "events": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StoredReceipt"
            }
          },
          "total": {
            "type": "integer",
            "minimum": 0
          },
          "limit": {
            "type": "integer",
            "minimum": 1
          },
          "counted_this_month": {
            "type": "integer",
            "minimum": 0
          },
          "over_limit_count": {
            "type": "integer",
            "minimum": 0
          },
          "next_cursor": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "ReceiptExport": {
        "type": "object",
        "required": [
          "site_id",
          "format",
          "exported_count",
          "gated_count",
          "gated_from",
          "chain_valid",
          "receipts"
        ],
        "properties": {
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "format": {
            "type": "string",
            "enum": [
              "json"
            ]
          },
          "exported_count": {
            "type": "integer",
            "minimum": 0
          },
          "gated_count": {
            "type": "integer",
            "minimum": 0
          },
          "gated_from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "chain_valid": {
            "type": "boolean"
          },
          "receipts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/StoredReceipt"
            }
          }
        }
      },
      "ReceiptInput": {
        "type": "object",
        "required": [
          "site_id",
          "client_event_id",
          "kind",
          "consent_id",
          "config_version",
          "config_sha256"
        ],
        "additionalProperties": false,
        "properties": {
          "format": {
            "type": "integer",
            "enum": [
              1
            ],
            "description": "The receipt format; left out means 1"
          },
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "client_event_id": {
            "type": "string",
            "format": "uuid",
            "description": "Made once per receipt, sent again on every retry: the dedupe key"
          },
          "kind": {
            "type": "string",
            "enum": [
              "consent",
              "reject",
              "withdraw",
              "reconsent",
              "notice_shown"
            ]
          },
          "consent_id": {
            "type": "string",
            "format": "uuid",
            "description": "Kept in the browser: the same for a visitor's consent and its later withdrawal or re-consent"
          },
          "config_version": {
            "type": "integer",
            "minimum": 1,
            "description": "The version the banner loaded"
          },
          "config_sha256": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[0-9a-f]{64}$",
            "description": "The loaded config's sha256 as the browser computed it, or null when it can't hash (no crypto.subtle on http); null is stored as config_mismatch. The stored hash is the published record's"
          },
          "notice_version": {
            "type": [
              "integer",
              "null"
            ],
            "minimum": 1,
            "description": "The consent notice version the banner showed (the browser's claim)"
          },
          "notice_sha256": {
            "type": [
              "string",
              "null"
            ],
            "pattern": "^[0-9a-f]{64}$",
            "description": "The shown notice's sha256 (the browser's claim)"
          },
          "choices": {
            "type": "object",
            "maxProperties": 64,
            "additionalProperties": {
              "oneOf": [
                {
                  "type": "boolean"
                },
                {
                  "type": "string",
                  "enum": [
                    "granted",
                    "denied"
                  ]
                }
              ]
            },
            "description": "Purpose id to choice: true (granted) or false (denied); \"granted\" / \"denied\" are accepted too. Required except for notice_shown"
          },
          "language": {
            "type": "string",
            "default": "en"
          },
          "client_ts": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "The browser's clock; kept, never trusted"
          },
          "subject_ref": {
            "type": [
              "string",
              "null"
            ],
            "maxLength": 128,
            "description": "Your own id for the visitor (forms consent); leave it out for the banner"
          }
        }
      },
      "EvidenceRoot": {
        "type": "object",
        "required": [
          "digest_date",
          "merkle_root",
          "receipt_count",
          "site_count",
          "key_id",
          "public_key",
          "signature",
          "sealed_at",
          "signature_valid"
        ],
        "properties": {
          "digest_date": {
            "type": "string",
            "format": "date"
          },
          "merkle_root": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "receipt_count": {
            "type": "integer",
            "minimum": 0,
            "description": "Leaves in the day's tree: hashed receipts from every site"
          },
          "site_count": {
            "type": "integer",
            "minimum": 0
          },
          "key_id": {
            "type": "string"
          },
          "public_key": {
            "type": "string",
            "description": "Base64 SPKI DER Ed25519 public key"
          },
          "signature": {
            "type": "string",
            "pattern": "^[0-9a-f]{128}$"
          },
          "sealed_at": {
            "type": "string",
            "format": "date-time"
          },
          "signature_valid": {
            "type": "boolean"
          }
        }
      },
      "ChainPoint": {
        "type": "object",
        "required": [
          "seq",
          "hash",
          "received_at"
        ],
        "properties": {
          "seq": {
            "type": "integer",
            "minimum": 1
          },
          "hash": {
            "type": [
              "string",
              "null"
            ]
          },
          "received_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Seal": {
        "type": "object",
        "required": [
          "site_id",
          "last_sealed_seq",
          "last_sealed_at",
          "chain_head",
          "unsealed_count",
          "root",
          "latest_root"
        ],
        "properties": {
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "last_sealed_seq": {
            "type": [
              "integer",
              "null"
            ]
          },
          "last_sealed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "chain_head": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ChainPoint"
              },
              {
                "type": "null"
              }
            ]
          },
          "unsealed_count": {
            "type": "integer",
            "minimum": 0
          },
          "root": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/EvidenceRoot"
              },
              {
                "type": "null"
              }
            ]
          },
          "latest_root": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/EvidenceRoot"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "EvidencePackRequest": {
        "type": "object",
        "required": [
          "from",
          "to"
        ],
        "properties": {
          "from": {
            "type": "string",
            "format": "date",
            "description": "First UTC day"
          },
          "to": {
            "type": "string",
            "format": "date",
            "description": "Last UTC day, today or earlier; at most 366 days after from"
          }
        }
      },
      "EvidencePack": {
        "type": "object",
        "required": [
          "id",
          "site_id",
          "status",
          "from",
          "to",
          "gated_from",
          "gated_count",
          "receipt_count",
          "download_url",
          "created_at",
          "expires_at",
          "error"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "ready"
            ]
          },
          "from": {
            "type": "string",
            "format": "date"
          },
          "to": {
            "type": "string",
            "format": "date"
          },
          "gated_from": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When the first receipt left out for the monthly export limit arrived"
          },
          "gated_count": {
            "type": "integer",
            "minimum": 0
          },
          "receipt_count": {
            "type": "integer",
            "minimum": 0
          },
          "download_url": {
            "type": "string"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "error": {
            "type": "null"
          }
        }
      },
      "EvidencePackFiles": {
        "type": "object",
        "required": [
          "id",
          "files"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "files": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "name",
                "content"
              ],
              "properties": {
                "name": {
                  "type": "string"
                },
                "content": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "SiteUsage": {
        "type": "object",
        "required": [
          "period",
          "site_id",
          "counted",
          "limit",
          "over_limit_count",
          "at_limit",
          "limit_reached_on"
        ],
        "properties": {
          "period": {
            "type": "string"
          },
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "counted": {
            "type": "integer",
            "minimum": 0
          },
          "limit": {
            "type": "integer",
            "minimum": 1
          },
          "over_limit_count": {
            "type": "integer",
            "minimum": 0
          },
          "at_limit": {
            "type": "boolean"
          },
          "limit_reached_on": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "AccountUsage": {
        "type": "object",
        "required": [
          "period",
          "counted",
          "limit",
          "over_limit_count",
          "at_limit",
          "limit_reached_on",
          "sites"
        ],
        "properties": {
          "period": {
            "type": "string"
          },
          "counted": {
            "type": "integer",
            "minimum": 0
          },
          "limit": {
            "type": "integer",
            "minimum": 1
          },
          "over_limit_count": {
            "type": "integer",
            "minimum": 0
          },
          "at_limit": {
            "type": "boolean"
          },
          "limit_reached_on": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "sites": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/SiteUsage"
            }
          }
        }
      },
      "Scan": {
        "type": "object",
        "required": [
          "id",
          "url",
          "final_url",
          "status",
          "couldnt_check",
          "created_at",
          "completed_at",
          "expires_at",
          "poll_after_ms",
          "passes",
          "checks",
          "observations",
          "engine"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "url": {
            "type": "string"
          },
          "final_url": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "completed",
              "couldnt_check"
            ]
          },
          "couldnt_check": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/CouldntCheck"
              },
              {
                "type": "null"
              }
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "completed_at": {
            "oneOf": [
              {
                "type": "string",
                "format": "date-time"
              },
              {
                "type": "null"
              }
            ]
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          },
          "poll_after_ms": {
            "oneOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ]
          },
          "passes": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Pass"
            }
          },
          "checks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Check"
            }
          },
          "observations": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Observations"
              },
              {
                "type": "null"
              }
            ]
          },
          "engine": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Engine"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "CouldntCheck": {
        "type": "object",
        "required": [
          "reason",
          "message",
          "fix"
        ],
        "description": "The site wasn't checked. This says nothing about the site either way; never shown as clean.",
        "properties": {
          "reason": {
            "type": "string",
            "enum": [
              "blocked",
              "unreachable",
              "timeout",
              "not_html",
              "http_error",
              "too_large",
              "refused_address",
              "opted_out",
              "scanner_paused",
              "failed"
            ]
          },
          "message": {
            "type": "string"
          },
          "fix": {
            "type": "string"
          }
        }
      },
      "Pass": {
        "type": "object",
        "required": [
          "pass",
          "outcome",
          "control_text"
        ],
        "properties": {
          "pass": {
            "type": "string",
            "enum": [
              "load",
              "reject",
              "accept"
            ]
          },
          "outcome": {
            "type": "string"
          },
          "control_text": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "Check": {
        "type": "object",
        "required": [
          "id",
          "outcome",
          "reason",
          "evidence",
          "rests_on",
          "settled",
          "positions",
          "explanation"
        ],
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              "trackers_before_choice",
              "trackers_after_reject",
              "no_banner_with_trackers",
              "reject_harder_than_accept",
              "consent_by_continuing",
              "preticked_choices",
              "consent_mode_granted_before_choice",
              "no_withdraw_route",
              "no_privacy_notice_link",
              "no_notice_at_form",
              "no_grievance_contact"
            ]
          },
          "outcome": {
            "type": "string",
            "enum": [
              "seen",
              "not_seen",
              "couldnt_check"
            ]
          },
          "reason": {
            "oneOf": [
              {
                "type": "string",
                "enum": [
                  "no_banner",
                  "banner_in_frame",
                  "no_reject_control",
                  "no_accept_control",
                  "reject_click_failed",
                  "accept_click_failed",
                  "pass_failed",
                  "capture_truncated",
                  "choices_not_visible"
                ]
              },
              {
                "type": "null"
              }
            ]
          },
          "evidence": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            },
            "description": "What was seen: requests (host and path), cookie and storage names, elements. Never values."
          },
          "rests_on": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/RowRef"
            }
          },
          "settled": {
            "type": "string",
            "enum": [
              "clear_from_text",
              "reasonable_reading",
              "uncertain"
            ],
            "description": "POSITIONS.md confidence."
          },
          "positions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "explanation": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/Explanation"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      },
      "RowRef": {
        "type": "object",
        "required": [
          "row",
          "cite",
          "commences"
        ],
        "properties": {
          "row": {
            "type": "string"
          },
          "cite": {
            "type": "string"
          },
          "commences": {
            "type": "string",
            "format": "date"
          }
        }
      },
      "Explanation": {
        "type": "object",
        "required": [
          "text",
          "fix",
          "approved",
          "source"
        ],
        "description": "Approved text from legal-sources/scanner/findings.yaml, shown only once the legal session approves the entry and the approved commit is pinned.",
        "properties": {
          "text": {
            "type": "string",
            "description": "What the finding means: what was seen and why it matters."
          },
          "fix": {
            "type": "string",
            "description": "What to do about it."
          },
          "approved": {
            "type": "string",
            "description": "The legal-sources approval record, e.g. approvals/2026-11-21-findings.md."
          },
          "source": {
            "type": "string",
            "description": "policygrain/legal-sources@<commit>:scanner/findings.yaml"
          }
        }
      },
      "Observations": {
        "type": "object",
        "required": [
          "banner",
          "vendors",
          "unrecognised_hosts",
          "consent_mode",
          "forms"
        ],
        "description": "What was seen, with no claim attached.",
        "properties": {
          "banner": {
            "type": "object",
            "required": [
              "found",
              "tool",
              "in_frame",
              "controls"
            ],
            "properties": {
              "found": {
                "type": "boolean"
              },
              "tool": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "in_frame": {
                "type": "boolean"
              },
              "controls": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          },
          "vendors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "vendor",
                "name",
                "category",
                "passes"
              ],
              "properties": {
                "vendor": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "category": {
                  "type": "string"
                },
                "passes": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "load",
                      "reject",
                      "accept"
                    ]
                  }
                }
              }
            }
          },
          "unrecognised_hosts": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "maxItems": 50
          },
          "consent_mode": {
            "type": "object",
            "required": [
              "seen",
              "before_choice"
            ],
            "properties": {
              "seen": {
                "type": "boolean"
              },
              "before_choice": {
                "oneOf": [
                  {
                    "type": "string"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          },
          "forms": {
            "type": "integer"
          }
        }
      },
      "Engine": {
        "type": "object",
        "required": [
          "version",
          "vendors",
          "catalogue",
          "register"
        ],
        "properties": {
          "version": {
            "type": "string"
          },
          "vendors": {
            "type": "string"
          },
          "catalogue": {
            "type": "string"
          },
          "register": {
            "type": "string"
          }
        }
      },
      "Handoff": {
        "type": "object",
        "required": [
          "token",
          "url",
          "expires_at"
        ],
        "properties": {
          "token": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Suggestion": {
        "type": "object",
        "required": [
          "question",
          "value",
          "source",
          "because"
        ],
        "description": "A suggested questionnaire answer the person confirms or changes (V1-SPEC §4). Question ids are provisional until T-07.",
        "properties": {
          "question": {
            "type": "string"
          },
          "value": {
            "oneOf": [
              {
                "type": "string"
              },
              {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            ]
          },
          "source": {
            "const": "agent_inferred"
          },
          "because": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Vendor ids."
          }
        }
      },
      "Redeemed": {
        "type": "object",
        "required": [
          "scan",
          "suggestions"
        ],
        "properties": {
          "scan": {
            "$ref": "#/components/schemas/Scan"
          },
          "suggestions": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Suggestion"
            }
          }
        }
      },
      "VerifyStartInput": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "description": "Optional https:// URL on one of the site's verified domains. Defaults to the first verified domain."
          }
        }
      },
      "VerificationSignal": {
        "type": "object",
        "required": [
          "id",
          "outcome",
          "detail"
        ],
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              "banner_loader_request",
              "banner_rendered",
              "trackers_before_choice",
              "trackers_after_reject",
              "withdraw_route",
              "privacy_notice_link"
            ]
          },
          "outcome": {
            "type": "string",
            "enum": [
              "seen",
              "not_seen",
              "couldnt_check"
            ]
          },
          "detail": {
            "type": "string"
          }
        }
      },
      "ScanDiff": {
        "type": "object",
        "required": [
          "baseline",
          "has_regressions",
          "has_changes",
          "new_pre_consent_vendors",
          "new_pre_consent_hosts",
          "new_post_reject_requests",
          "reject_parity_broken",
          "reject_parity_regressions",
          "notice_or_grievance_missing",
          "new_findings",
          "resolved_findings",
          "summary"
        ],
        "properties": {
          "baseline": {
            "type": "string",
            "enum": [
              "present",
              "none",
              "incomplete"
            ]
          },
          "has_regressions": {
            "type": "boolean"
          },
          "has_changes": {
            "type": "boolean"
          },
          "new_pre_consent_vendors": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "new_pre_consent_hosts": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "new_post_reject_requests": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "reject_parity_broken": {
            "type": "boolean"
          },
          "reject_parity_regressions": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "notice_or_grievance_missing": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "new_findings": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "resolved_findings": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "summary": {
            "type": "object",
            "required": [
              "regressions_count",
              "resolved_count",
              "new_pre_consent_vendor_count",
              "new_post_reject_request_count"
            ],
            "properties": {
              "regressions_count": {
                "type": "integer"
              },
              "resolved_count": {
                "type": "integer"
              },
              "new_pre_consent_vendor_count": {
                "type": "integer"
              },
              "new_post_reject_request_count": {
                "type": "integer"
              }
            }
          }
        }
      },
      "Verification": {
        "type": "object",
        "required": [
          "id",
          "site_id",
          "url",
          "status",
          "created_at",
          "completed_at",
          "previous_check_id",
          "diff",
          "result"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "url": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "completed",
              "couldnt_check"
            ]
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "completed_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "previous_check_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "diff": {
            "oneOf": [
              {
                "$ref": "#/components/schemas/ScanDiff"
              },
              {
                "type": "null"
              }
            ]
          },
          "result": {
            "type": [
              "object",
              "null"
            ]
          }
        }
      },
      "VerificationList": {
        "type": "object",
        "required": [
          "verifications"
        ],
        "properties": {
          "verifications": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Verification"
            }
          }
        }
      },
      "VerificationDiff": {
        "type": "object",
        "required": [
          "verification_id",
          "site_id",
          "previous_check_id",
          "status",
          "diff"
        ],
        "properties": {
          "verification_id": {
            "type": "string",
            "format": "uuid"
          },
          "site_id": {
            "type": "string",
            "format": "uuid"
          },
          "previous_check_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "running",
              "completed",
              "couldnt_check"
            ]
          },
          "diff": {
            "$ref": "#/components/schemas/ScanDiff"
          }
        }
      },
      "BillingPlan": {
        "type": "object",
        "required": [
          "id",
          "name",
          "description",
          "currency",
          "monthly_paise",
          "annual_paise",
          "monthly_inr",
          "annual_inr",
          "gst_exclusive",
          "monthly_receipt_export_limit",
          "max_sites",
          "drift_monitoring",
          "priority_export",
          "documents_included",
          "receipt_ingestion_blocked"
        ],
        "properties": {
          "id": {
            "type": "string",
            "enum": [
              "free",
              "pro",
              "agency"
            ]
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "currency": {
            "type": "string",
            "enum": [
              "INR"
            ]
          },
          "monthly_paise": {
            "type": "integer",
            "minimum": 0
          },
          "annual_paise": {
            "type": "integer",
            "minimum": 0
          },
          "monthly_inr": {
            "type": "integer",
            "minimum": 0
          },
          "annual_inr": {
            "type": "integer",
            "minimum": 0
          },
          "gst_exclusive": {
            "type": "boolean"
          },
          "monthly_receipt_export_limit": {
            "type": "integer",
            "minimum": 1
          },
          "max_sites": {
            "type": "integer",
            "minimum": 1
          },
          "drift_monitoring": {
            "type": "string",
            "enum": [
              "manual",
              "weekly",
              "daily"
            ]
          },
          "priority_export": {
            "type": "boolean"
          },
          "documents_included": {
            "type": "boolean"
          },
          "receipt_ingestion_blocked": {
            "type": "boolean"
          }
        }
      },
      "BillingPlansCatalog": {
        "type": "object",
        "required": [
          "currency",
          "gst_rate_percent",
          "sac_code",
          "supplier_state_code",
          "supplier_state_name",
          "tax_rule",
          "receipt_ingestion_blocked_ever",
          "plans"
        ],
        "properties": {
          "currency": {
            "type": "string",
            "enum": [
              "INR"
            ]
          },
          "gst_rate_percent": {
            "type": "integer"
          },
          "sac_code": {
            "type": "string"
          },
          "supplier_state_code": {
            "type": "string"
          },
          "supplier_state_name": {
            "type": "string"
          },
          "tax_rule": {
            "type": "string"
          },
          "receipt_ingestion_blocked_ever": {
            "type": "boolean"
          },
          "plans": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BillingPlan"
            }
          }
        }
      },
      "BillingSubscription": {
        "type": "object",
        "required": [
          "id",
          "plan",
          "billing_cycle",
          "status",
          "razorpay_subscription_id",
          "razorpay_plan_id",
          "short_url",
          "buyer_legal_name",
          "buyer_gstin",
          "buyer_state_code",
          "current_period_start",
          "current_period_end",
          "grace_until",
          "cancel_at_period_end",
          "cancelled_at",
          "created_at",
          "updated_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "plan": {
            "type": "string",
            "enum": [
              "free",
              "pro",
              "agency"
            ]
          },
          "billing_cycle": {
            "type": "string",
            "enum": [
              "monthly",
              "annual"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "created",
              "authenticated",
              "active",
              "pending",
              "halted",
              "cancelled",
              "completed",
              "expired"
            ]
          },
          "razorpay_subscription_id": {
            "type": "string"
          },
          "razorpay_plan_id": {
            "type": "string"
          },
          "short_url": {
            "type": [
              "string",
              "null"
            ]
          },
          "buyer_legal_name": {
            "type": [
              "string",
              "null"
            ]
          },
          "buyer_gstin": {
            "type": [
              "string",
              "null"
            ]
          },
          "buyer_state_code": {
            "type": "string"
          },
          "current_period_start": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "current_period_end": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "grace_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "cancel_at_period_end": {
            "type": "boolean"
          },
          "cancelled_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "BillingEntitlements": {
        "type": "object",
        "required": [
          "plan",
          "plan_name",
          "max_sites",
          "monthly_receipt_export_limit",
          "drift_monitoring",
          "priority_export",
          "documents_included",
          "receipt_ingestion_blocked",
          "in_grace_period",
          "grace_until",
          "subscription"
        ],
        "properties": {
          "plan": {
            "type": "string",
            "enum": [
              "free",
              "pro",
              "agency"
            ]
          },
          "plan_name": {
            "type": "string"
          },
          "max_sites": {
            "type": "integer",
            "minimum": 1
          },
          "monthly_receipt_export_limit": {
            "type": "integer",
            "minimum": 1
          },
          "drift_monitoring": {
            "type": "string",
            "enum": [
              "manual",
              "weekly",
              "daily"
            ]
          },
          "priority_export": {
            "type": "boolean"
          },
          "documents_included": {
            "type": "boolean"
          },
          "receipt_ingestion_blocked": {
            "type": "boolean"
          },
          "in_grace_period": {
            "type": "boolean"
          },
          "grace_until": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "subscription": {
            "type": [
              "object",
              "null"
            ]
          }
        }
      },
      "CreateSubscriptionInput": {
        "type": "object",
        "required": [
          "plan"
        ],
        "properties": {
          "plan": {
            "type": "string",
            "enum": [
              "pro",
              "agency",
              "growth"
            ],
            "description": "pro or agency; growth (the first v1.5 name) is accepted and stored as pro"
          },
          "billing_cycle": {
            "type": "string",
            "enum": [
              "monthly",
              "annual"
            ]
          },
          "buyer_legal_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "buyer_gstin": {
            "type": "string",
            "pattern": "^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z][1-9A-Z]Z[0-9A-Z]$"
          },
          "buyer_state_code": {
            "type": "string",
            "pattern": "^[0-9]{2}$"
          }
        }
      },
      "SubscriptionCheckoutResponse": {
        "type": "object",
        "required": [
          "subscription",
          "mode",
          "entitlement_granted",
          "tax_preview"
        ],
        "properties": {
          "subscription": {
            "$ref": "#/components/schemas/BillingSubscription"
          },
          "mode": {
            "type": "string",
            "enum": [
              "test",
              "live"
            ]
          },
          "entitlement_granted": {
            "type": "boolean"
          },
          "tax_preview": {
            "type": "object",
            "required": [
              "tax_mode",
              "taxable_paise",
              "cgst_paise",
              "sgst_paise",
              "igst_paise",
              "total_paise",
              "total_formatted"
            ],
            "properties": {
              "tax_mode": {
                "type": "string",
                "enum": [
                  "intra_state",
                  "inter_state"
                ]
              },
              "taxable_paise": {
                "type": "integer"
              },
              "cgst_paise": {
                "type": "integer"
              },
              "sgst_paise": {
                "type": "integer"
              },
              "igst_paise": {
                "type": "integer"
              },
              "total_paise": {
                "type": "integer"
              },
              "total_formatted": {
                "type": "string"
              }
            }
          }
        }
      },
      "CancelSubscriptionInput": {
        "type": "object",
        "properties": {
          "cancel_at_period_end": {
            "type": "boolean",
            "default": true
          }
        }
      },
      "SubscriptionEnvelope": {
        "type": "object",
        "required": [
          "subscription"
        ],
        "properties": {
          "subscription": {
            "$ref": "#/components/schemas/BillingSubscription"
          }
        }
      },
      "BillingInvoice": {
        "type": "object",
        "required": [
          "id",
          "subscription_id",
          "invoice_number",
          "financial_year",
          "sequence_number",
          "issued_at",
          "period_start",
          "period_end",
          "plan",
          "billing_cycle",
          "sac_code",
          "currency",
          "supplier",
          "buyer",
          "tax_mode",
          "taxable_paise",
          "cgst_rate_bps",
          "sgst_rate_bps",
          "igst_rate_bps",
          "cgst_paise",
          "sgst_paise",
          "igst_paise",
          "total_paise",
          "total_formatted",
          "razorpay_payment_id",
          "razorpay_invoice_id",
          "line_items",
          "html_url"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "subscription_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          },
          "invoice_number": {
            "type": "string"
          },
          "financial_year": {
            "type": "string"
          },
          "sequence_number": {
            "type": "integer",
            "minimum": 1
          },
          "issued_at": {
            "type": "string",
            "format": "date-time"
          },
          "period_start": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "period_end": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "plan": {
            "type": "string",
            "enum": [
              "pro",
              "agency",
              "starter",
              "growth"
            ],
            "description": "The plan as invoiced; invoices issued under the first v1.5 names keep them"
          },
          "billing_cycle": {
            "type": "string",
            "enum": [
              "monthly",
              "annual"
            ]
          },
          "sac_code": {
            "type": "string"
          },
          "currency": {
            "type": "string",
            "enum": [
              "INR"
            ]
          },
          "supplier": {
            "type": "object"
          },
          "buyer": {
            "type": "object"
          },
          "tax_mode": {
            "type": "string",
            "enum": [
              "intra_state",
              "inter_state"
            ]
          },
          "taxable_paise": {
            "type": "integer",
            "minimum": 0
          },
          "cgst_rate_bps": {
            "type": "integer",
            "minimum": 0
          },
          "sgst_rate_bps": {
            "type": "integer",
            "minimum": 0
          },
          "igst_rate_bps": {
            "type": "integer",
            "minimum": 0
          },
          "cgst_paise": {
            "type": "integer",
            "minimum": 0
          },
          "sgst_paise": {
            "type": "integer",
            "minimum": 0
          },
          "igst_paise": {
            "type": "integer",
            "minimum": 0
          },
          "total_paise": {
            "type": "integer",
            "minimum": 0
          },
          "total_formatted": {
            "type": "string"
          },
          "razorpay_payment_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "razorpay_invoice_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "line_items": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "html_url": {
            "type": "string"
          }
        }
      },
      "BillingInvoiceList": {
        "type": "object",
        "required": [
          "invoices"
        ],
        "properties": {
          "invoices": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BillingInvoice"
            }
          }
        }
      },
      "WebhookAck": {
        "type": "object",
        "required": [
          "received",
          "event_id",
          "event_type",
          "duplicate",
          "ignored",
          "invoice_id"
        ],
        "properties": {
          "received": {
            "type": "boolean"
          },
          "event_id": {
            "type": "string"
          },
          "event_type": {
            "type": "string"
          },
          "duplicate": {
            "type": "boolean"
          },
          "ignored": {
            "type": "boolean"
          },
          "invoice_id": {
            "type": [
              "string",
              "null"
            ],
            "format": "uuid"
          }
        }
      }
    }
  }
}