{
 "openapi": "3.1.0",
 "info": {
  "title": "Martialytics API",
  "version": "2.0.0",
  "description": "REST API for the Martialytics school management platform.\n\n**Authentication**: integrations authenticate with an **API key**: send `X-API-Key: mk_live_…` (canonical) or `Authorization: Bearer mk_live_…` on every request. Keys are created by the school owner in Settings → API & AI, are shown once at creation, and are scoped: full access, or read/write grants per area that follow the staff permissions (students, leads, events, send, webhooks, widgets, attendance, grading, billing, reports, shop, news, waivers, settings, plus read-only reference data). A key resolves your school automatically, can only reach the endpoints documented here, and there is no query-parameter form (keys in URLs leak into logs). Where a record must name a person (a note, a chat message, a webhook) a key acts as the school owner, and the audit log names the key. A key can invite staff within its own reach (the grantable permissions are listed at `GET /v1/school/users/permissions`) and never sets a password. The first-party apps use an admin JWT instead: `POST /v1/auth/login` with email/password, then `Authorization: Bearer <token>`. Exceptions: `/v1/public/*` (URL hash/token auth for public forms), `/v1/kiosk/*` (kiosk device tokens), and `/v1/student-app-portal/*` (student-scoped JWTs).\n\n**Conventions**\n- Every JSON response is enveloped: `{ \"success\": true, \"data\": ... }` on success (with `meta` on lists and writes, where the operation documents it), `{ \"success\": false, \"error\": { code, message } }` on failure. A few operations answer with a file (CSV, iCal, PDF) or a redirect instead, and say so. Creates answer 201, background work 202. Version 2.0.0 is the product generation; every path lives under `/v1`, the first and only path version.\n- Mutations support `?preview=true` dry-runs where the operation documents it. A dry run runs the operation's own checks and writes nothing; the answer has `preview: true`, what would happen in `data`, and a `previewToken` (also in the `X-Preview-Token` response header).\n- To commit, repeat the same request without `preview=true` and with the token in the `X-Preview-Token` header. AI callers must send one, and must show the person the preview and get their yes to it first: a yes given before the preview does not count. Plain integrations may commit without a token; one they send is checked. Copy the token exactly; it lasts 15 minutes.\n- On commit the dry run runs again. If what it finds has changed, nothing is done: 409 with the fresh preview and a new token to show. A missing, mistyped, expired or other request's token is refused with 412. A token commits once: the same token again returns the first answer (header `Preview-Token-Status: replayed`) and nothing runs twice. On an operation without a dry run, `?preview=true` is refused with 400 and nothing runs. Destructive operations require `?confirm=true`.\n- Timestamps are unix seconds. Dates are `YYYY-MM-DD` on the school's calendar (its timezone is in `GET /v1/school/settings`). Date-ranged lists take `from` and `to`.\n- List endpoints paginate with `page`/`limit` (a few with `cursor`, where the operation documents it) and sort with `?sort=field` / `?sort=-field`.\n- Safe retries via the `Idempotency-Key` header on POST/PUT/PATCH: the same key and body within 24 hours returns the stored answer; the same key with a different body is refused 422 `CONFLICT`; the same key sent at once is one write (the others get 409 `IDEMPOTENCY_IN_PROGRESS`); a failure releases the key.\n- `POST /v1/batch` counts against the rate limit once for the batch and once per sub-request.\n- Work that runs in the background (bulk bookings, bulk plan changes, exports, certificate batches) answers 202 with an operation; follow it at `GET /v1/operations/{id}` until its `status` is `completed` or `failed`. A plan's price or tax change answers with a billing job instead (`jobId`), followed at `GET /v1/billing/jobs/{jobId}`. Outbound events (including `send.batch.completed` and `send.message.*`) arrive by webhook, with a delivery log and replay at `/v1/webhooks/{id}/deliveries`.\n- Every operation lists its error codes (`x-error-codes`, and one response per status) and carries generated examples; every mutation carries its risk class (`x-risk`: reversible, irreversible or financial).\n- Conditional requests via `ETag` / `If-None-Match`.\n\n**Machine discovery**: generated from the API's self-describing schema layer: `GET /v1/` lists all modules, `GET /v1/{module}/_schema` returns each module's operations and models as JSON. LLM-friendly markdown: `/llms.txt` (index), `/docs/{module}.md` (per module), `/llms-full.txt` (everything in one file).\n\n**AI assistants (MCP)**: the same API is available to AI tools over the Model Context Protocol at `POST /v1/mcp` on this host (stateless JSON transport; GET answers 405). Authenticate with the same API key as a header; the tools the assistant sees are limited to the key's scopes. Write tools preview first and need `confirm: true` with the preview's `previewToken`; every answer carries `structuredContent` matching the tool's `outputSchema`. Per-client setup, with `<url>` = this host + `/v1/mcp`:\n- **Claude Code**: `claude mcp add --transport http martialytics <url> --header \"Authorization: Bearer <key>\"`\n- **Claude Desktop**: its config file only launches local servers, so bridge with `mcp-remote` (needs Node.js): `{ \"mcpServers\": { \"martialytics\": { \"command\": \"npx\", \"args\": [\"-y\", \"mcp-remote\", \"<url>\", \"--header\", \"Authorization: Bearer ${MARTIALYTICS_KEY}\"], \"env\": { \"MARTIALYTICS_KEY\": \"<key>\" } } } }`\n- **Cursor** (`.cursor/mcp.json`): `{ \"mcpServers\": { \"martialytics\": { \"url\": \"<url>\", \"headers\": { \"Authorization\": \"Bearer <key>\" } } } }`\n- **Codex CLI** (`~/.codex/config.toml`): `[mcp_servers.martialytics]` with `url = \"<url>\"` and `bearer_token_env_var = \"MARTIALYTICS_KEY\"`, then `export MARTIALYTICS_KEY=\"<key>\"` in your shell\n\nThe \"Add custom connector\" screens in claude.ai, Claude Desktop and ChatGPT only accept servers that sign in with OAuth, which Martialytics does not offer; use the config-file route above. Settings → API & AI shows these snippets with your key filled in when a key is created.\n\n**Rate limits**: API-key requests are tiered (free 20/min, basic 60/min, pro 120/min, enterprise 600/min) with standard `X-RateLimit-*` headers. MCP tool calls (`/v1/mcp` tools/call) draw from their own per-key window at 5x the tier's per-minute allowance; a rejected call comes back as a tool error stating how many seconds to wait."
 },
 "servers": [
  {
   "url": "https://api.mtly.app"
  }
 ],
 "tags": [
  {
   "name": "auth",
   "description": "Authentication and session management. Login with email/password to receive a JWT bearer token. Tokens expire and can be refreshed. Password reset via email flow."
  },
  {
   "name": "students",
   "description": "Student lifecycle management, the core module. CRUD operations, attendance history, rank progression, waivers, files, notes, billing, family links, and trial-to-member conversion. Supports bulk operations, CSV export, and full preview/confirm patterns."
  },
  {
   "name": "attendance",
   "description": "Check-in/check-out operations for student attendance tracking. Supports single and bulk check-ins, kiosk mode for recent attendees, and today's attendance summary."
  },
  {
   "name": "grading",
   "description": "Rank progression management. Promote students through belt/rank levels, track skill scores, and manage grading dates and notes."
  },
  {
   "name": "workflows",
   "description": "Multi-step workflows in one call (create student + assign plan + send waiver, lead conversion, check-in, promotion) returning a plain summary alongside structured data. Every operation is a preview-first write: without ?confirm=true it validates and answers with preview: true and nothing changes, the same as ?preview=true; with ?confirm=true it runs."
  },
  {
   "name": "families",
   "description": "Family grouping for related students. Create families, manage members (students of the school; a family has no non-student contacts of its own), track family-level billing, and add notes."
  },
  {
   "name": "tags",
   "description": "Tag management for categorising students. Tags are school-scoped labels that can be assigned to students for filtering and organisation."
  },
  {
   "name": "operations",
   "description": "The school's queued long runs: a bulk plan assign, a plan migration, a price or tax change, a bulk booking, a chat broadcast, a certificate batch, an export. Each row carries its progress and one result per student. Rows are shown by their type's permission."
  },
  {
   "name": "statuses",
   "description": "Status management for categorising students. Statuses are school-scoped labels like 'Student', 'Instructor', or 'Trial' that can be assigned to students."
  },
  {
   "name": "clubs",
   "description": "Club management for grouping students. Clubs are school-scoped groups like 'Weapons', 'Competition Team', or 'Kids Class' that students can be assigned to."
  },
  {
   "name": "locations",
   "description": "Location/venue management for schools. Locations represent physical training venues that can be assigned to classes and events."
  },
  {
   "name": "skills",
   "description": "Skill management for curriculum. Skills are techniques/forms that can be assigned to ranks as requirements."
  },
  {
   "name": "styles",
   "description": "Style and rank management for martial arts curriculum. Styles (e.g., 'BJJ', 'Taekwondo') contain ordered ranks (e.g., 'White Belt', 'Yellow Belt'). Each rank can have colors, stripe patterns, grading requirements, and associated skills."
  },
  {
   "name": "waivers",
   "description": "Waiver (contract) management. Each waiver has metadata + an immutable version history; the current published version supplies body HTML and field definitions for signing. Supports both native (rich text) and uploaded_pdf source types. Idempotency-Key headers are honoured globally for unsafe methods."
  },
  {
   "name": "certificates",
   "description": "Grading certificate templates and PDF rendering. Each school owns N templates (e.g. Adults, Kids) backed by one of 10 designed base templates. Renders are atomic + cached by (promotion, template)."
  },
  {
   "name": "study",
   "description": "Rank-tied curriculum content (PDFs, images, external video links) managed per martial-art style."
  },
  {
   "name": "events",
   "description": "Calendar and booking management. Create recurring or single events, manage class rosters (enrollments), handle drop-in bookings, track attendance and no-shows. Integrates with PAYG billing."
  },
  {
   "name": "calendar",
   "description": "Read-only calendar views. Expands recurring events into occurrences, applies exceptions, and aggregates booking/enrollment counts."
  },
  {
   "name": "billing",
   "description": "Billing management for schools. Handles billing plans (recurring, passes, one-time), student subscriptions, transactions, and payment gateway integration (Stripe, GoCardless, local/cash). All monetary amounts are in cents. All dates are Unix timestamps (seconds)."
  },
  {
   "name": "invoices",
   "description": "Line-item invoices sent to a student (or their guardian) from the Pay button: free-text lines, a due date, and a per-school sequential number (INV-0042). Paid online via the public link, marked paid offline, or collected against a GoCardless mandate. The system tracks draft/sent/paid/overdue/cancelled and nudges on overdue."
  },
  {
   "name": "shop",
   "description": "Shop management: catalogue (categories, products with matrix variants, stock) and the order and refund lifecycle (point-of-sale orders, refunds, receipts)."
  },
  {
   "name": "leads",
   "description": "Lead pipeline CRM. Manage leads through Kanban stages (New, Contacted, Trial, then Won or Lost). Supports temperature tracking, activity timeline, reminders, and stage-aware state transitions (trial start, conversion, loss)."
  },
  {
   "name": "onetouch",
   "description": "One-Touch form management for OTSU (signup) and OTCO (checkout) forms. Build public-facing registration and checkout pages with style, venue, plan, and waiver linkage."
  },
  {
   "name": "widgets",
   "description": "Admin configuration for the public Lead Capture, Class Bookings, and Online Shop widgets that schools embed on their websites. Returns settings + ready-to-paste embed code in one call."
  },
  {
   "name": "dashboard",
   "description": "Dashboard widgets: actionable nudges, student lifecycle stats, and upcoming classes with notable student tracking."
  },
  {
   "name": "reports",
   "description": "School analytics: ten lenses (summary, income, payments, growth, retention, churn, curriculum, grading, attendance, demographics) of read-only aggregate endpoints. Every endpoint accepts the same filters (from/to dates, venueId, asOf anchor) and returns structured aggregates. The overview endpoint reads a precomputed snapshot (refreshed nightly); lens endpoints are live. Per-lens permission gates (REPORT_LENSES ids); the income lens guards all monetary data."
  },
  {
   "name": "news",
   "description": "News article publishing for school-to-student communication. Articles support scheduled publish windows, visibility toggling, and (in later phases) hero images and push notifications on publish. Wraps the legacy `school_news` table: existing legacy articles continue to render unchanged."
  },
  {
   "name": "send",
   "description": "Communication core: inline send (email/SMS/push), broadcast scheduling, draft CRUD, asset upload, merge tags, delivery log, email preview. Sub-modules (each with its own _schema): send-automations, send-chat, send-social, send-segments, send-analytics, send-library, send-templates, send-credits, send-marketplace, send-share-import, send-system, send-suppression."
  },
  {
   "name": "send/automations",
   "description": "Event-driven or scheduled workflows that automatically send messages, update records, and perform actions for enrolled students. System automations are read-only."
  },
  {
   "name": "send-chat",
   "description": "1:1 admin and student chat, plus website visitor threads (student null, visitor block): real-time messaging with SSE, VAPID push for admins, and typing / read-receipt support."
  },
  {
   "name": "send-social",
   "description": "Social Suite: connect Facebook Pages + Instagram Business accounts, publish/schedule posts, maintain a per-school media library. Facebook and Instagram only."
  },
  {
   "name": "send-segments",
   "description": "Smart segment definitions for the Send module. Segments evaluate dynamic filter rules against the student population and drive targeted sends + segment_entry automation triggers. Rule trees follow the RuleTree model below; see GET /v1/send/segments/fields for queryable fields and GET /v1/send/segments/capabilities for which categories of fields have data for this school."
  },
  {
   "name": "send-analytics",
   "description": "Delivery stats, per-channel breakdowns, automation funnels, per-student communication scores, and a schedule of upcoming sends with iCal export. All range queries default to the last 30 days; max range 365 days. Responses cached 5 minutes."
  },
  {
   "name": "send-library",
   "description": "Platform-curated automation blueprints. Schools browse and import into their own automations as drafts. Imports are deep copies: editing an imported automation doesn't affect the blueprint, and blueprint updates don't touch already-imported automations. A second import of the same blueprint without an `idempotencyKey` returns the automation already imported, with `alreadyInstalled: true`; pass a distinct `idempotencyKey` to hold more than one copy (for same-blueprint variations with different names or recipients)."
  },
  {
   "name": "send/templates",
   "description": "Reusable email/SMS/chat/social message templates. For email channel, content is a JSON-serialized EmailDocument (see EmailDocument model in GET /v1/send/_schema). For sms/chat/social, content is plain text. All channels support `{{merge_tag}}` placeholders (use POST /v1/send/templates/validate to check shape + tag resolution before saving). System templates split into two flavours: curated-library system rows (`isSystem=true` AND `templateKey=null`) are read-only (duplicate to edit); auto-seeded defaults (`isSystem=true` AND `templateKey` non-null) are per-school editable copies of platform defaults (e.g. public-bookings confirmation copy) and can be PATCHed, DELETEd (soft), and RESET via POST /:id/reset."
  },
  {
   "name": "send-credits",
   "description": "SMS credit balance, in-modal top-up on the platform-billing rails (saved card one-click or inline card entry, priced server-side), auto-recharge config, and transaction history. Purchases fulfil SYNCHRONOUSLY (grant keyed on the PaymentIntent id); the platform Stripe webhook is a backstop for 3DS-return and delayed outcomes."
  },
  {
   "name": "send-marketplace",
   "description": "School-to-school automation sharing, curated by Martialytics moderators. Distinct from /v1/send/share-imports (the viewer side of the per-automation public-share viral loop); this is the browsable, moderated catalogue. Publishers submit automations (5/school/24h cap); moderators approve; other schools browse and import. Listings are shape-deduplicated on publish (same trigger + audience + step-type sequence collapses). Imports deep-copy the trigger + steps into the importer's account as a DRAFT automation, with per-listing idempotency (re-importing returns reused=true rather than duplicating). Self-imports (publisher == importer) are blocked with 409."
  },
  {
   "name": "send-share-import",
   "description": "Cross-school import of automations shared via the marketplace viral loop. The viewer's side of the share-link flow: a slug from someone else's /v1/send/automations/:id/share toggle resolves here. GET returns a shape-only preview (trigger label + step labels, no step config); POST deep-clones the automation into the caller's school as a DRAFT. Per-importer rate-limited at 5 imports per rolling 7-day window. Self-imports (publisher == importer) are blocked with 409. Distinct from /v1/send/library/:id/import (platform-curated blueprints); this is school-to-school sharing."
  },
  {
   "name": "send-system",
   "description": "Martialytics-maintained system automations (morning briefing, weekly/monthly reports, instructor prep + class reminder). Definitions are platform-level; schools enable/disable, reschedule, and reconfigure recipients but cannot structurally alter them. A school row is materialized on first enable."
  },
  {
   "name": "send-suppression",
   "description": "Addresses the school must never send to again. Populated automatically from hard bounces and spam complaints; admins can add 'manual' entries. Removal is soft (sets removed_on) so history is preserved."
  },
  {
   "name": "school",
   "description": "School configuration: settings (general/branding/kiosk/notifications), logo/content image uploads, and PAYG billing config. Users, account, integrations and lead-stages are federated as their own modules (school-users, school-account, school-integrations, lead-stages)."
  },
  {
   "name": "school-users",
   "description": "Sub-account (staff login) management. Every route requires the PRIMARY account or an API key; sub-accounts cannot manage other sub-accounts. Permissions are granular ids: GET /v1/school/users/permissions lists each with its area, name and meaning; the primary account implicitly holds everything."
  },
  {
   "name": "lead-stages",
   "description": "Pipeline stage management for lead CRM. Stages define the Kanban columns (New, Contacted, Trial, then Won or Lost). Schools can add/rename/reorder custom stages. System stages (New, Won, Lost) cannot be deleted."
  },
  {
   "name": "webhooks",
   "description": "Webhook registration and management. Subscribe to domain events (student, attendance, billing, waiver, shop, etc.) and receive HTTP POST callbacks when they occur. Waiver events (waiver.signed, waiver.requested, waiver.signature.declined, etc.) ship with resolved field responses, signer identity, and the signed version number in addition to the raw event payload. Downstream systems do not need a follow-up API call to inspect the signature. Shop order events (shop.order.created, shop.order.statusChanged, shop.order.refunded) ship with the full order attached under `order` (customer, line items with product and option snapshots, refunds), so a stock-reorder or bookkeeping integration needs no follow-up call either. Every delivery is a POST whose JSON body is { event, data, timestamp (ISO 8601), webhookId }, and a replay adds replayOf (the delivery it repeats). The headers are X-Webhook-Signature (hex HMAC-SHA256 of the raw body with the webhook's secret), X-Webhook-Event, X-Webhook-Id, X-Webhook-Delivery (the id receivers dedupe on; a retry repeats it) and X-Webhook-Attempt. The event names are the domain events (student.created, student.updated, student.archived, lead.created, lead.stageChanged, lead.converted, attendance.checkedIn, booking.confirmed, booking.cancelled, billing.payment.succeeded, billing.payment.failed, billing.subscription.created, billing.invoice.created, waiver.signed, shop.order.created, send.batch.completed, send.message.delivered, tag.created, class.created and the rest of their families; eventsCatalog lists every one). The data is each event's own payload: ids at the least (tag.created carries { tagId, schoolId }), the full record where the event says so."
  },
  {
   "name": "batch",
   "description": "Execute multiple API operations in a single HTTP request. Each operation runs independently (not transactional) with the same auth context. Max 20 operations per batch."
  },
  {
   "name": "student-insight",
   "description": "Class-roster context for a dated class occurrence: who is checked in, expected or eligible, and deterministic, explainable signals worth knowing before speaking to a student (first class, return after absence, attendance decline, milestone, recent note). Rule-based; nothing here is a prediction. Restricted context (notes, retention, billing) is included only when the caller holds that permission."
  }
 ],
 "paths": {
  "/v1/auth/login": {
   "post": {
    "operationId": "auth_login",
    "summary": "login",
    "description": "Authenticate with email and password. Returns access token (JWT) and refresh token.",
    "tags": [
     "auth"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/auth.AuthTokens"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "accessToken": "string",
          "refreshToken": "string",
          "expiresIn": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "email": {
          "type": "string",
          "description": "User email address",
          "format": "email"
         },
         "password": {
          "type": "string",
          "description": "User password"
         }
        },
        "required": [
         "email",
         "password"
        ]
       },
       "example": {
        "email": "jo@example.com",
        "password": "string"
       }
      }
     }
    }
   }
  },
  "/v1/auth/refresh": {
   "post": {
    "operationId": "auth_refresh",
    "summary": "refresh",
    "description": "Exchange a refresh token for a new access token. Answers 503 SERVICE_UNAVAILABLE, not 401, when the session cannot be checked for the moment: keep the token and try again shortly.",
    "tags": [
     "auth"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/auth.AuthTokens"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "accessToken": "string",
          "refreshToken": "string",
          "expiresIn": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE, SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "refreshToken": {
          "type": "string",
          "description": "Refresh token from login response"
         }
        },
        "required": [
         "refreshToken"
        ]
       },
       "example": {
        "refreshToken": "string"
       }
      }
     }
    }
   }
  },
  "/v1/auth/logout": {
   "post": {
    "operationId": "auth_logout",
    "summary": "logout",
    "description": "Revoke the current refresh token",
    "tags": [
     "auth"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "refreshToken": {
          "type": "string",
          "description": "Refresh token to revoke"
         }
        },
        "required": [
         "refreshToken"
        ]
       },
       "example": {
        "refreshToken": "string"
       }
      }
     }
    }
   }
  },
  "/v1/auth/forgot-password": {
   "post": {
    "operationId": "auth_forgotPassword",
    "summary": "forgotPassword",
    "description": "Request a password reset email",
    "tags": [
     "auth"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "email": {
          "type": "string",
          "description": "Email address for reset",
          "format": "email"
         }
        },
        "required": [
         "email"
        ]
       },
       "example": {
        "email": "jo@example.com"
       }
      }
     }
    }
   }
  },
  "/v1/auth/reset-password": {
   "post": {
    "operationId": "auth_resetPassword",
    "summary": "resetPassword",
    "description": "Reset password using token from email",
    "tags": [
     "auth"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "token": {
          "type": "string",
          "description": "Reset token from email link"
         },
         "password": {
          "type": "string",
          "description": "New password",
          "minLength": 8
         }
        },
        "required": [
         "token",
         "password"
        ]
       },
       "example": {
        "token": "string",
        "password": "stringxx"
       }
      }
     }
    }
   }
  },
  "/v1/auth/me": {
   "get": {
    "operationId": "auth_me",
    "summary": "me",
    "description": "Get current authenticated user info including permissions",
    "tags": [
     "auth"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/auth.CurrentUser"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "email": "string",
          "firstName": "string",
          "lastName": "string",
          "schoolId": 1,
          "permissions": [
           1
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students": {
   "get": {
    "operationId": "students_list",
    "summary": "list",
    "description": "List students with filtering, sorting, and pagination. Supports complex filters by status, tags, ranks, styles, active state, and search.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/students.Student"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "firstName": "string",
           "lastName": "string",
           "emailAddress": "jo@example.com",
           "mobileNumber": "string",
           "isActive": 0,
           "isLead": 0,
           "isTrial": 0,
           "trialStartedOn": "2026-11-05",
           "trialExpiresOn": "2026-11-05",
           "trialClassesLimit": 1,
           "trialClassesUsed": 1,
           "joinedOn": "2026-11-05",
           "birthday": "2026-11-05",
           "memberNumber": "string",
           "lastSeenOn": 1793836800,
           "planStatus": "active",
           "passesRemaining": 1,
           "currentRank": {},
           "ranks": [],
           "tags": [],
           "status": {},
           "familyId": 1,
           "familyName": "string",
           "photoUrl": "string",
           "photoStorageKey": "string",
           "signupFormName": "string",
           "contractExpiresOn": "2026-11-05",
           "venueIds": [
            1
           ],
           "deletedOn": 1793836800,
           "archivedOn": 1793836800
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "Page number"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Items per page (max 10000)"
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Sort field; prefix with - for descending. Unknown values fall back to lastName ascending. Allowed fields: firstName, -firstName, lastName, -lastName, joinedOn, -joinedOn, lastAttendance, -lastAttendance, birthday, -birthday, contractExpiry, -contractExpiry"
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Search by name, email (primary, alternate or a contact's), mobile or member number. Email and phone terms apply only when the caller may see those fields (Email 24, Phone 25); % and _ are literal."
     },
     {
      "name": "ids",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Restrict to these student IDs (comma-separated)"
     },
     {
      "name": "statusTypes",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Student type filter (comma-separated). These four are mutually exclusive and exhaustive over the live roster, so they sum to the unfiltered total. 'active' means an Active Student (is_active=1, is_lead=0, is_trial=0), NOT merely enabled: a Lead and a Trial are also is_active=1. An unrecognised value is rejected with 400 rather than ignored. Pending students are NOT here: they are not students yet, they are rows in student_information_request awaiting approval. See GET /v1/students/pending. Allowed fields: leads, trials, active, inactive"
     },
     {
      "name": "archived",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "List the ARCHIVED students (deleted/archived records) instead of the live roster, newest archived first; each row carries archivedOn. The status filters do not apply to it. Restore one with POST /v1/students/:id/restore."
     },
     {
      "name": "isActive",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Legacy single-status filter. Prefer statusTypes; this one also excludes leads and trials."
     },
     {
      "name": "isLead",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Legacy filter, leads only. Prefer statusTypes=leads."
     },
     {
      "name": "isTrial",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Legacy filter, trials only. Prefer statusTypes=trials."
     },
     {
      "name": "venueIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by venue IDs (comma-separated)"
     },
     {
      "name": "styleIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by style IDs (comma-separated)"
     },
     {
      "name": "rankIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by rank IDs (comma-separated)"
     },
     {
      "name": "tagIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by tag IDs (comma-separated)"
     },
     {
      "name": "onetouchIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "filter by One Touch Sign Up form IDs (comma-separated): students who signed up through any of them. Each row carries signupFormName."
     },
     {
      "name": "statusIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by school-defined status category IDs (comma-separated)"
     },
     {
      "name": "planIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by billing plan IDs (comma-separated)"
     },
     {
      "name": "waiverIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter to students who have SIGNED the given waivers (comma-separated IDs). Signed means status='signed', or a legacy row carrying signed_on; pending, viewed, declined, expired and voided rows do not count as coverage. Multiple ids OR together."
     },
     {
      "name": "hasNoPlan",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Only students with no billing plan assigned"
     },
     {
      "name": "hasPlanOverdue",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Only students whose plan is overdue"
     },
     {
      "name": "gradingStatus",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Grading eligibility (comma-separated) Allowed fields: ready, almost, notReady"
     },
     {
      "name": "receiveEmail",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "true = only students who accept email, false = only those who have opted out. Omit for no filter."
     },
     {
      "name": "receiveSms",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "true = only students who accept SMS, false = only those who have opted out. Omit for no filter."
     },
     {
      "name": "receiveChat",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "true = only students who accept chat, false = only those who have opted out. Omit for no filter."
     },
     {
      "name": "ageMin",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Minimum age in years. Needs the Birthday (10) sub-permission, as does sort=birthday; refused 403 otherwise."
     },
     {
      "name": "ageMax",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Maximum age in years. Needs the Birthday (10) sub-permission; refused 403 otherwise."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "students_create",
    "summary": "create",
    "description": "Create a new student",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/students.Student"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "jo@example.com",
            "mobileNumber": "string",
            "isActive": 0,
            "isLead": 0,
            "isTrial": 0,
            "trialStartedOn": "2026-11-05",
            "trialExpiresOn": "2026-11-05",
            "trialClassesLimit": 1,
            "trialClassesUsed": 1,
            "joinedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "memberNumber": "string",
            "lastSeenOn": 1793836800,
            "planStatus": "active",
            "passesRemaining": 1,
            "currentRank": {},
            "ranks": [],
            "tags": [],
            "status": {},
            "familyId": 1,
            "familyName": "string",
            "photoUrl": "string",
            "photoStorageKey": "string",
            "signupFormName": "string",
            "contractExpiresOn": "2026-11-05",
            "venueIds": [
             1
            ],
            "deletedOn": 1793836800,
            "archivedOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "jo@example.com",
            "mobileNumber": "string",
            "isActive": 0,
            "isLead": 0,
            "isTrial": 0,
            "trialStartedOn": "2026-11-05",
            "trialExpiresOn": "2026-11-05",
            "trialClassesLimit": 1,
            "trialClassesUsed": 1,
            "joinedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "memberNumber": "string",
            "lastSeenOn": 1793836800,
            "planStatus": "active",
            "passesRemaining": 1,
            "currentRank": {},
            "ranks": [],
            "tags": [],
            "status": {},
            "familyId": 1,
            "familyName": "string",
            "photoUrl": "string",
            "photoStorageKey": "string",
            "signupFormName": "string",
            "contractExpiresOn": "2026-11-05",
            "venueIds": [
             1
            ],
            "deletedOn": 1793836800,
            "archivedOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "firstName": {
          "type": "string",
          "description": "First name (max 50)"
         },
         "lastName": {
          "type": "string",
          "description": "Last name (max 50)"
         },
         "emailAddress": {
          "type": "string",
          "description": "Email address. Optional: walk-in leads may have none; stored as \"\" (empty) when absent, matching migrated v1 data.",
          "format": "email"
         },
         "emailAddressAlt": {
          "type": "string",
          "description": "Secondary email address",
          "format": "email"
         },
         "isLead": {
          "type": "boolean",
          "description": "Create as a lead (not yet a member). Default false."
         },
         "isTrial": {
          "type": "boolean",
          "description": "Create as a trial. Default false."
         },
         "isActive": {
          "type": "boolean",
          "description": "Record enabled. Default true: leads and trials are active records too."
         },
         "mobileNumber": {
          "type": "string",
          "description": "Mobile number (max 20)"
         },
         "phoneNumber": {
          "type": "string",
          "description": "Landline/phone number (max 20)"
         },
         "address": {
          "type": "string",
          "description": "Street address (max 100)"
         },
         "suburb": {
          "type": "string",
          "description": "Suburb (max 100)"
         },
         "postcode": {
          "type": "string",
          "description": "Postcode (max 20)"
         },
         "gender": {
          "type": [
           "string",
           "null"
          ],
          "description": "Any spelling of these is accepted and stored as the enum value",
          "enum": [
           "male",
           "female",
           "other",
           "prefer_not_to_say"
          ]
         },
         "birthday": {
          "type": "string",
          "description": "Date of birth, YYYY-MM-DD (legacy midnight-epoch integers also accepted). Future dates are rejected.",
          "format": "date"
         },
         "memberNumber": {
          "type": "string",
          "description": "Member number (max 50)"
         },
         "joinedOn": {
          "type": "string",
          "description": "Join date, YYYY-MM-DD (legacy epoch also accepted). Future dates ARE allowed: pre-registering a start date is legitimate.",
          "format": "date"
         },
         "contractExpiresOn": {
          "type": "integer",
          "description": "Contract expiry, unix seconds"
         },
         "referralSource": {
          "type": "string",
          "description": "How they found the school (max 120)"
         },
         "beltSize": {
          "type": "string",
          "description": "Belt size (max 25)"
         },
         "uniformSize": {
          "type": "string",
          "description": "Uniform size (max 25)"
         },
         "receiveEmail": {
          "type": "boolean",
          "description": "Email opt-in. Default true."
         },
         "receiveSms": {
          "type": "boolean",
          "description": "SMS opt-in. Default true."
         },
         "receiveChat": {
          "type": "boolean",
          "description": "Chat opt-in. Default true."
         },
         "notes": {
          "type": "string",
          "description": "Initial notes"
         },
         "emergencyContacts": {
          "type": "array",
          "description": "Emergency contacts: [{firstName (required), lastName, relationship, mobile, phone, email, receiveEmails, receiveSms}]. Needs Medical & Emergency (59); refused with 403 without it.",
          "items": {}
         },
         "venueIds": {
          "type": "array",
          "description": "Venues to enroll in",
          "items": {
           "type": "integer"
          }
         },
         "statusId": {
          "type": "integer",
          "description": "The student's status (from /v1/statuses). A student holds one; left out, they get the school's Student status"
         },
         "tagIds": {
          "type": "array",
          "description": "Tags to assign",
          "items": {
           "type": "integer"
          }
         },
         "clubIds": {
          "type": "array",
          "description": "Clubs to assign",
          "items": {
           "type": "integer"
          }
         },
         "rankAssignments": {
          "type": "array",
          "description": "Style enrollment with starting rank: [{styleId, rankId}]. This is how you enroll a student in a martial art.",
          "items": {}
         },
         "addressLatitude": {
          "type": "number",
          "description": "Geocoded latitude, cached for demographic map reports"
         },
         "addressLongitude": {
          "type": "number",
          "description": "Geocoded longitude"
         }
        },
        "required": [
         "firstName",
         "lastName"
        ]
       },
       "example": {
        "firstName": "string",
        "lastName": "string"
       }
      }
     }
    }
   }
  },
  "/v1/students/counts": {
   "get": {
    "operationId": "students_getCounts",
    "summary": "getCounts",
    "description": "Student counts by type: leads, trials, active, inactive. Mutually exclusive and exhaustive over the live (non-deleted) roster, so the four sum to the unfiltered list total. Each corresponds to one statusTypes value on GET /v1/students. Pending students are counted separately by GET /v1/students/pending.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/students.StudentCounts"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "active": 1,
          "inactive": 1,
          "leads": 1,
          "trials": 1,
          "archived": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/update-request": {
   "post": {
    "operationId": "students_sendUpdateRequest",
    "summary": "sendUpdateRequest",
    "description": "Send the member a link (email or SMS) to a form prefilled from their record so they can update it themselves. Their answers land in the pending queue as an info update; nothing changes until approved. Fails when the member has no address for the chosen channel.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "channel": {
          "type": "string",
          "enum": [
           "email",
           "sms"
          ]
         },
         "message": {
          "type": "string",
          "description": "Optional note shown above the link (max 500 chars)"
         }
        },
        "required": [
         "channel"
        ]
       },
       "example": {
        "channel": "email"
       }
      }
     }
    }
   },
   "get": {
    "operationId": "students_getUpdateRequest",
    "summary": "getUpdateRequest",
    "description": "The latest 'update your details' request for this member: channel, sent / opened / submitted / expired, and the pending submission id while it awaits review. Null when none was ever sent.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/watch": {
   "get": {
    "operationId": "students_getWatch",
    "summary": "getWatch",
    "description": "Whether the signed-in user is watching this student: a push to their browsers each time the student checks themselves in at the kiosk or in the app. Personal to the user.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "put": {
    "operationId": "students_setWatch",
    "summary": "setWatch",
    "description": "Start or stop watching this student's check-ins for the signed-in user. Idempotent. Other admins' watch lists are untouched.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "watching": {
          "type": "boolean"
         }
        },
        "required": [
         "watching"
        ]
       },
       "example": {
        "watching": false
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/check-in-code": {
   "get": {
    "operationId": "students_getCheckInCode",
    "summary": "getCheckInCode",
    "description": "The student's check-in code: the text their QR code carries. Render it as a QR for a printed card or fob; the kiosk's Instructor mode scans it from a phone and checks the student in. The member sees the same code in the portal and the app. Derived from the student, never stored, so it cannot be changed on its own.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/students.StudentCheckInCode"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "code": "A3F9C27E51B08D64E2C7"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/pending": {
   "get": {
    "operationId": "students_listPending",
    "summary": "listPending",
    "description": "Outstanding student-form submissions awaiting owner approval, oldest first. Unpaginated: a request only exists between 'form emailed' and 'owner approves'. A row with a non-null studentId is an INFO UPDATE for an existing student rather than a new signup.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/students.PendingStudent"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "firstName": "string",
           "lastName": "string",
           "emailAddress": "string",
           "mobileNumber": "string",
           "phoneNumber": "string",
           "gender": "string",
           "birthday": "2026-11-05",
           "address": "string",
           "suburb": "string",
           "postcode": "string",
           "medical": "string",
           "studentId": 1,
           "submittedOn": 1,
           "updatedOn": 1,
           "emailSuppression": {}
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/pending/count": {
   "get": {
    "operationId": "students_getPendingCount",
    "summary": "getPendingCount",
    "description": "Count of outstanding submissions. Drives the student-list filter chip, which renders only when this is greater than zero.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/pending/{id}/approve": {
   "post": {
    "operationId": "students_approvePending",
    "summary": "approvePending",
    "description": "Approve a submission. Creates the student, or updates the existing one when the request carries a studentId, then retires the request. An approved signup becomes an Active Student. Returns 400 when the submission lacks a first name, last name or email address, because a student cannot be created without them.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/students/pending/{id}": {
   "delete": {
    "operationId": "students_discardPending",
    "summary": "discardPending",
    "description": "Discard a submission without creating anything. Soft delete, so the original submission stays auditable.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/students/filters": {
   "get": {
    "operationId": "students_getFilters",
    "summary": "getFilters",
    "description": "Get available filter options (tags, styles, ranks, statuses) for building filter UI",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/students.FilterOptions"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "tags": [],
          "styles": [],
          "ranks": [],
          "statuses": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/styles-ranks": {
   "get": {
    "operationId": "students_getStylesRanks",
    "summary": "getStylesRanks",
    "description": "Get all styles with their rank progressions",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "description": "StyleWithRanks"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/no-style": {
   "get": {
    "operationId": "students_listNoStyle",
    "summary": "listNoStyle",
    "description": "Members (active, not a lead, not on trial) who hold no rank in any style. A member sees and books only the classes for a style they belong to, so these see none. Give each a rank with PATCH /v1/students/:id/ranks.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/students.MemberInNoStyle"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "firstName": "string",
           "lastName": "string"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/bulk/tags": {
   "post": {
    "operationId": "students_bulkTags",
    "summary": "bulkTags",
    "description": "Add, remove, or replace tags on multiple students. Requires the Edit Profiles permission (STUDENTS category satisfies it).",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "Target students (1 to 10,000)",
          "items": {
           "type": "integer"
          }
         },
         "action": {
          "type": "string",
          "description": "add/remove adjusts the existing tags; set replaces them",
          "enum": [
           "add",
           "remove",
           "set"
          ]
         },
         "tagIds": {
          "type": "array",
          "description": "Tag IDs to apply (at least one)",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "studentIds",
         "action",
         "tagIds"
        ]
       },
       "example": {
        "studentIds": [
         1
        ],
        "action": "add",
        "tagIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/students/bulk/status": {
   "post": {
    "operationId": "students_bulkStatus",
    "summary": "bulkStatus",
    "description": "Set or clear the status of multiple students. A student holds one status, so setting one replaces whatever they held. This is NOT the active/inactive toggle. See the updateActive operation for that. Requires the Edit Profiles permission (STUDENTS category satisfies it).",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "Target students (1 to 10,000)",
          "items": {
           "type": "integer"
          }
         },
         "statusId": {
          "type": "integer",
          "description": "A status (from /v1/statuses). A student holds one status, so set replaces whatever they hold"
         },
         "action": {
          "type": "string",
          "description": "set (default) replaces the student's status; remove clears it for the students who hold the one named",
          "enum": [
           "set",
           "remove"
          ]
         }
        },
        "required": [
         "studentIds",
         "statusId"
        ]
       },
       "example": {
        "studentIds": [
         1
        ],
        "statusId": 1
       }
      }
     }
    }
   }
  },
  "/v1/students/bulk/export": {
   "post": {
    "operationId": "students_bulkExport",
    "summary": "bulkExport",
    "description": "Export students to CSV. Requires a STUDENTS permission; columns are filtered to what the caller's sub-permissions allow (email/phone/address/birthday/notes, and medical info and emergency contacts without Medical & Emergency (59), may be absent). Hidden columns are omitted entirely, not blanked.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "Specific students (omit for all)",
          "items": {
           "type": "integer"
          }
         }
        }
       },
       "example": {
        "studentIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/students/bulk/export-photos": {
   "post": {
    "operationId": "students_bulkExportPhotos",
    "summary": "bulkExportPhotos",
    "description": "Every selected student's profile photo as one zip, built in the background as an operation: the answer is 202 with { operationId, label }, followed through GET /v1/operations/:id, whose file.downloadUrl is a short-lived signed link to the zip; the zip is kept for seven days. Photos are JPEG named \"First Last.jpg\" (the student id in brackets when two share a name). Refused when no selected student has a photo. Requires a STUDENTS permission.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "The selection (1 to 10,000)",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "studentIds"
        ]
       },
       "example": {
        "studentIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/students/bulk": {
   "delete": {
    "operationId": "students_bulkDelete",
    "summary": "bulkDelete",
    "description": "Archive multiple students. Students still billed by a live plan are left in place and named as blocked, in the preview and in the result. Requires the Edit Profiles permission (STUDENTS category satisfies it).",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "Target students (1 to 10,000)",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "studentIds"
        ]
       },
       "example": {
        "studentIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/students/selection-summary": {
   "post": {
    "operationId": "students_selectionSummary",
    "summary": "selectionSummary",
    "description": "What a bulk action needs to know about a selection before acting: per student the flags, contact reach, tag ids, the one status held and whether any waiver is signed, plus aggregate counts. Whether a live plan blocks archiving is added per student (archiveBlock) only with includeArchiveBlock. Read-only; up to 10,000 ids, or 500 with includeArchiveBlock.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "The selection (1 to 10,000)",
          "items": {
           "type": "integer"
          }
         },
         "includeArchiveBlock": {
          "type": "boolean",
          "description": "Add archiveBlock per student (why archiving would leave them in place, or null). A full billing read per student, so only for up to 500 ids."
         }
        },
        "required": [
         "studentIds"
        ]
       },
       "example": {
        "studentIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}": {
   "get": {
    "operationId": "students_get",
    "summary": "get",
    "description": "Get a single student with full details. Fields the caller's sub-permissions do not allow are omitted: address (9), email (24), phone (25), birthday (10), notes (12), and emergencyInfo and emergencyContacts.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/students.StudentDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "memberNumber": "string",
          "firstName": "string",
          "lastName": "string",
          "address": "string",
          "suburb": "string",
          "postcode": "string",
          "emailAddress": "jo@example.com",
          "emailAddressAlt": "string",
          "phoneNumber": "string",
          "mobileNumber": "string",
          "emergencyInfo": "string",
          "gender": "male",
          "birthday": "2026-11-05",
          "isActive": 0,
          "isLead": 0,
          "isTrial": 0,
          "trialStartedOn": "2026-11-05",
          "trialExpiresOn": "2026-11-05",
          "trialClassesLimit": 1,
          "trialClassesUsed": 1,
          "joinedOn": "2026-11-05",
          "contractExpiresOn": "2026-11-05",
          "lastSeenOn": 1793836800,
          "notes": "string",
          "beltSize": "string",
          "uniformSize": "string",
          "receiveEmail": false,
          "receiveSms": false,
          "receiveChat": false,
          "referralSource": "string",
          "createdOn": 1793836800,
          "updatedOn": 1793836800,
          "deactivatedOn": 1793836800,
          "deletedOn": 1793836800,
          "schoolId": 1,
          "onetouchId": 1,
          "onetouchFormId": 1,
          "portalStatus": "string",
          "appVersion": "string",
          "wasActiveThisMonth": 0,
          "paymentMethod": "string",
          "paymentFrequency": "string",
          "photoStorageKey": "string",
          "referredOn": "2026-11-05",
          "convertedOn": "2026-11-05",
          "leadStageId": 1,
          "leadStageChangedOn": 1793836800,
          "leadDormantOn": 1793836800,
          "leadTemperatureOverride": 1,
          "lossReason": "string",
          "emailSuppression": {},
          "archivedStyleCount": 1,
          "signupFormName": "string",
          "ranks": [],
          "tags": [],
          "status": {},
          "venues": [],
          "emergencyContacts": [],
          "family": {},
          "clubs": [],
          "photoUrl": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "students_update",
    "summary": "update",
    "description": "Update student fields",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/students.Student"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "jo@example.com",
            "mobileNumber": "string",
            "isActive": 0,
            "isLead": 0,
            "isTrial": 0,
            "trialStartedOn": "2026-11-05",
            "trialExpiresOn": "2026-11-05",
            "trialClassesLimit": 1,
            "trialClassesUsed": 1,
            "joinedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "memberNumber": "string",
            "lastSeenOn": 1793836800,
            "planStatus": "active",
            "passesRemaining": 1,
            "currentRank": {},
            "ranks": [],
            "tags": [],
            "status": {},
            "familyId": 1,
            "familyName": "string",
            "photoUrl": "string",
            "photoStorageKey": "string",
            "signupFormName": "string",
            "contractExpiresOn": "2026-11-05",
            "venueIds": [
             1
            ],
            "deletedOn": 1793836800,
            "archivedOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "jo@example.com",
            "mobileNumber": "string",
            "isActive": 0,
            "isLead": 0,
            "isTrial": 0,
            "trialStartedOn": "2026-11-05",
            "trialExpiresOn": "2026-11-05",
            "trialClassesLimit": 1,
            "trialClassesUsed": 1,
            "joinedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "memberNumber": "string",
            "lastSeenOn": 1793836800,
            "planStatus": "active",
            "passesRemaining": 1,
            "currentRank": {},
            "ranks": [],
            "tags": [],
            "status": {},
            "familyId": 1,
            "familyName": "string",
            "photoUrl": "string",
            "photoStorageKey": "string",
            "signupFormName": "string",
            "contractExpiresOn": "2026-11-05",
            "venueIds": [
             1
            ],
            "deletedOn": 1793836800,
            "archivedOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, STATUS_HELD_BY_LIVE_PLAN",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "STATUS_HELD_BY_LIVE_PLAN",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "firstName": {
          "type": "string"
         },
         "lastName": {
          "type": "string"
         },
         "emailAddress": {
          "type": "string",
          "description": "Set a new address, or send null or \"\" to CLEAR it.",
          "format": "email"
         },
         "emailAddressAlt": {
          "type": "string",
          "description": "Nullable",
          "format": "email"
         },
         "mobileNumber": {
          "type": "string",
          "description": "Nullable"
         },
         "phoneNumber": {
          "type": "string",
          "description": "Nullable"
         },
         "address": {
          "type": "string",
          "description": "Nullable"
         },
         "suburb": {
          "type": "string",
          "description": "Nullable"
         },
         "postcode": {
          "type": "string",
          "description": "Nullable"
         },
         "gender": {
          "type": [
           "string",
           "null"
          ],
          "description": "Any spelling of these is accepted and stored as the enum value; null clears it",
          "enum": [
           "male",
           "female",
           "other",
           "prefer_not_to_say"
          ]
         },
         "birthday": {
          "type": "string",
          "description": "YYYY-MM-DD (legacy epoch accepted). Future dates rejected.",
          "format": "date"
         },
         "memberNumber": {
          "type": "string",
          "description": "Nullable"
         },
         "isLead": {
          "type": "boolean",
          "description": "Type discriminator: see the create operation's notes. Setting true is refused with 409 STATUS_HELD_BY_LIVE_PLAN while the student holds a live paid plan, their own or on a family plan (not set to cancel, and not paused unless a resume date is booked): cancel the plan first."
         },
         "isActive": {
          "type": "boolean",
          "description": "Enabled flag, not a membership flag. Setting false is refused with 409 STATUS_HELD_BY_LIVE_PLAN while the student holds a live paid plan, their own or on a family plan (not set to cancel, and not paused unless a resume date is booked): cancel the plan first."
         },
         "joinedOn": {
          "type": "string",
          "description": "YYYY-MM-DD (legacy epoch accepted)",
          "format": "date"
         },
         "contractExpiresOn": {
          "type": "integer",
          "description": "Unix seconds. Nullable."
         },
         "referralSource": {
          "type": "string",
          "description": "Nullable"
         },
         "beltSize": {
          "type": "string",
          "description": "Nullable"
         },
         "uniformSize": {
          "type": "string",
          "description": "Nullable"
         },
         "receiveEmail": {
          "type": "boolean"
         },
         "receiveSms": {
          "type": "boolean"
         },
         "receiveChat": {
          "type": "boolean"
         },
         "notes": {
          "type": "string",
          "description": "Nullable"
         },
         "emergencyContacts": {
          "type": "array",
          "description": "Replaces the full set: [{id (omit for new), firstName (required), lastName, relationship, mobile, phone, email, receiveEmails, receiveSms}]. Needs Medical & Emergency (59); refused with 403 without it, since a caller who cannot see the contacts would delete them.",
          "items": {}
         },
         "venueIds": {
          "type": "array",
          "description": "Set-based: replaces all existing",
          "items": {
           "type": "integer"
          }
         },
         "statusId": {
          "type": [
           "integer",
           "null"
          ],
          "description": "The student's one status (from /v1/statuses): a new one replaces it, null clears it"
         },
         "tagIds": {
          "type": "array",
          "description": "Set-based: replaces all existing",
          "items": {
           "type": "integer"
          }
         },
         "clubIds": {
          "type": "array",
          "description": "Set-based: replaces all existing",
          "items": {
           "type": "integer"
          }
         },
         "familyId": {
          "type": "integer",
          "description": "Link to a family, or null to unlink"
         },
         "familyRelationship": {
          "type": "string",
          "description": "Role within the family. Nullable."
         },
         "isBillingResponsible": {
          "type": "boolean",
          "description": "Whether this member pays for the family"
         },
         "rankAssignments": {
          "type": "array",
          "description": "Per-style: [{styleId, rankId}]: rankId null unenrolls from that style",
          "items": {}
         },
         "updatedOn": {
          "type": "integer",
          "description": "Optimistic lock: if sent, the server rejects the write when it does not match the stored value"
         }
        }
       },
       "example": {
        "firstName": "string",
        "lastName": "string",
        "emailAddress": "jo@example.com",
        "emailAddressAlt": "jo@example.com",
        "mobileNumber": "string",
        "phoneNumber": "string",
        "address": "string",
        "suburb": "string",
        "postcode": "string",
        "gender": "male",
        "birthday": "2026-11-05",
        "memberNumber": "string",
        "isLead": false,
        "isActive": false,
        "joinedOn": "2026-11-05",
        "contractExpiresOn": 1,
        "referralSource": "string",
        "beltSize": "string",
        "uniformSize": "string",
        "receiveEmail": false,
        "receiveSms": false,
        "receiveChat": false,
        "notes": "string",
        "emergencyContacts": [],
        "venueIds": [
         1
        ],
        "statusId": 1,
        "tagIds": [
         1
        ],
        "clubIds": [
         1
        ],
        "familyId": 1,
        "familyRelationship": "string",
        "isBillingResponsible": false,
        "rankAssignments": [],
        "updatedOn": 1
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "students_delete",
    "summary": "delete",
    "description": "Archive a student (soft delete; POST /:id/restore brings them back). Refused with 409 CONFLICT while any of their plans, or a family plan billing through them, is still billing: cancel, pause or move it first. The preview names the blocking plan in `validation`.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/students/{id}/attendance": {
   "get": {
    "operationId": "students_getAttendance",
    "summary": "getAttendance",
    "description": "Get student's attendance history with pagination",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "description": "AttendanceRecord"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/attendance/summary": {
   "get": {
    "operationId": "students_getAttendanceSummary",
    "summary": "getAttendanceSummary",
    "description": "Get full attendance summary with streaks, totals by period, and class breakdown",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/ranks": {
   "get": {
    "operationId": "students_getRanks",
    "summary": "getRanks",
    "description": "Get student's rank progression across all styles",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {}
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "students_updateRanks",
    "summary": "updateRanks",
    "description": "Award or remove a single rank for a student. To promote to the next rank in a style, use POST /v1/workflows/promote Needs the Grading permission, as promote does.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "action": {
          "type": "string",
          "description": "What to do with the rank",
          "enum": [
           "award",
           "remove"
          ]
         },
         "rankId": {
          "type": "integer",
          "description": "The rank to award (required for award)"
         },
         "studentRankId": {
          "type": "integer",
          "description": "The existing student-rank row to remove (required for remove)"
         },
         "gradingDate": {
          "type": "string",
          "description": "When the rank was awarded, YYYY-MM-DD. Defaults to today.",
          "format": "date"
         },
         "notes": {
          "type": "string",
          "description": "Grading notes"
         }
        },
        "required": [
         "action"
        ]
       },
       "example": {
        "action": "award"
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/family": {
   "get": {
    "operationId": "students_getFamily",
    "summary": "getFamily",
    "description": "Get student's family members",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "description": "FamilyMember"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/notes": {
   "get": {
    "operationId": "students_listNotes",
    "summary": "listNotes",
    "description": "Get all notes for a student",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/students.StudentNote"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "studentId": 1,
           "content": "string",
           "type": "general",
           "createdBy": "string",
           "createdAt": "2026-11-05T18:00:00Z"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "students_createNote",
    "summary": "createNote",
    "description": "Add a note to a student",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/students.StudentNote"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "content": "string",
            "type": "general",
            "createdBy": "string",
            "createdAt": "2026-11-05T18:00:00Z"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "content": "string",
            "type": "general",
            "createdBy": "string",
            "createdAt": "2026-11-05T18:00:00Z"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "content": {
          "type": "string",
          "description": "Note content (non-empty; trimmed on save)"
         }
        },
        "required": [
         "content"
        ]
       },
       "example": {
        "content": "string"
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/notes/{noteId}": {
   "patch": {
    "operationId": "students_updateNote",
    "summary": "updateNote",
    "description": "Update a student note",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/students.StudentNote"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "content": "string",
            "type": "general",
            "createdBy": "string",
            "createdAt": "2026-11-05T18:00:00Z"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "content": "string",
            "type": "general",
            "createdBy": "string",
            "createdAt": "2026-11-05T18:00:00Z"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "noteId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "content": {
          "type": "string"
         }
        },
        "required": [
         "content"
        ]
       },
       "example": {
        "content": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "students_deleteNote",
    "summary": "deleteNote",
    "description": "Delete a student note",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "noteId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/students/{id}/waivers/available": {
   "get": {
    "operationId": "students_getAvailableWaivers",
    "summary": "getAvailableWaivers",
    "description": "Waivers this student could sign now. Only a current signature removes a waiver from the list; declined, expired, voided and still-outstanding requests do NOT, so a declined waiver can be re-requested or signed in person. Each entry carries `lastRequest` (the most recent non-signed row: signatureId, status, on) or null, so callers can explain the history rather than re-offering silently.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {}
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/waivers": {
   "get": {
    "operationId": "students_getSignedWaivers",
    "summary": "getSignedWaivers",
    "description": "Get waivers this student has signed",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {}
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/waivers/{signatureId}": {
   "get": {
    "operationId": "students_getWaiverDetail",
    "summary": "getWaiverDetail",
    "description": "Get details of a signed waiver including signature image",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "signatureId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "delete": {
    "operationId": "students_deleteSignature",
    "summary": "deleteSignature",
    "description": "Delete a waiver signature",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "signatureId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/students/{id}/waivers/guardian-preview": {
   "get": {
    "operationId": "students_getGuardianPreview",
    "summary": "getGuardianPreview",
    "description": "Preview the guardian contact an automatic guardian waiver request would use for this student. Returns isMinor, and when a contact is found, the guardian's name/email/relationship plus its source ('emergencyInfo' = extracted from emergency contact info, 'altEmail' = the student's alternate email). Uses the exact same detection logic as sending, so the preview never disagrees with the actual send.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/waivers/{waiverId}/sign": {
   "post": {
    "operationId": "students_signWaiver",
    "summary": "signWaiver",
    "description": "Sign a waiver on a student's behalf (in person). Required field affirmations from the waiver's current version are enforced. Fetch them via the prefilled endpoint and submit responses in fieldResponses.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "waiverId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "signature": {
          "type": "string",
          "description": "Signer's name (typed) or signature label (drawn)"
         },
         "signatureType": {
          "type": "string",
          "description": "How the signature was captured",
          "enum": [
           "typed",
           "drawn"
          ]
         },
         "signatureImage": {
          "type": "string",
          "description": "Base64 PNG data URL, required when signatureType is 'drawn'"
         },
         "fieldResponses": {
          "type": "object",
          "description": "Responses keyed by field key for the version's fields; required fields are enforced"
         },
         "signerRole": {
          "type": "string",
          "description": "Who physically signed (default student)",
          "enum": [
           "student",
           "guardian",
           "witness"
          ]
         },
         "signerRelationship": {
          "type": "string",
          "description": "Relationship to the student when a non-student signs (e.g. 'Mother')"
         }
        },
        "required": [
         "signature",
         "signatureType"
        ]
       },
       "example": {
        "signature": "string",
        "signatureType": "typed"
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/files": {
   "get": {
    "operationId": "students_listFiles",
    "summary": "listFiles",
    "description": "List all files uploaded for a student",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/students.StudentFile"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "studentId": 1,
           "name": "string",
           "size": 1,
           "mimeType": "string",
           "url": "https://example.com",
           "createdAt": "2026-11-05T18:00:00Z"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "students_uploadFile",
    "summary": "uploadFile",
    "description": "Upload a file for a student (max 10MB per file, 25MB per student)",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/students.StudentFile"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "studentId": 1,
          "name": "string",
          "size": 1,
          "mimeType": "string",
          "url": "https://example.com",
          "createdAt": "2026-11-05T18:00:00Z"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/students/{id}/files/{fileId}": {
   "get": {
    "operationId": "students_getFile",
    "summary": "getFile",
    "description": "Get file metadata and download URL",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/students.StudentFile"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "studentId": 1,
          "name": "string",
          "size": 1,
          "mimeType": "string",
          "url": "https://example.com",
          "createdAt": "2026-11-05T18:00:00Z"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "fileId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "students_renameFile",
    "summary": "renameFile",
    "description": "Rename a student file",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/students.StudentFile"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "name": "string",
            "size": 1,
            "mimeType": "string",
            "url": "https://example.com",
            "createdAt": "2026-11-05T18:00:00Z"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "name": "string",
            "size": 1,
            "mimeType": "string",
            "url": "https://example.com",
            "createdAt": "2026-11-05T18:00:00Z"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "fileId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "New file name"
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "students_deleteFile",
    "summary": "deleteFile",
    "description": "Delete a student file",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "fileId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/students/{id}/no-shows": {
   "get": {
    "operationId": "students_getNoShows",
    "summary": "getNoShows",
    "description": "Get student's no-show history. Returns bookings where the student was expected but did not attend, with fee info.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "days",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 30
      },
      "description": "Number of days to look back. Default: 30"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/photo": {
   "post": {
    "operationId": "students_uploadPhoto",
    "summary": "uploadPhoto",
    "description": "Upload a student photo. Accepts multipart form data with a 'photo' field. Image is auto-resized to 400x400 WebP. Max 10MB. Replaces existing photo.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   },
   "delete": {
    "operationId": "students_deletePhoto",
    "summary": "deletePhoto",
    "description": "Delete a student's photo from storage.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/students/{id}/billing": {
   "get": {
    "operationId": "students_getBilling",
    "summary": "getBilling",
    "description": "Get student's billing information",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{studentId}/subscription": {
   "post": {
    "operationId": "students_assignPlan",
    "summary": "assignPlan",
    "description": "Assign a billing plan to a student. Creates a subscription and optionally records an initial payment. An API key needs billing:write as well as students:write.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/students.AssignPlanResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "subscriptionId": 1,
            "transactionId": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "subscriptionId": 1,
            "transactionId": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "planId": {
          "type": "integer",
          "description": "ID of the billing plan to assign"
         },
         "startOn": {
          "type": "string",
          "description": "Start day as YYYY-MM-DD in the school's zone; a unix timestamp is still accepted and re-anchored to that day. Defaults to now",
          "format": "date"
         },
         "endOn": {
          "type": "string",
          "description": "End day as YYYY-MM-DD in the school's zone (null = no end date)",
          "format": "date"
         },
         "discount": {
          "type": "number",
          "description": "Discount amount (interpretation depends on discountType)"
         },
         "discountType": {
          "type": "integer",
          "description": "0 = percentage (0-100), 1 = fixed amount in cents",
          "enum": [
           0,
           1
          ]
         },
         "paymentMethod": {
          "type": "string",
          "description": "How the plan is paid: an offline method is billed locally; credit_card_stripe and direct_debit_gocardless need the gateway connected",
          "enum": [
           "cash",
           "cheque",
           "credit_card_offline",
           "direct_debit_offline",
           "standing_order_offline",
           "credit_card_stripe",
           "direct_debit_gocardless"
          ]
         },
         "paymentMethodId": {
          "type": "string",
          "description": "Stored Stripe card (pm_…) the plan is charged against; omitted, the customer default is used"
         },
         "oneOffAmount": {
          "type": "integer",
          "description": "One-off payment amount in cents (setup fee or prorated first payment)"
         },
         "billingAnchorDay": {
          "type": "integer",
          "description": "Day of month for recurring billing (1-28)"
         },
         "prorateFirst": {
          "type": "boolean",
          "description": "Whether to prorate first payment to align with billing anchor"
         }
        },
        "required": [
         "planId",
         "paymentMethod"
        ]
       },
       "example": {
        "planId": 1,
        "paymentMethod": "cash"
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/tags": {
   "patch": {
    "operationId": "students_updateTags",
    "summary": "updateTags",
    "description": "Set tags for a student (replaces all existing tags)",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "tagIds": {
          "type": "array",
          "description": "Tag IDs to assign",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "tagIds"
        ]
       },
       "example": {
        "tagIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/status": {
   "patch": {
    "operationId": "students_updateStatus",
    "summary": "updateStatus",
    "description": "Change the one status a student holds. Status IDs come from the statuses module (GET /v1/statuses).",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "statusId": {
          "type": "integer",
          "description": "The status to set or remove. Enumerate via GET /v1/statuses"
         },
         "action": {
          "type": "string",
          "description": "set (default) replaces the status the student holds; remove clears it when it is the one named.",
          "enum": [
           "set",
           "remove"
          ]
         }
        },
        "required": [
         "statusId"
        ]
       },
       "example": {
        "statusId": 1
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/active": {
   "patch": {
    "operationId": "students_updateActive",
    "summary": "updateActive",
    "description": "Toggle student active/inactive state. Refused with 409 STATUS_HELD_BY_LIVE_PLAN while the student holds a live paid plan, their own or on a family plan (not set to cancel, and not paused unless a resume date is booked): cancel the plan first. A dry run refuses the same way.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, STATUS_HELD_BY_LIVE_PLAN",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "STATUS_HELD_BY_LIVE_PLAN",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "isActive": {
          "type": "boolean",
          "description": "true enables the record, false deactivates it"
         },
         "reason": {
          "type": "string",
          "description": "Churn reason, only applied when deactivating. An unrecognised value falls back to 'unknown' rather than failing the toggle."
         },
         "note": {
          "type": "string",
          "description": "Free-text churn note, only applied when deactivating"
         }
        },
        "required": [
         "isActive"
        ]
       },
       "example": {
        "isActive": false
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/medical": {
   "patch": {
    "operationId": "students_updateMedical",
    "summary": "updateMedical",
    "description": "Update student medical information. This is a single free-text field, not a structured record. Requires Medical & Emergency (59).",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "emergencyInfo": {
          "type": "string",
          "description": "Medical and emergency information as free text (conditions, medications, allergies, doctor details all go here)"
         }
        },
        "required": [
         "emergencyInfo"
        ]
       },
       "example": {
        "emergencyInfo": "string"
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/archive": {
   "post": {
    "operationId": "students_archive",
    "summary": "archive",
    "description": "Archive a student (soft-delete, can be restored)",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/students/{id}/archived": {
   "get": {
    "operationId": "students_getArchived",
    "summary": "getArchived",
    "description": "The archived record behind a profile URL: name, when it was archived, current rank per style, family, the most recent plan and its state, the last attendance, and how much is on file. Every other read 404s an archived student.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/restore": {
   "post": {
    "operationId": "students_restore",
    "summary": "restore",
    "description": "Restore an archived student. By default they come back exactly as they were (an inactive student stays inactive, a lead stays a lead). With reactivate: true an inactive student comes back as an Active Student in the same step. Their old plans stay as they were at archive (cancelled or paused): restoring never restarts billing.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "reactivate": {
          "type": "boolean",
          "description": "Also make them an Active Student (only meaningful for a student who was inactive). Default false."
         }
        }
       },
       "example": {
        "reactivate": false
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/trial": {
   "get": {
    "operationId": "students_getTrialInfo",
    "summary": "getTrialInfo",
    "description": "Get trial status and info for a student",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/students/{id}/start-trial": {
   "post": {
    "operationId": "students_startTrial",
    "summary": "startTrial",
    "description": "Start a trial period for a student. A second trial keeps the count: days and classes an earlier trial used carry over, so the trial runs only for what is left of the limit, and is refused with 409 TRIAL_USED_UP when nothing is left (every day or every class used). A dry run refuses the same way.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, TRIAL_USED_UP",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "TRIAL_USED_UP",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "durationDays": {
          "type": "integer",
          "description": "Trial length in days, in total across every trial. Defaults to the school's configured trial window."
         },
         "classesLimit": {
          "type": "integer",
          "description": "How many classes the trial allows, in total across every trial. Defaults to the school's configured limit."
         }
        }
       },
       "example": {
        "durationDays": 1,
        "classesLimit": 1
       }
      }
     }
    }
   }
  },
  "/v1/students/{id}/convert": {
   "post": {
    "operationId": "students_convertTrial",
    "summary": "convertTrial",
    "description": "Convert a trial student to a full member",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/students/{id}/expire-trial": {
   "post": {
    "operationId": "students_expireTrial",
    "summary": "expireTrial",
    "description": "Mark a trial as expired: they go back to being a lead. A trial already holding a live plan is refused (409 TRIAL_HOLDS_LIVE_PLAN): convert them instead.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, TRIAL_HOLDS_LIVE_PLAN",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "TRIAL_HOLDS_LIVE_PLAN",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/students/{id}/send-join-link": {
   "post": {
    "operationId": "students_sendJoinLink",
    "summary": "sendJoinLink",
    "description": "Send a lead or trial a One-Touch Sign-Up link prefilled with their details. Submitting it converts the existing record into a member. Members are refused. A message goes out immediately.",
    "tags": [
     "students"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "formId": {
          "type": "integer",
          "description": "Sign-up form to link to. 0 or omitted uses the school's default form."
         },
         "channel": {
          "type": "string",
          "description": "Delivery channel. Defaults to email. SMS spends credits.",
          "enum": [
           "email",
           "sms",
           "both",
           "link"
          ]
         },
         "note": {
          "type": "string",
          "description": "Optional note merged into the school's join-invitation template."
         }
        }
       },
       "example": {
        "formId": 1,
        "channel": "email",
        "note": "string"
       }
      }
     }
    }
   }
  },
  "/v1/attendance": {
   "get": {
    "operationId": "attendance_list",
    "summary": "list",
    "description": "List attendance records with filtering by date, class, student, and pagination",
    "tags": [
     "attendance"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/attendance.AttendanceRecord"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "studentId": 1,
           "studentName": "string",
           "classId": 1,
           "className": "string",
           "date": "2026-11-05",
           "checkInTime": "18:00"
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "date",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by date (YYYY-MM-DD)"
     },
     {
      "name": "classId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by class ID"
     },
     {
      "name": "studentId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by student ID"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "Page number"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Items per page"
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Sort field Allowed fields: date, -date, studentName, -studentName"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "attendance_checkIn",
    "summary": "checkIn",
    "description": "Check in a student at a venue against a rank. Optionally attach the check-in to an event occurrence via eventId, and backdate it with timestamp.",
    "tags": [
     "attendance"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/attendance.AttendanceRecord"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "studentName": "string",
            "classId": 1,
            "className": "string",
            "date": "2026-11-05",
            "checkInTime": "18:00"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "studentName": "string",
            "classId": 1,
            "className": "string",
            "date": "2026-11-05",
            "checkInTime": "18:00"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, PLAN_DOES_NOT_COVER, NOT_YOUR_CLASS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PLAN_DOES_NOT_COVER",
     "NOT_YOUR_CLASS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer",
          "description": "Student to check in"
         },
         "venueId": {
          "type": "integer",
          "description": "Venue the student is training at"
         },
         "rankId": {
          "type": "integer",
          "description": "Rank the student is training under"
         },
         "eventId": {
          "type": "integer",
          "description": "Event occurrence to attach the check-in to"
         },
         "timestamp": {
          "type": "integer",
          "description": "Unix seconds. Defaults to now; set it to backdate the record."
         },
         "override": {
          "type": "boolean",
          "description": "Admin override: skips the duplicate check and pass limits. It does not lift a plan that doesn't cover the class. Default false."
         },
         "liftNotCovered": {
          "type": "boolean",
          "description": "Check the member in although their plan doesn't cover this class: nothing is charged and the check-in is marked for review. Default false."
         },
         "liftNotForClass": {
          "type": "boolean",
          "description": "Check the student in although the class is not for them (not their style, not their rank in it, or not trial eligible). Send it only after the person has seen the NOT_YOUR_CLASS refusal and said to go ahead."
         }
        },
        "required": [
         "studentId",
         "venueId",
         "rankId"
        ]
       },
       "example": {
        "studentId": 1,
        "venueId": 1,
        "rankId": 1
       }
      }
     }
    }
   }
  },
  "/v1/attendance/students": {
   "get": {
    "operationId": "attendance_getStudents",
    "summary": "getStudents",
    "description": "Get students for the attendance UI at a venue over a time window, including their check-in status",
    "tags": [
     "attendance"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/attendance.AttendanceStudent"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "studentId": 1,
           "studentName": "string",
           "checkedIn": false,
           "attendanceId": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Venue to list students for"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Window start, unix seconds"
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Window end, unix seconds"
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Restrict to students training this style"
     },
     {
      "name": "eventId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Restrict to students booked on this event occurrence"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/attendance/recent": {
   "get": {
    "operationId": "attendance_getRecent",
    "summary": "getRecent",
    "description": "Get recently checked-in students (for kiosk display)",
    "tags": [
     "attendance"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/attendance.AttendanceRecord"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "studentId": 1,
           "studentName": "string",
           "classId": 1,
           "className": "string",
           "date": "2026-11-05",
           "checkInTime": "18:00"
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 10
      },
      "description": "Number of recent attendees to return"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/attendance/today": {
   "get": {
    "operationId": "attendance_getToday",
    "summary": "getToday",
    "description": "Get today's attendance summary: total check-ins, by class breakdown",
    "tags": [
     "attendance"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/attendance.TodaySummary"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "total": 1,
          "byClass": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/attendance/currently-attending": {
   "get": {
    "operationId": "attendance_getCurrentlyAttending",
    "summary": "getCurrentlyAttending",
    "description": "Dashboard widget: counts students currently in class, broken down by venue. The lookback window defaults to the school's configured class duration (school setting 22); override with the duration query param.",
    "tags": [
     "attendance"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/attendance.CurrentlyAttending"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "total": 1,
          "since": 1,
          "byVenue": [],
          "windowMinutes": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "duration",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Lookback window in minutes. Defaults to school setting 22 (class duration)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/attendance/active-events": {
   "get": {
    "operationId": "attendance_getActiveEvents",
    "summary": "getActiveEvents",
    "description": "Get events currently running at a venue. Use mode='day' to see all events for the day instead of just currently active.",
    "tags": [
     "attendance"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/attendance.ActiveEvent"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "eventId": 1,
           "eventName": "string",
           "startTime": 1,
           "endTime": 1,
           "venueId": 1,
           "venueName": "string"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Venue/location ID"
     },
     {
      "name": "mode",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "active",
        "day"
       ],
       "default": "active"
      },
      "description": "'active' = currently in progress, 'day' = all events today"
     },
     {
      "name": "date",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Date override (Unix timestamp, defaults to now)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/attendance/at-risk": {
   "get": {
    "operationId": "attendance_getAtRisk",
    "summary": "getAtRisk",
    "description": "Get students with declining attendance patterns. Compares recent window against baseline to detect drops.",
    "tags": [
     "attendance"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/attendance.AtRiskStudent"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "studentId": 1,
           "studentName": "string",
           "recentCount": 1,
           "baselineAvg": 1,
           "dropPercentage": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "recentDays",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 14
      },
      "description": "Recent window to measure (days)"
     },
     {
      "name": "baselineDays",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 90
      },
      "description": "Baseline window to compare against (days)"
     },
     {
      "name": "dropPct",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Minimum attendance drop percentage to flag (0-100)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/attendance/bulk": {
   "post": {
    "operationId": "attendance_bulkCheckIn",
    "summary": "bulkCheckIn",
    "description": "Check in multiple students at one venue. ?preview=true lists who would be checked in and who is skipped with the reason. The run is queued as an operation and answers 202 with { operationId, label }: follow it under GET /v1/operations/:id, where each student's row says checked_in or failed with the reason. Each student's rank is resolved at that venue; no time given means the moment the run was queued.",
    "tags": [
     "attendance"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "Student IDs to check in (1 to 10,000)",
          "items": {
           "type": "integer"
          }
         },
         "venueId": {
          "type": "integer",
          "description": "Venue the students are training at"
         },
         "eventId": {
          "type": "integer",
          "description": "Event occurrence to attach the check-ins to"
         },
         "timestamp": {
          "type": "integer",
          "description": "Unix seconds. Defaults to now; set it to backdate the records."
         },
         "override": {
          "type": "boolean",
          "description": "Admin override: skips duplicate, pass-limit, and billing checks. Default false."
         }
        },
        "required": [
         "studentIds",
         "venueId"
        ]
       },
       "example": {
        "studentIds": [
         1
        ],
        "venueId": 1
       }
      }
     }
    }
   }
  },
  "/v1/attendance/{id}": {
   "delete": {
    "operationId": "attendance_undoCheckIn",
    "summary": "undoCheckIn",
    "description": "Undo a check-in (delete attendance record). A pass the check-in used is restored. When the check-in took a pay-as-you-go session charge, the undo is refused with 409 SESSION_CHARGE_DECISION_REQUIRED (details: transactionId, amountCents, state) until the request says what happens to it: sessionCharge=refund refunds a paid charge (or writes off one still owed) before the check-in is undone, sessionCharge=keep leaves it. Nothing is refunded without that choice.",
    "tags": [
     "attendance"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "sessionCharge",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "refund",
        "keep"
       ]
      },
      "description": "Required only when the check-in carries a pay-as-you-go charge"
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/grading/promote": {
   "post": {
    "operationId": "grading_promote",
    "summary": "promote",
    "description": "Promote a student to the next rank in a style. The system automatically determines the next rank in the hierarchy.",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/grading.StudentRank"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "rankId": 1,
            "rankName": "string",
            "styleName": "string",
            "gradingDate": "2026-11-05",
            "notes": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "rankId": 1,
            "rankName": "string",
            "styleName": "string",
            "gradingDate": "2026-11-05",
            "notes": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer",
          "description": "Student to promote"
         },
         "styleId": {
          "type": "integer",
          "description": "Style ID (system auto-determines the next rank)"
         },
         "gradingDate": {
          "type": "string",
          "description": "Grading date (YYYY-MM-DD)",
          "format": "date"
         }
        },
        "required": [
         "studentId",
         "styleId",
         "gradingDate"
        ]
       },
       "example": {
        "studentId": 1,
        "styleId": 1,
        "gradingDate": "2026-11-05"
       }
      }
     }
    }
   }
  },
  "/v1/grading/{studentId}/{styleId}": {
   "get": {
    "operationId": "grading_getHistory",
    "summary": "getHistory",
    "description": "Get grading history for a student in a specific style. Includes rank progression, skills, and eligibility info.",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/grading.GradingHistory"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "studentId": 1,
          "styleId": 1,
          "ranks": [
           {
            "id": 1,
            "studentId": 1,
            "rankId": 1,
            "rankName": "string",
            "styleName": "string",
            "gradingDate": "2026-11-05",
            "notes": "string"
           }
          ],
          "eligibility": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "styleId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/grading/{studentRankId}/notes": {
   "patch": {
    "operationId": "grading_updateNotes",
    "summary": "updateNotes",
    "description": "Update notes on a student rank record",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/grading.StudentRank"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "rankId": 1,
            "rankName": "string",
            "styleName": "string",
            "gradingDate": "2026-11-05",
            "notes": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "rankId": 1,
            "rankName": "string",
            "styleName": "string",
            "gradingDate": "2026-11-05",
            "notes": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentRankId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "notes": {
          "type": "string",
          "description": "Updated notes"
         }
        },
        "required": [
         "notes"
        ]
       },
       "example": {
        "notes": "string"
       }
      }
     }
    }
   }
  },
  "/v1/grading/{studentRankId}/grading-date": {
   "patch": {
    "operationId": "grading_updateGradingDate",
    "summary": "updateGradingDate",
    "description": "Update the grading date on a student rank record",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/grading.StudentRank"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "rankId": 1,
            "rankName": "string",
            "styleName": "string",
            "gradingDate": "2026-11-05",
            "notes": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "rankId": 1,
            "rankName": "string",
            "styleName": "string",
            "gradingDate": "2026-11-05",
            "notes": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentRankId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "gradingDate": {
          "type": "string",
          "description": "New grading date (YYYY-MM-DD)",
          "format": "date"
         }
        },
        "required": [
         "gradingDate"
        ]
       },
       "example": {
        "gradingDate": "2026-11-05"
       }
      }
     }
    }
   }
  },
  "/v1/grading/{studentRankId}/skill/{skillId}": {
   "patch": {
    "operationId": "grading_updateSkill",
    "summary": "updateSkill",
    "description": "Update a skill score and/or notes for a student rank",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/grading.SkillScore"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "studentRankId": 1,
            "skillId": 1,
            "score": "pass",
            "notes": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "studentRankId": 1,
            "skillId": 1,
            "score": "pass",
            "notes": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentRankId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "skillId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "score": {
          "type": "string",
          "description": "Skill score (pass/fail, or null to clear)",
          "enum": [
           "pass",
           "fail"
          ]
         },
         "notes": {
          "type": "string",
          "description": "Skill notes",
          "maxLength": 500
         }
        }
       },
       "example": {
        "score": "pass",
        "notes": "string"
       }
      }
     }
    }
   }
  },
  "/v1/grading/{studentRankId}": {
   "delete": {
    "operationId": "grading_deleteRank",
    "summary": "deleteRank",
    "description": "Delete a student rank record",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentRankId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/grading/roster": {
   "get": {
    "operationId": "grading_getRoster",
    "summary": "getRoster",
    "description": "Get the traffic-light roster (green/yellow/red/na bucketed list of students with eligibility scores) for one style.",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/grading.GradingRoster"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "styleId": 1,
          "styleName": "string",
          "rankNoun": "string",
          "counts": {},
          "green": [],
          "yellow": [],
          "red": [],
          "na": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Style to bucket against"
     },
     {
      "name": "rankIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "CSV of rank IDs to include (multi-select)"
     },
     {
      "name": "tagIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "CSV of tag IDs to filter by (OR semantics)"
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter to students enrolled at this venue"
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Search firstName/lastName/email"
     },
     {
      "name": "date",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix timestamp for in-attendance lookup; defaults to today"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/grading/promote/bulk": {
   "post": {
    "operationId": "grading_bulkPromote",
    "summary": "bulkPromote",
    "description": "Promote many students to their next rank in one transaction. Shares one group_hash for the post-promotion report and the 24-hour undo. With ?queue=true the run is queued as an operation instead: the answer is 202 { operationId, label }, followed through GET /v1/operations/:id, whose promote field carries the group hash and each promotion.",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/grading.BulkPromoteResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "groupHash": "string",
            "promotedCount": 1,
            "skippedCount": 1,
            "results": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "groupHash": "string",
            "promotedCount": 1,
            "skippedCount": 1,
            "results": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "Student IDs (1 to 10,000)",
          "items": {}
         },
         "styleId": {
          "type": "integer"
         },
         "gradingDate": {
          "type": "string",
          "description": "Grading date (YYYY-MM-DD)",
          "format": "date"
         },
         "targetRankId": {
          "type": "integer",
          "description": "Promote everyone to this rank in the style instead of each student's next rank; students at or above it are skipped"
         }
        },
        "required": [
         "studentIds",
         "styleId",
         "gradingDate"
        ]
       },
       "example": {
        "studentIds": [],
        "styleId": 1,
        "gradingDate": "2026-11-05"
       }
      }
     }
    }
   }
  },
  "/v1/grading/{studentRankId}/offset": {
   "patch": {
    "operationId": "grading_updateOffset",
    "summary": "updateOffset",
    "description": "Update the class-offset on a student rank (added to actualClasses in eligibility calc).",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/grading.StudentRank"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "rankId": 1,
            "rankName": "string",
            "styleName": "string",
            "gradingDate": "2026-11-05",
            "notes": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "rankId": 1,
            "rankName": "string",
            "styleName": "string",
            "gradingDate": "2026-11-05",
            "notes": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentRankId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "offset": {
          "type": "integer",
          "description": "Number of classes to credit/debit (-10000..10000)"
         }
        },
        "required": [
         "offset"
        ]
       },
       "example": {
        "offset": 1
       }
      }
     }
    }
   }
  },
  "/v1/grading/roster/export": {
   "get": {
    "operationId": "grading_exportRoster",
    "summary": "exportRoster",
    "description": "CSV export of the current roster filtered by the same shape as /roster.",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true
     },
     {
      "name": "rankIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "CSV of rank IDs"
     },
     {
      "name": "tagIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "CSV of tag IDs (OR semantics)"
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "date",
      "in": "query",
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/grading/promotions/{groupHash}/report": {
   "get": {
    "operationId": "grading_promotionReport",
    "summary": "promotionReport",
    "description": "CSV report of one bulk-promotion batch (one row per student).",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "groupHash",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/grading/students/{studentId}/export": {
   "get": {
    "operationId": "grading_exportStudentHistory",
    "summary": "exportStudentHistory",
    "description": "CSV of one student's full rank history across every style. Useful as a transfer record / audit document.",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/grading/students/{studentId}/archived": {
   "get": {
    "operationId": "grading_getArchivedHistory",
    "summary": "getArchivedHistory",
    "description": "Rank history in styles the student has history in but no longer holds a rank in (aged out of, or stopped training). Grouped by style, newest first. Manually deleted ranks are excluded. An empty list means nothing is archived.",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/grading.ArchivedGradingHistory"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "styles": [
           {
            "styleId": 1,
            "styleName": "string",
            "firstGradedOn": "2026-11-05",
            "lastGradedOn": "2026-11-05",
            "records": [
             {}
            ]
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/grading/promote/undo/{groupHash}": {
   "post": {
    "operationId": "grading_undoBulkPromote",
    "summary": "undoBulkPromote",
    "description": "Undo a bulk-promotion batch. Restores the prior rank for every student in the batch. Only valid within 24 hours of the original promotion. Requires ?confirm=true.",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/grading.BulkPromoteUndoResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "undoneCount": 1,
            "results": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "undoneCount": 1,
            "results": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "groupHash",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/grading/{studentRankId}/email": {
   "post": {
    "operationId": "grading_sendRankNotesEmail",
    "summary": "sendRankNotesEmail",
    "description": "Send the rank notes (and skill scorecard) for this student-rank to the student via Postmark. No body fields.",
    "tags": [
     "grading"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "studentRankId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/workflows/enroll-student": {
   "post": {
    "operationId": "workflows_enrollStudent",
    "summary": "enrollStudent",
    "description": "Create a student, optionally assign a billing plan, and optionally send a waiver for signature, in one call. Partial failures after the student is created are reported in warnings, never silently dropped. Preview-first: without ?confirm=true nothing is written and the response describes what would happen. Add ?confirm=true to execute.",
    "tags": [
     "workflows"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/workflows.WorkflowResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "mode": "preview",
            "summary": "string",
            "data": {},
            "warnings": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "mode": "preview",
            "summary": "string",
            "data": {},
            "warnings": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "student": {
          "type": "object",
          "description": "The student to create: exactly the POST /v1/students body (see the students module schema)."
         },
         "plan": {
          "type": "object",
          "description": "Optional plan assignment: exactly the POST /v1/students/:id/plan body (planId, paymentMethod, …). Requires the Manage Billing permission."
         },
         "waiverId": {
          "type": "number",
          "description": "Optional waiver to send for signature after creation. Requires the Waivers permission."
         }
        },
        "required": [
         "student"
        ]
       },
       "example": {
        "student": {}
       }
      }
     }
    }
   }
  },
  "/v1/workflows/convert-lead": {
   "post": {
    "operationId": "workflows_convertLead",
    "summary": "convertLead",
    "description": "Move a student through the lifecycle: Lead to Trial (to: \"trial\") or Trial to Member (to: \"member\"). Transitions are state-machine validated and refuse invalid jumps with an explanation. Preview-first: without ?confirm=true nothing is written and the response describes what would happen. Add ?confirm=true to execute.",
    "tags": [
     "workflows"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/workflows.WorkflowResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "mode": "preview",
            "summary": "string",
            "data": {},
            "warnings": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "mode": "preview",
            "summary": "string",
            "data": {},
            "warnings": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "number"
         },
         "to": {
          "type": "string",
          "description": "Target state. One step at a time: leads start a trial; trials convert to members.",
          "enum": [
           "trial",
           "member"
          ]
         },
         "trial": {
          "type": "object",
          "description": "Trial options (durationDays, classesLimit): only with to: \"trial\"."
         }
        },
        "required": [
         "studentId",
         "to"
        ]
       },
       "example": {
        "studentId": 1,
        "to": "trial"
       }
      }
     }
    }
   }
  },
  "/v1/workflows/check-in": {
   "post": {
    "operationId": "workflows_checkIn",
    "summary": "checkIn",
    "description": "Check a student in to a class: deducts passes, tracks trial classes, and charges pay-as-you-go plans where applicable. Preview-first: without ?confirm=true nothing is written and the response describes what would happen. Add ?confirm=true to execute.",
    "tags": [
     "workflows"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/workflows.WorkflowResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "mode": "preview",
            "summary": "string",
            "data": {},
            "warnings": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "mode": "preview",
            "summary": "string",
            "data": {},
            "warnings": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "number"
         },
         "venueId": {
          "type": "number"
         },
         "rankId": {
          "type": "number",
          "description": "The rank the student trains at in this class: one of their own ranks (GET /v1/students/:id lists them)."
         },
         "eventId": {
          "type": "number",
          "description": "Optional event/class to link the attendance to."
         },
         "timestamp": {
          "type": "number",
          "description": "Unix seconds; defaults to now."
         }
        },
        "required": [
         "studentId",
         "venueId",
         "rankId"
        ]
       },
       "example": {
        "studentId": 1,
        "venueId": 1,
        "rankId": 1
       }
      }
     }
    }
   }
  },
  "/v1/workflows/promote": {
   "post": {
    "operationId": "workflows_promote",
    "summary": "promote",
    "description": "Promote a student to the next rank in a style. Preview names the exact from and to ranks. Promotions can be undone within 24 hours. Preview-first: without ?confirm=true nothing is written and the response describes what would happen. Add ?confirm=true to execute.",
    "tags": [
     "workflows"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/workflows.WorkflowResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "mode": "preview",
            "summary": "string",
            "data": {},
            "warnings": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "mode": "preview",
            "summary": "string",
            "data": {},
            "warnings": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "number"
         },
         "styleId": {
          "type": "number"
         },
         "gradingDate": {
          "type": "string",
          "description": "YYYY-MM-DD; defaults to today in the school's timezone.",
          "format": "date"
         }
        },
        "required": [
         "studentId",
         "styleId"
        ]
       },
       "example": {
        "studentId": 1,
        "styleId": 1
       }
      }
     }
    }
   }
  },
  "/v1/workflows/assign-plan": {
   "post": {
    "operationId": "workflows_assignPlan",
    "summary": "assignPlan",
    "description": "Assign a billing plan to a student. Resolves the payment gateway (Stripe, GoCardless, or offline), tax, and family billing routing. Preview-first: without ?confirm=true nothing is written and the response describes what would happen. Add ?confirm=true to execute.",
    "tags": [
     "workflows"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/workflows.WorkflowResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "mode": "preview",
            "summary": "string",
            "data": {},
            "warnings": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "mode": "preview",
            "summary": "string",
            "data": {},
            "warnings": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "number"
         },
         "plan": {
          "type": "object",
          "description": "Exactly the POST /v1/students/:id/plan body (planId, paymentMethod, …)."
         }
        },
        "required": [
         "studentId",
         "plan"
        ]
       },
       "example": {
        "studentId": 1,
        "plan": {}
       }
      }
     }
    }
   }
  },
  "/v1/families": {
   "get": {
    "operationId": "families_list",
    "summary": "list",
    "description": "List all families with member counts and pagination",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/families.Family"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "email": "string",
           "phone": "string",
           "address": "string",
           "memberCount": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "Page number"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Items per page"
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Sort field Allowed fields: name, -name, created_at, -created_at"
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Search by family name"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "families_create",
    "summary": "create",
    "description": "Create a new family. A family groups existing students; contact details live on the member students, not on the family.",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/families.Family"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "string",
            "phone": "string",
            "address": "string",
            "memberCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "string",
            "phone": "string",
            "address": "string",
            "memberCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Family name, e.g. 'Smith Family' (max 100)"
         },
         "notes": {
          "type": "string",
          "description": "Free-text notes about the family (max 5000)"
         },
         "members": {
          "type": "array",
          "description": "Optionally seed the family in the same call: [{studentId (required), relationship, isBillingResponsible}]",
          "items": {}
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/families/search": {
   "get": {
    "operationId": "families_search",
    "summary": "search",
    "description": "Quick search families by name (for autocomplete/linking)",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/families.Family"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "email": "string",
           "phone": "string",
           "address": "string",
           "memberCount": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "Search query (min 1 char)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 10
      },
      "description": "Max results (1-50)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/families/{id}": {
   "get": {
    "operationId": "families_get",
    "summary": "get",
    "description": "Get a family with all members and details",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/families.FamilyDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "email": "string",
          "phone": "string",
          "address": "string",
          "members": [
           {
            "id": 1,
            "familyId": 1,
            "studentId": 1,
            "name": "string",
            "relationship": "string",
            "email": "string",
            "phone": "string"
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "families_update",
    "summary": "update",
    "description": "Update family details. To change membership use the addMember / updateMember / removeMember operations.",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/families.Family"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "string",
            "phone": "string",
            "address": "string",
            "memberCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "string",
            "phone": "string",
            "address": "string",
            "memberCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Family name (max 100)"
         },
         "notes": {
          "type": "string",
          "description": "Free-text notes (max 5000). Nullable."
         }
        }
       },
       "example": {
        "name": "string",
        "notes": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "families_delete",
    "summary": "delete",
    "description": "Delete a family (removes grouping, does not delete member students)",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/families/{id}/members": {
   "post": {
    "operationId": "families_addMember",
    "summary": "addMember",
    "description": "Add an existing student to the family. Non-student contacts are not supported here. Use a student's emergencyContacts for those.",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/families.FamilyMember"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "familyId": 1,
            "studentId": 1,
            "name": "string",
            "relationship": "string",
            "email": "string",
            "phone": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "familyId": 1,
            "studentId": 1,
            "name": "string",
            "relationship": "string",
            "email": "string",
            "phone": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer",
          "description": "The existing student to add"
         },
         "relationship": {
          "type": "string",
          "description": "Role within the family",
          "enum": [
           "parent",
           "child",
           "sibling",
           "spouse",
           "guardian",
           "grandparent",
           "other"
          ]
         },
         "isBillingResponsible": {
          "type": "boolean",
          "description": "Whether this member pays for the family. Default false. Refused if the family already has a billing member; move billing with POST /v1/families/:id/billing/transfer instead."
         }
        },
        "required": [
         "studentId"
        ]
       },
       "example": {
        "studentId": 1
       }
      }
     }
    }
   }
  },
  "/v1/families/{id}/members/{memberId}": {
   "patch": {
    "operationId": "families_updateMember",
    "summary": "updateMember",
    "description": "Update a family member's role. Personal details belong to the student record. Edit them via PATCH /v1/students/:id.",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/families.FamilyMember"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "familyId": 1,
            "studentId": 1,
            "name": "string",
            "relationship": "string",
            "email": "string",
            "phone": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "familyId": 1,
            "studentId": 1,
            "name": "string",
            "relationship": "string",
            "email": "string",
            "phone": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "memberId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Confirmation required (condition: billing_responsible_only). Pass confirm=true to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "relationship": {
          "type": "string",
          "description": "Updated role within the family. Nullable.",
          "enum": [
           "parent",
           "child",
           "sibling",
           "spouse",
           "guardian",
           "grandparent",
           "other"
          ]
         },
         "isBillingResponsible": {
          "type": "boolean",
          "description": "Whether this member pays for the family. Requires the Manage Billing permission. Changing WHO pays while active family subscriptions exist is refused; use POST /v1/families/:id/billing/transfer, which migrates the gateway subscriptions with the responsibility."
         }
        }
       },
       "example": {
        "relationship": "parent",
        "isBillingResponsible": false
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "families_removeMember",
    "summary": "removeMember",
    "description": "Remove a member from the family. Refused for the billing-responsible member while the family has subscriptions: move billing to another member first.",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "memberId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/families/{id}/billing": {
   "get": {
    "operationId": "families_getBilling",
    "summary": "getBilling",
    "description": "Get family billing information (all member billing plans)",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/families.FamilyBilling"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "familyId": 1,
          "members": [],
          "totalMonthly": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/families/{id}/transactions": {
   "get": {
    "operationId": "families_getTransactions",
    "summary": "getTransactions",
    "description": "Get family transaction history across all members",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/families.FamilyTransaction"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "studentId": 1,
           "studentName": "string",
           "amount": 1,
           "type": "string",
           "status": "successful",
           "failureReason": "string",
           "failedOn": 1,
           "createdOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "Page number"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Items per page"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/families/{id}/billing/validate": {
   "get": {
    "operationId": "families_validateBilling",
    "summary": "validateBilling",
    "description": "Check if a family is billing-ready (has a billing-responsible member with payment method).",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/families.BillingValidation"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "ready": false,
          "hasBillingMember": false,
          "billingMember": {},
          "issues": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/families/{id}/billing/plans": {
   "post": {
    "operationId": "families_assignPlan",
    "summary": "assignPlan",
    "description": "Assign an umbrella family plan. Subscription created on billing-responsible member's gateway customer.",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "planId": {
          "type": "integer",
          "description": "Plan ID to assign"
         },
         "startOn": {
          "type": [
           "string",
           "null"
          ],
          "description": "Future start date, YYYY-MM-DD (unix seconds also accepted); null starts now",
          "format": "date"
         },
         "endOn": {
          "type": [
           "string",
           "null"
          ],
          "description": "Fixed end date, YYYY-MM-DD (unix seconds also accepted); null is open-ended",
          "format": "date"
         },
         "discount": {
          "type": "number",
          "description": "Discount value (percentage 0-100 or fixed amount in cents)"
         },
         "discountType": {
          "type": "integer",
          "description": "0 = percentage, 1 = fixed amount",
          "enum": [
           0,
           1
          ]
         },
         "paymentMethod": {
          "type": "string",
          "description": "Payment method",
          "enum": [
           "stripe",
           "gocardless",
           "cash",
           "bank_transfer",
           "other"
          ]
         },
         "paymentRouting": {
          "type": "string",
          "description": "'family' = billing-responsible member pays",
          "enum": [
           "self",
           "family"
          ],
          "default": "self"
         }
        },
        "required": [
         "planId",
         "paymentMethod"
        ]
       },
       "example": {
        "planId": 1,
        "paymentMethod": "stripe"
       }
      }
     }
    }
   }
  },
  "/v1/families/{id}/billing/plans/{subId}/pause": {
   "post": {
    "operationId": "families_pausePlan",
    "summary": "pausePlan",
    "description": "Pause a family plan subscription. Only a plan that bills on a schedule can be paused: a pass pack or a one-time plan is refused with 409 PLAN_NOT_PAUSABLE, in the preview too.",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, PLAN_NOT_PAUSABLE",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PLAN_NOT_PAUSABLE",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "scheduledResumeOn": {
          "type": "string",
          "description": "Optional. The day the plan resumes by itself, YYYY-MM-DD in the school's zone, after today. Leave out to pause until someone resumes it.",
          "format": "date"
         }
        }
       },
       "example": {
        "scheduledResumeOn": "2026-11-05"
       }
      }
     }
    }
   }
  },
  "/v1/families/{id}/billing/plans/{subId}/resume": {
   "post": {
    "operationId": "families_resumePlan",
    "summary": "resumePlan",
    "description": "Resume a paused family plan subscription. A member on it who is a lead or inactive becomes an active student in the same write, when the plan is paid; the preview refuses where the resume would and says so in wouldBecome.becomesActive { studentId, from, note } (null otherwise).",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/families/{id}/billing/plans/{subId}": {
   "delete": {
    "operationId": "families_cancelPlan",
    "summary": "cancelPlan",
    "description": "Cancel a family plan subscription. Requires ?confirm=true.",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "atPeriodEnd": {
          "type": "boolean",
          "description": "If true, cancel at end of current billing period instead of immediately. Also accepted as a query param (query takes precedence).",
          "default": false
         },
         "cancelAt": {
          "type": "number",
          "description": "Unix timestamp for a specific future cancellation date. Cannot be combined with atPeriodEnd. Also accepted as a query param (query takes precedence)."
         }
        }
       },
       "example": {
        "atPeriodEnd": false,
        "cancelAt": 1
       }
      }
     }
    }
   }
  },
  "/v1/families/{id}/billing/transfer": {
   "post": {
    "operationId": "families_transferBilling",
    "summary": "transferBilling",
    "description": "Move billing responsibility to another family member. Recurring gateway subscriptions are re-created on the incoming payer and the current one cancelled, timed so nobody is charged twice. Payment methods do NOT transfer: the incoming payer needs their own card (pass paymentMethodId) or an existing Direct Debit mandate. Requires ?confirm=true.",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "toMemberId": {
          "type": "integer",
          "description": "Target family member ID to become billing-responsible"
         },
         "paymentMethodId": {
          "type": "string",
          "description": "Stripe payment method (pm_...) for the incoming payer, when they have no card on file"
         }
        },
        "required": [
         "toMemberId"
        ]
       },
       "example": {
        "toMemberId": 1
       }
      }
     }
    }
   }
  },
  "/v1/families/{id}/notes": {
   "get": {
    "operationId": "families_listNotes",
    "summary": "listNotes",
    "description": "Get all notes for a family",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/families.FamilyNote"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "familyId": 1,
           "content": "string",
           "createdBy": "string",
           "createdAt": "2026-11-05T18:00:00Z"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "families_createNote",
    "summary": "createNote",
    "description": "Add a note to a family",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/families.FamilyNote"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "familyId": 1,
            "content": "string",
            "createdBy": "string",
            "createdAt": "2026-11-05T18:00:00Z"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "familyId": 1,
            "content": "string",
            "createdBy": "string",
            "createdAt": "2026-11-05T18:00:00Z"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "content": {
          "type": "string",
          "description": "Note content"
         }
        },
        "required": [
         "content"
        ]
       },
       "example": {
        "content": "string"
       }
      }
     }
    }
   }
  },
  "/v1/families/{id}/notes/{noteId}": {
   "patch": {
    "operationId": "families_updateNote",
    "summary": "updateNote",
    "description": "Update a family note",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/families.FamilyNote"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "familyId": 1,
            "content": "string",
            "createdBy": "string",
            "createdAt": "2026-11-05T18:00:00Z"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "familyId": 1,
            "content": "string",
            "createdBy": "string",
            "createdAt": "2026-11-05T18:00:00Z"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "noteId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "content": {
          "type": "string",
          "description": "Updated note content"
         }
        },
        "required": [
         "content"
        ]
       },
       "example": {
        "content": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "families_deleteNote",
    "summary": "deleteNote",
    "description": "Delete a family note (soft delete)",
    "tags": [
     "families"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "noteId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/tags": {
   "get": {
    "operationId": "tags_list",
    "summary": "list",
    "description": "List all tags for the school with student counts",
    "tags": [
     "tags"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/tags.Tag"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "colour": "1F7F5C",
           "type": "manual",
           "studentCount": 1,
           "categoryId": 1,
           "rules": {}
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "tags_create",
    "summary": "create",
    "description": "Create a new tag",
    "tags": [
     "tags"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/tags.Tag"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "colour": "1F7F5C",
            "type": "manual",
            "studentCount": 1,
            "categoryId": 1,
            "rules": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "colour": "1F7F5C",
            "type": "manual",
            "studentCount": 1,
            "categoryId": 1,
            "rules": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Tag name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 30
         },
         "colour": {
          "type": "string",
          "description": "Hex colour code (e.g., FF5500 or #FF5500). Optional.",
          "pattern": "^#?[0-9A-Fa-f]{6}$",
          "format": "hex-color"
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/tags/{id}": {
   "get": {
    "operationId": "tags_get",
    "summary": "get",
    "description": "Get a single tag by ID with student count",
    "tags": [
     "tags"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/tags.Tag"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "colour": "1F7F5C",
          "type": "manual",
          "studentCount": 1,
          "categoryId": 1,
          "rules": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "tags_update",
    "summary": "update",
    "description": "Update an existing tag",
    "tags": [
     "tags"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/tags.Tag"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "colour": "1F7F5C",
            "type": "manual",
            "studentCount": 1,
            "categoryId": 1,
            "rules": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "colour": "1F7F5C",
            "type": "manual",
            "studentCount": 1,
            "categoryId": 1,
            "rules": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "New tag name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 30
         },
         "colour": {
          "type": "string",
          "description": "Hex colour code",
          "pattern": "^#?[0-9A-Fa-f]{6}$",
          "format": "hex-color"
         }
        }
       },
       "example": {
        "name": "string",
        "colour": "1F7F5C"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "tags_delete",
    "summary": "delete",
    "description": "Delete a tag and remove it from all students. Returns cascade effects showing how many students are affected.",
    "tags": [
     "tags"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/tags/bulk/delete": {
   "post": {
    "operationId": "tags_bulkDelete",
    "summary": "bulkDelete",
    "description": "Delete multiple tags at once. Returns cascade effects.",
    "tags": [
     "tags"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "tagIds": {
          "type": "array",
          "description": "Array of tag IDs to delete (1 to 100)",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "tagIds"
        ]
       },
       "example": {
        "tagIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/operations": {
   "get": {
    "operationId": "operations_list",
    "summary": "list",
    "description": "Running operations first, then those finished in the last 7 days, newest first, at most 20.",
    "tags": [
     "operations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/operations.Operation"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "type": "string",
           "label": "string",
           "status": "pending",
           "stopped": false,
           "stoppable": false,
           "startedBy": 1,
           "startedByName": "string",
           "createdAt": 1,
           "completedAt": 1,
           "lastProgressAt": 1,
           "failedReason": "string",
           "progress": {},
           "inFlight": {},
           "counts": {},
           "results": [],
           "file": {},
           "promote": {}
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/operations/{id}": {
   "get": {
    "operationId": "operations_get",
    "summary": "get",
    "description": "One operation with its per-student results.",
    "tags": [
     "operations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/operations.Operation"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "type": "string",
          "label": "string",
          "status": "pending",
          "stopped": false,
          "stoppable": false,
          "startedBy": 1,
          "startedByName": "string",
          "createdAt": 1,
          "completedAt": 1,
          "lastProgressAt": 1,
          "failedReason": "string",
          "progress": {},
          "inFlight": {},
          "counts": {},
          "results": [],
          "file": {},
          "promote": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/operations/{id}/stop": {
   "post": {
    "operationId": "operations_stop",
    "summary": "stop",
    "description": "Stop a run. A bulk assign, booking, chat broadcast or export stops after the student it is on; an export's half-built zip is discarded. A plan migration, price or tax change is stopped only once it has stalled for half an hour. A certificate batch cannot be stopped.",
    "tags": [
     "operations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/operations/{id}/request-payment": {
   "post": {
    "operationId": "operations_requestPayment",
    "summary": "requestPayment",
    "description": "After a bulk plan assign has finished, send the plan as a payment request (an emailed smart invoice) to students whose card was declined in that run. Each of those students' rows then reads requested. Refused while the run is going, and for any other kind of operation.",
    "tags": [
     "operations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "Students whose row in this run reads failed",
          "items": {}
         }
        },
        "required": [
         "studentIds"
        ]
       },
       "example": {
        "studentIds": []
       }
      }
     }
    }
   }
  },
  "/v1/statuses": {
   "get": {
    "operationId": "statuses_list",
    "summary": "list",
    "description": "List all statuses for the school with student counts",
    "tags": [
     "statuses"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/statuses.Status"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "order": 1,
           "studentCount": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "statuses_create",
    "summary": "create",
    "description": "Create a new status",
    "tags": [
     "statuses"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/statuses.Status"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "order": 1,
            "studentCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "order": 1,
            "studentCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Status name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 200
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/statuses/{id}": {
   "get": {
    "operationId": "statuses_get",
    "summary": "get",
    "description": "Get a single status by ID with student count",
    "tags": [
     "statuses"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/statuses.Status"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "order": 1,
          "studentCount": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "statuses_update",
    "summary": "update",
    "description": "Update an existing status",
    "tags": [
     "statuses"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/statuses.Status"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "order": 1,
            "studentCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "order": 1,
            "studentCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "New status name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 200
         }
        }
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "statuses_delete",
    "summary": "delete",
    "description": "Delete a status and remove it from all students. Returns cascade effects showing how many students are affected.",
    "tags": [
     "statuses"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/statuses/bulk/delete": {
   "post": {
    "operationId": "statuses_bulkDelete",
    "summary": "bulkDelete",
    "description": "Delete multiple statuses at once. Returns cascade effects.",
    "tags": [
     "statuses"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "statusIds": {
          "type": "array",
          "description": "Array of status IDs to delete (1 to 100)",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "statusIds"
        ]
       },
       "example": {
        "statusIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/clubs": {
   "get": {
    "operationId": "clubs_list",
    "summary": "list",
    "description": "List all clubs for the school with student counts",
    "tags": [
     "clubs"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/clubs.Club"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "studentCount": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "clubs_create",
    "summary": "create",
    "description": "Create a new club",
    "tags": [
     "clubs"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/clubs.Club"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "studentCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "studentCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Club name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 255
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/clubs/{id}": {
   "get": {
    "operationId": "clubs_get",
    "summary": "get",
    "description": "Get a single club by ID with student count",
    "tags": [
     "clubs"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/clubs.Club"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "studentCount": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "clubs_update",
    "summary": "update",
    "description": "Update an existing club",
    "tags": [
     "clubs"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/clubs.Club"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "studentCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "studentCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "New club name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 255
         }
        }
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "clubs_delete",
    "summary": "delete",
    "description": "Delete a club and remove it from all students. Returns cascade effects showing how many students are affected.",
    "tags": [
     "clubs"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/clubs/bulk/delete": {
   "post": {
    "operationId": "clubs_bulkDelete",
    "summary": "bulkDelete",
    "description": "Delete multiple clubs at once. Returns cascade effects.",
    "tags": [
     "clubs"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "clubIds": {
          "type": "array",
          "description": "Array of club IDs to delete (1–100)",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "clubIds"
        ]
       },
       "example": {
        "clubIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/locations": {
   "get": {
    "operationId": "locations_list",
    "summary": "list",
    "description": "List all locations for the school",
    "tags": [
     "locations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/locations.Location"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "address": "string",
           "suburb": "string",
           "state": "string",
           "country": "string",
           "postcode": "string",
           "contactNumber": "string",
           "capacity": 1,
           "latitude": 1,
           "longitude": 1,
           "createdOn": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "locations_create",
    "summary": "create",
    "description": "Create a new location",
    "tags": [
     "locations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/locations.Location"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "address": "string",
            "suburb": "string",
            "state": "string",
            "country": "string",
            "postcode": "string",
            "contactNumber": "string",
            "capacity": 1,
            "latitude": 1,
            "longitude": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "address": "string",
            "suburb": "string",
            "state": "string",
            "country": "string",
            "postcode": "string",
            "contactNumber": "string",
            "capacity": 1,
            "latitude": 1,
            "longitude": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Location name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 500
         },
         "address": {
          "type": "string",
          "description": "Street address",
          "maxLength": 500
         },
         "suburb": {
          "type": "string",
          "description": "Suburb or city",
          "maxLength": 100
         },
         "state": {
          "type": "string",
          "description": "State or region",
          "maxLength": 100
         },
         "country": {
          "type": "string",
          "description": "Country",
          "maxLength": 100
         },
         "postcode": {
          "type": "string",
          "description": "Postal code",
          "maxLength": 20
         },
         "contactNumber": {
          "type": "string",
          "description": "Contact phone number",
          "maxLength": 100
         },
         "capacity": {
          "type": "integer",
          "description": "Maximum venue capacity",
          "minimum": 1
         },
         "latitude": {
          "type": "number",
          "description": "GPS latitude coordinate",
          "minimum": -90,
          "maximum": 90
         },
         "longitude": {
          "type": "number",
          "description": "GPS longitude coordinate",
          "minimum": -180,
          "maximum": 180
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/locations/{id}": {
   "get": {
    "operationId": "locations_get",
    "summary": "get",
    "description": "Get a single location by ID",
    "tags": [
     "locations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/locations.Location"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "address": "string",
          "suburb": "string",
          "state": "string",
          "country": "string",
          "postcode": "string",
          "contactNumber": "string",
          "capacity": 1,
          "latitude": 1,
          "longitude": 1,
          "createdOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "locations_update",
    "summary": "update",
    "description": "Update an existing location",
    "tags": [
     "locations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/locations.Location"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "address": "string",
            "suburb": "string",
            "state": "string",
            "country": "string",
            "postcode": "string",
            "contactNumber": "string",
            "capacity": 1,
            "latitude": 1,
            "longitude": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "address": "string",
            "suburb": "string",
            "state": "string",
            "country": "string",
            "postcode": "string",
            "contactNumber": "string",
            "capacity": 1,
            "latitude": 1,
            "longitude": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Location name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 500
         },
         "address": {
          "type": "string",
          "description": "Street address",
          "maxLength": 500
         },
         "suburb": {
          "type": "string",
          "description": "Suburb or city",
          "maxLength": 100
         },
         "state": {
          "type": "string",
          "description": "State or region",
          "maxLength": 100
         },
         "country": {
          "type": "string",
          "description": "Country",
          "maxLength": 100
         },
         "postcode": {
          "type": "string",
          "description": "Postal code",
          "maxLength": 20
         },
         "contactNumber": {
          "type": "string",
          "description": "Contact phone number",
          "maxLength": 100
         },
         "capacity": {
          "type": "integer",
          "description": "Maximum venue capacity",
          "minimum": 1
         },
         "latitude": {
          "type": "number",
          "description": "GPS latitude coordinate",
          "minimum": -90,
          "maximum": 90
         },
         "longitude": {
          "type": "number",
          "description": "GPS longitude coordinate",
          "minimum": -180,
          "maximum": 180
         }
        }
       },
       "example": {
        "name": "string",
        "address": "string",
        "suburb": "string",
        "state": "string",
        "country": "string",
        "postcode": "string",
        "contactNumber": "string",
        "capacity": 1,
        "latitude": 1,
        "longitude": 1
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "locations_delete",
    "summary": "delete",
    "description": "Delete a location (soft delete). Requires confirmation.",
    "tags": [
     "locations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/locations/bulk/delete": {
   "post": {
    "operationId": "locations_bulkDelete",
    "summary": "bulkDelete",
    "description": "Delete multiple locations at once (soft delete). Requires confirmation.",
    "tags": [
     "locations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "locationIds": {
          "type": "array",
          "description": "Array of location IDs to delete (1–100)",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "locationIds"
        ]
       },
       "example": {
        "locationIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/skills": {
   "get": {
    "operationId": "skills_list",
    "summary": "list",
    "description": "List all skills for the school with rank counts",
    "tags": [
     "skills"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/skills.Skill"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "order": 1,
           "rankCount": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "skills_create",
    "summary": "create",
    "description": "Create a new skill",
    "tags": [
     "skills"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/skills.Skill"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "order": 1,
            "rankCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "order": 1,
            "rankCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Skill name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 200
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/skills/{id}": {
   "get": {
    "operationId": "skills_get",
    "summary": "get",
    "description": "Get a single skill by ID with rank count",
    "tags": [
     "skills"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/skills.Skill"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "order": 1,
          "rankCount": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "skills_update",
    "summary": "update",
    "description": "Update an existing skill",
    "tags": [
     "skills"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/skills.Skill"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "order": 1,
            "rankCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "order": 1,
            "rankCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "New skill name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 200
         }
        }
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "skills_delete",
    "summary": "delete",
    "description": "Delete a skill and remove it from all ranks. Returns cascade effects showing how many ranks are affected.",
    "tags": [
     "skills"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/styles": {
   "get": {
    "operationId": "styles_list",
    "summary": "list",
    "description": "List all styles for the school with rank and student counts",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/styles.Style"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "rankNoun": "string",
           "rankCount": 1,
           "studentCount": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "styles_create",
    "summary": "create",
    "description": "Create a new style, optionally from a template or with manual ranks",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/styles.StyleWithRanks"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "rankNoun": "string",
            "rankCount": 1,
            "studentCount": 1,
            "ranks": [
             {
              "id": 1,
              "name": "string",
              "color": "string",
              "colorAlt": "string",
              "stripes": 1,
              "stripeColor": "string",
              "numCheckins": 1,
              "numDays": 1,
              "operator": "OR",
              "order": 1,
              "studentCount": 1,
              "skills": [
               {}
              ]
             }
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "rankNoun": "string",
            "rankCount": 1,
            "studentCount": 1,
            "ranks": [
             {
              "id": 1,
              "name": "string",
              "color": "string",
              "colorAlt": "string",
              "stripes": 1,
              "stripeColor": "string",
              "numCheckins": 1,
              "numDays": 1,
              "operator": "OR",
              "order": 1,
              "studentCount": 1,
              "skills": [
               {}
              ]
             }
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Style name (e.g., 'Brazilian Jiu-Jitsu')",
          "minLength": 1,
          "maxLength": 255
         },
         "rankNoun": {
          "type": "string",
          "description": "Custom noun for ranks in this style (e.g., 'Belt', 'Level'). Defaults to 'Rank'.",
          "maxLength": 50
         },
         "templateId": {
          "type": "string",
          "description": "Optional template ID to pre-populate ranks (see /templates endpoint)"
         },
         "ranks": {
          "type": "array",
          "description": "Manual ranks to create (ignored if templateId is provided)",
          "items": {
           "$ref": "#/components/schemas/styles.RankInput"
          }
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/styles/templates": {
   "get": {
    "operationId": "styles_templates",
    "summary": "templates",
    "description": "List available style templates for quick creation (e.g., BJJ, Taekwondo, Karate variants). Templates include pre-configured rank progressions. Returns { templates: TemplatePreview[], categories: string[] }",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/styles.TemplatesResponse"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "templates": [
           {
            "id": "string",
            "name": "string",
            "category": "string",
            "origin": "string",
            "rankCount": 1,
            "rankPreview": [
             "string"
            ]
           }
          ],
          "categories": [
           "string"
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/styles/{id}": {
   "get": {
    "operationId": "styles_get",
    "summary": "get",
    "description": "Get a single style with all its ranks and skills",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/styles.StyleWithRanks"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "rankNoun": "string",
          "rankCount": 1,
          "studentCount": 1,
          "ranks": [
           {
            "id": 1,
            "name": "string",
            "color": "string",
            "colorAlt": "string",
            "stripes": 1,
            "stripeColor": "string",
            "numCheckins": 1,
            "numDays": 1,
            "operator": "OR",
            "order": 1,
            "studentCount": 1,
            "skills": [
             {}
            ]
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "styles_update",
    "summary": "update",
    "description": "Update a style's name or rank noun",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/styles.StyleWithRanks"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "rankNoun": "string",
            "rankCount": 1,
            "studentCount": 1,
            "ranks": [
             {
              "id": 1,
              "name": "string",
              "color": "string",
              "colorAlt": "string",
              "stripes": 1,
              "stripeColor": "string",
              "numCheckins": 1,
              "numDays": 1,
              "operator": "OR",
              "order": 1,
              "studentCount": 1,
              "skills": [
               {}
              ]
             }
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "rankNoun": "string",
            "rankCount": 1,
            "studentCount": 1,
            "ranks": [
             {
              "id": 1,
              "name": "string",
              "color": "string",
              "colorAlt": "string",
              "stripes": 1,
              "stripeColor": "string",
              "numCheckins": 1,
              "numDays": 1,
              "operator": "OR",
              "order": 1,
              "studentCount": 1,
              "skills": [
               {}
              ]
             }
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "New style name",
          "minLength": 1,
          "maxLength": 255
         },
         "rankNoun": {
          "type": "string",
          "description": "New rank noun (set to null to remove)",
          "maxLength": 50
         }
        }
       },
       "example": {
        "name": "string",
        "rankNoun": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "styles_delete",
    "summary": "delete",
    "description": "Delete a style and all its ranks. Returns cascade effects showing impacted students.",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/styles/{id}/clone": {
   "post": {
    "operationId": "styles_clone",
    "summary": "clone",
    "description": "Clone a style with all its ranks",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/styles.StyleWithRanks"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "rankNoun": "string",
            "rankCount": 1,
            "studentCount": 1,
            "ranks": [
             {
              "id": 1,
              "name": "string",
              "color": "string",
              "colorAlt": "string",
              "stripes": 1,
              "stripeColor": "string",
              "numCheckins": 1,
              "numDays": 1,
              "operator": "OR",
              "order": 1,
              "studentCount": 1,
              "skills": [
               {}
              ]
             }
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "rankNoun": "string",
            "rankCount": 1,
            "studentCount": 1,
            "ranks": [
             {
              "id": 1,
              "name": "string",
              "color": "string",
              "colorAlt": "string",
              "stripes": 1,
              "stripeColor": "string",
              "numCheckins": 1,
              "numDays": 1,
              "operator": "OR",
              "order": 1,
              "studentCount": 1,
              "skills": [
               {}
              ]
             }
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Optional name for the cloned style (defaults to 'Original (Copy)')"
         }
        }
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/styles/{id}/ranks": {
   "post": {
    "operationId": "styles_createRank",
    "summary": "createRank",
    "description": "Add a new rank to a style (added at the end)",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/styles.Rank"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "color": "string",
            "colorAlt": "string",
            "stripes": 1,
            "stripeColor": "string",
            "numCheckins": 1,
            "numDays": 1,
            "operator": "OR",
            "order": 1,
            "studentCount": 1,
            "skills": [
             {
              "id": 1,
              "name": "string"
             }
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "color": "string",
            "colorAlt": "string",
            "stripes": 1,
            "stripeColor": "string",
            "numCheckins": 1,
            "numDays": 1,
            "operator": "OR",
            "order": 1,
            "studentCount": 1,
            "skills": [
             {
              "id": 1,
              "name": "string"
             }
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Rank name (e.g., 'White Belt')",
          "minLength": 1,
          "maxLength": 100
         },
         "color": {
          "type": "string",
          "description": "Primary color as 6-character hex (e.g., 'FFFFFF' or '#FFFFFF')",
          "pattern": "^#?[0-9A-Fa-f]{6}$"
         },
         "colorAlt": {
          "type": "string",
          "description": "Optional secondary color for gradient effect (can be null)",
          "pattern": "^#?[0-9A-Fa-f]{6}$"
         },
         "stripes": {
          "type": "integer",
          "description": "Number of stripes (0-9)",
          "minimum": 0,
          "maximum": 9
         },
         "stripeColor": {
          "type": "string",
          "description": "Stripe color (required if stripes > 0, can be null)",
          "pattern": "^#?[0-9A-Fa-f]{6}$"
         },
         "numCheckins": {
          "type": "integer",
          "description": "Required attendance count for grading eligibility (can be null)",
          "minimum": 0
         },
         "numDays": {
          "type": "integer",
          "description": "Required days at rank for grading eligibility (can be null)",
          "minimum": 0
         },
         "operator": {
          "type": "string",
          "description": "How to combine requirements: 'OR' (either requirement suffices) or 'AND' (both required)",
          "enum": [
           "OR",
           "AND"
          ]
         },
         "skillIds": {
          "type": "array",
          "description": "Skill IDs required for this rank",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "name",
         "color"
        ]
       },
       "example": {
        "name": "string",
        "color": "1F7F5C"
       }
      }
     }
    }
   }
  },
  "/v1/styles/{id}/ranks/{rankId}": {
   "patch": {
    "operationId": "styles_updateRank",
    "summary": "updateRank",
    "description": "Update a rank's properties",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/styles.Rank"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "color": "string",
            "colorAlt": "string",
            "stripes": 1,
            "stripeColor": "string",
            "numCheckins": 1,
            "numDays": 1,
            "operator": "OR",
            "order": 1,
            "studentCount": 1,
            "skills": [
             {
              "id": 1,
              "name": "string"
             }
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "color": "string",
            "colorAlt": "string",
            "stripes": 1,
            "stripeColor": "string",
            "numCheckins": 1,
            "numDays": 1,
            "operator": "OR",
            "order": 1,
            "studentCount": 1,
            "skills": [
             {
              "id": 1,
              "name": "string"
             }
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "rankId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
         },
         "color": {
          "type": "string",
          "pattern": "^#?[0-9A-Fa-f]{6}$"
         },
         "colorAlt": {
          "type": "string",
          "description": "Can be null to clear",
          "pattern": "^#?[0-9A-Fa-f]{6}$"
         },
         "stripes": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9
         },
         "stripeColor": {
          "type": "string",
          "description": "Can be null to clear",
          "pattern": "^#?[0-9A-Fa-f]{6}$"
         },
         "numCheckins": {
          "type": "integer",
          "description": "Can be null to clear",
          "minimum": 0
         },
         "numDays": {
          "type": "integer",
          "description": "Can be null to clear",
          "minimum": 0
         },
         "operator": {
          "type": "string",
          "enum": [
           "OR",
           "AND"
          ]
         },
         "skillIds": {
          "type": "array",
          "items": {
           "type": "integer"
          }
         }
        }
       },
       "example": {
        "name": "string",
        "color": "1F7F5C",
        "colorAlt": "1F7F5C",
        "stripes": 1,
        "stripeColor": "1F7F5C",
        "numCheckins": 1,
        "numDays": 1,
        "operator": "OR",
        "skillIds": [
         1
        ]
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "styles_deleteRank",
    "summary": "deleteRank",
    "description": "Delete a rank. Returns cascade effects showing impacted students.",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "rankId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/styles/reorder": {
   "patch": {
    "operationId": "styles_reorderStyles",
    "summary": "reorderStyles",
    "description": "Put the school's styles in order. Every list of the school's styles reads in this order; a style not in the list keeps no position and sorts after the ordered ones, by name.",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/styles.Style"
             }
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": [
            {
             "id": 1,
             "name": "string",
             "rankNoun": "string",
             "rankCount": 1,
             "studentCount": 1
            }
           ]
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": [
            {
             "id": 1,
             "name": "string",
             "rankNoun": "string",
             "rankCount": 1,
             "studentCount": 1
            }
           ],
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "styleIds": {
          "type": "array",
          "description": "The school's style IDs in the desired order. Every id must be one of the school's live styles.",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "styleIds"
        ]
       },
       "example": {
        "styleIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/styles/{id}/ranks/reorder": {
   "patch": {
    "operationId": "styles_reorderRanks",
    "summary": "reorderRanks",
    "description": "Reorder ranks within a style",
    "tags": [
     "styles"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/styles.Rank"
             }
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": [
            {
             "id": 1,
             "name": "string",
             "color": "string",
             "colorAlt": "string",
             "stripes": 1,
             "stripeColor": "string",
             "numCheckins": 1,
             "numDays": 1,
             "operator": "OR",
             "order": 1,
             "studentCount": 1,
             "skills": [
              {
               "id": 1,
               "name": "string"
              }
             ]
            }
           ]
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": [
            {
             "id": 1,
             "name": "string",
             "color": "string",
             "colorAlt": "string",
             "stripes": 1,
             "stripeColor": "string",
             "numCheckins": 1,
             "numDays": 1,
             "operator": "OR",
             "order": 1,
             "studentCount": 1,
             "skills": [
              {
               "id": 1,
               "name": "string"
              }
             ]
            }
           ],
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "rankIds": {
          "type": "array",
          "description": "Array of rank IDs in the desired order. Must include all ranks in the style.",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "rankIds"
        ]
       },
       "example": {
        "rankIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/waivers": {
   "get": {
    "operationId": "waivers_list",
    "summary": "list",
    "description": "List waivers for the school. Cursor-paginated descending by id. Defaults to active (non-archived) waivers; pass ?archived=true to flip.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/waivers.Waiver"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/CursorMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "name": "string",
           "description": "string",
           "category": "waiver",
           "sourceType": "native",
           "signingMode": "sequential",
           "countersignerRequired": false,
           "required": false,
           "expiryDays": 1,
           "autoRenew": false,
           "renewalReminderDays": 1,
           "reminderSchedule": [
            1
           ],
           "archivedOn": 1,
           "createdOn": 1,
           "currentVersion": {
            "id": 1,
            "waiverId": 1,
            "versionNumber": 1,
            "bodyHtml": "string",
            "fields": [
             {}
            ],
            "sourcePdfKey": "string",
            "sourcePdfPages": 1,
            "effectiveFrom": 1,
            "createdBy": 1,
            "createdOn": 1
           },
           "signatureCounts": {
            "signed": 1,
            "pending": 1,
            "declined": 1,
            "expired": 1,
            "voided": 1
           }
          }
         ],
         "meta": {
          "count": 1,
          "total": 1,
          "nextCursor": null
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "category",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "waiver",
        "medical",
        "photo_release",
        "membership",
        "behavior",
        "custom"
       ]
      },
      "description": "Filter by category"
     },
     {
      "name": "archived",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Include archived (true) or only non-archived (false, default)."
     },
     {
      "name": "expand",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Comma-separated list of expansions: 'currentVersion' (inlines the latest published version body+fields), 'signatureCounts' (adds per-status counts)."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Pagination cursor (id of the last item from the previous page)."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Max items per page (1 to 100)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "waivers_create",
    "summary": "create",
    "description": "Create a new waiver. 'fromTemplate' seeds METADATA only (category); it does NOT publish the template body as v1; fetch the template and pass its content through 'initialVersion' or a later POST /:id/versions once reviewed. Only 'initialVersion' publishes atomically with create. Otherwise the waiver is a draft (no published version): unsendable and unsignable until POST /:id/versions.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/waivers.Waiver"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "waiver",
            "sourceType": "native",
            "signingMode": "sequential",
            "countersignerRequired": false,
            "required": false,
            "expiryDays": 1,
            "autoRenew": false,
            "renewalReminderDays": 1,
            "reminderSchedule": [
             1
            ],
            "archivedOn": 1,
            "createdOn": 1,
            "currentVersion": {
             "id": 1,
             "waiverId": 1,
             "versionNumber": 1,
             "bodyHtml": "string",
             "fields": [
              {}
             ],
             "sourcePdfKey": "string",
             "sourcePdfPages": 1,
             "effectiveFrom": 1,
             "createdBy": 1,
             "createdOn": 1
            },
            "signatureCounts": {
             "signed": 1,
             "pending": 1,
             "declined": 1,
             "expired": 1,
             "voided": 1
            }
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "waiver",
            "sourceType": "native",
            "signingMode": "sequential",
            "countersignerRequired": false,
            "required": false,
            "expiryDays": 1,
            "autoRenew": false,
            "renewalReminderDays": 1,
            "reminderSchedule": [
             1
            ],
            "archivedOn": 1,
            "createdOn": 1,
            "currentVersion": {
             "id": 1,
             "waiverId": 1,
             "versionNumber": 1,
             "bodyHtml": "string",
             "fields": [
              {}
             ],
             "sourcePdfKey": "string",
             "sourcePdfPages": 1,
             "effectiveFrom": 1,
             "createdBy": 1,
             "createdOn": 1
            },
            "signatureCounts": {
             "signed": 1,
             "pending": 1,
             "declined": 1,
             "expired": 1,
             "voided": 1
            }
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
         },
         "description": {
          "type": "string",
          "maxLength": 2000
         },
         "category": {
          "type": "string",
          "enum": [
           "waiver",
           "medical",
           "photo_release",
           "membership",
           "behavior",
           "custom"
          ],
          "default": "custom"
         },
         "sourceType": {
          "type": "string",
          "enum": [
           "native",
           "uploaded_pdf"
          ],
          "default": "native"
         },
         "signingMode": {
          "type": "string",
          "enum": [
           "sequential",
           "parallel"
          ],
          "default": "sequential"
         },
         "countersignerRequired": {
          "type": "boolean",
          "default": false
         },
         "required": {
          "type": "boolean",
          "default": false
         },
         "expiryDays": {
          "type": "integer",
          "description": "Days after signing until the signature expires.",
          "minimum": 1,
          "maximum": 36500
         },
         "autoRenew": {
          "type": "boolean",
          "description": "Automatically create + email a fresh signing request when a signed waiver expires. Requires expiryDays to have any effect."
         },
         "renewalReminderDays": {
          "type": "integer",
          "description": "Email signers this many days before their signed waiver expires. Null = no expiry reminder email.",
          "minimum": 1,
          "maximum": 365
         },
         "reminderSchedule": {
          "type": "array",
          "description": "Nag cadence for UNANSWERED requests: day-offsets from requested_on (max 10 entries). Distinct from renewalReminderDays, which is about signed waivers approaching expiry.",
          "items": {
           "type": "integer"
          }
         },
         "fromTemplate": {
          "type": "string",
          "description": "Template slug to seed metadata (category) from. Body/fields are NOT auto-published: review the template content and publish it explicitly."
         },
         "initialVersion": {
          "type": "object",
          "description": "Optional v1 payload, atomically published with create.",
          "properties": {
           "bodyHtml": {
            "type": "string",
            "maxLength": 500000
           },
           "fields": {
            "type": "array",
            "items": {
             "$ref": "#/components/schemas/waivers.Field"
            }
           },
           "sourcePdfKey": {
            "type": "string",
            "description": "Storage key from prior PDF upload (uploaded_pdf only)."
           },
           "sourcePdfPages": {
            "type": "integer",
            "minimum": 1
           }
          }
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/waivers/{id}": {
   "get": {
    "operationId": "waivers_get",
    "summary": "get",
    "description": "Get a single waiver by ID, with current version inlined.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/waivers.Waiver"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "name": "string",
          "description": "string",
          "category": "waiver",
          "sourceType": "native",
          "signingMode": "sequential",
          "countersignerRequired": false,
          "required": false,
          "expiryDays": 1,
          "autoRenew": false,
          "renewalReminderDays": 1,
          "reminderSchedule": [
           1
          ],
          "archivedOn": 1,
          "createdOn": 1,
          "currentVersion": {
           "id": 1,
           "waiverId": 1,
           "versionNumber": 1,
           "bodyHtml": "string",
           "fields": [
            {}
           ],
           "sourcePdfKey": "string",
           "sourcePdfPages": 1,
           "effectiveFrom": 1,
           "createdBy": 1,
           "createdOn": 1
          },
          "signatureCounts": {
           "signed": 1,
           "pending": 1,
           "declined": 1,
           "expired": 1,
           "voided": 1
          }
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "expand",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Comma-separated expansions. Currently supports 'signatureCounts'."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "waivers_update",
    "summary": "update",
    "description": "Update waiver metadata only (name, description, category, signing config, lifecycle). Body/fields edits MUST use POST /:id/versions. The atomic-operation invariant prevents conflating a 'save' with a version bump.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/waivers.Waiver"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "waiver",
            "sourceType": "native",
            "signingMode": "sequential",
            "countersignerRequired": false,
            "required": false,
            "expiryDays": 1,
            "autoRenew": false,
            "renewalReminderDays": 1,
            "reminderSchedule": [
             1
            ],
            "archivedOn": 1,
            "createdOn": 1,
            "currentVersion": {
             "id": 1,
             "waiverId": 1,
             "versionNumber": 1,
             "bodyHtml": "string",
             "fields": [
              {}
             ],
             "sourcePdfKey": "string",
             "sourcePdfPages": 1,
             "effectiveFrom": 1,
             "createdBy": 1,
             "createdOn": 1
            },
            "signatureCounts": {
             "signed": 1,
             "pending": 1,
             "declined": 1,
             "expired": 1,
             "voided": 1
            }
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "waiver",
            "sourceType": "native",
            "signingMode": "sequential",
            "countersignerRequired": false,
            "required": false,
            "expiryDays": 1,
            "autoRenew": false,
            "renewalReminderDays": 1,
            "reminderSchedule": [
             1
            ],
            "archivedOn": 1,
            "createdOn": 1,
            "currentVersion": {
             "id": 1,
             "waiverId": 1,
             "versionNumber": 1,
             "bodyHtml": "string",
             "fields": [
              {}
             ],
             "sourcePdfKey": "string",
             "sourcePdfPages": 1,
             "effectiveFrom": 1,
             "createdBy": 1,
             "createdOn": 1
            },
            "signatureCounts": {
             "signed": 1,
             "pending": 1,
             "declined": 1,
             "expired": 1,
             "voided": 1
            }
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
         },
         "description": {
          "type": "string",
          "maxLength": 2000
         },
         "category": {
          "type": "string",
          "enum": [
           "waiver",
           "medical",
           "photo_release",
           "membership",
           "behavior",
           "custom"
          ]
         },
         "sourceType": {
          "type": "string",
          "enum": [
           "native",
           "uploaded_pdf"
          ]
         },
         "signingMode": {
          "type": "string",
          "enum": [
           "sequential",
           "parallel"
          ]
         },
         "countersignerRequired": {
          "type": "boolean"
         },
         "required": {
          "type": "boolean"
         },
         "expiryDays": {
          "type": "integer",
          "minimum": 1,
          "maximum": 36500
         },
         "autoRenew": {
          "type": "boolean"
         },
         "renewalReminderDays": {
          "type": "integer",
          "minimum": 1,
          "maximum": 365
         },
         "reminderSchedule": {
          "type": "array",
          "items": {
           "type": "integer"
          }
         }
        }
       },
       "example": {
        "name": "string",
        "description": "string",
        "category": "waiver",
        "sourceType": "native",
        "signingMode": "sequential",
        "countersignerRequired": false,
        "required": false,
        "expiryDays": 1,
        "autoRenew": false,
        "renewalReminderDays": 1,
        "reminderSchedule": [
         1
        ]
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "waivers_delete",
    "summary": "delete",
    "description": "Soft-delete a waiver (sets deletedOn). Existing signatures are retained but the waiver becomes invisible to all list/get operations. Supports ?preview=true. Requires ?confirm=true.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/waivers.Waiver"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "waiver",
            "sourceType": "native",
            "signingMode": "sequential",
            "countersignerRequired": false,
            "required": false,
            "expiryDays": 1,
            "autoRenew": false,
            "renewalReminderDays": 1,
            "reminderSchedule": [
             1
            ],
            "archivedOn": 1,
            "createdOn": 1,
            "currentVersion": {
             "id": 1,
             "waiverId": 1,
             "versionNumber": 1,
             "bodyHtml": "string",
             "fields": [
              {}
             ],
             "sourcePdfKey": "string",
             "sourcePdfPages": 1,
             "effectiveFrom": 1,
             "createdBy": 1,
             "createdOn": 1
            },
            "signatureCounts": {
             "signed": 1,
             "pending": 1,
             "declined": 1,
             "expired": 1,
             "voided": 1
            }
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "waiver",
            "sourceType": "native",
            "signingMode": "sequential",
            "countersignerRequired": false,
            "required": false,
            "expiryDays": 1,
            "autoRenew": false,
            "renewalReminderDays": 1,
            "reminderSchedule": [
             1
            ],
            "archivedOn": 1,
            "createdOn": 1,
            "currentVersion": {
             "id": 1,
             "waiverId": 1,
             "versionNumber": 1,
             "bodyHtml": "string",
             "fields": [
              {}
             ],
             "sourcePdfKey": "string",
             "sourcePdfPages": 1,
             "effectiveFrom": 1,
             "createdBy": 1,
             "createdOn": 1
            },
            "signatureCounts": {
             "signed": 1,
             "pending": 1,
             "declined": 1,
             "expired": 1,
             "voided": 1
            }
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/waivers/{id}/archive": {
   "post": {
    "operationId": "waivers_archive",
    "summary": "archive",
    "description": "Archive a waiver. Archived waivers are hidden from default lists, cannot be requested, but existing signatures remain accessible. Idempotent: re-archiving a previously archived waiver is a no-op.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/waivers.Waiver"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "waiver",
            "sourceType": "native",
            "signingMode": "sequential",
            "countersignerRequired": false,
            "required": false,
            "expiryDays": 1,
            "autoRenew": false,
            "renewalReminderDays": 1,
            "reminderSchedule": [
             1
            ],
            "archivedOn": 1,
            "createdOn": 1,
            "currentVersion": {
             "id": 1,
             "waiverId": 1,
             "versionNumber": 1,
             "bodyHtml": "string",
             "fields": [
              {}
             ],
             "sourcePdfKey": "string",
             "sourcePdfPages": 1,
             "effectiveFrom": 1,
             "createdBy": 1,
             "createdOn": 1
            },
            "signatureCounts": {
             "signed": 1,
             "pending": 1,
             "declined": 1,
             "expired": 1,
             "voided": 1
            }
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "waiver",
            "sourceType": "native",
            "signingMode": "sequential",
            "countersignerRequired": false,
            "required": false,
            "expiryDays": 1,
            "autoRenew": false,
            "renewalReminderDays": 1,
            "reminderSchedule": [
             1
            ],
            "archivedOn": 1,
            "createdOn": 1,
            "currentVersion": {
             "id": 1,
             "waiverId": 1,
             "versionNumber": 1,
             "bodyHtml": "string",
             "fields": [
              {}
             ],
             "sourcePdfKey": "string",
             "sourcePdfPages": 1,
             "effectiveFrom": 1,
             "createdBy": 1,
             "createdOn": 1
            },
            "signatureCounts": {
             "signed": 1,
             "pending": 1,
             "declined": 1,
             "expired": 1,
             "voided": 1
            }
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/waivers/{id}/unarchive": {
   "post": {
    "operationId": "waivers_unarchive",
    "summary": "unarchive",
    "description": "Restore an archived waiver. Idempotent.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/waivers.Waiver"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "waiver",
            "sourceType": "native",
            "signingMode": "sequential",
            "countersignerRequired": false,
            "required": false,
            "expiryDays": 1,
            "autoRenew": false,
            "renewalReminderDays": 1,
            "reminderSchedule": [
             1
            ],
            "archivedOn": 1,
            "createdOn": 1,
            "currentVersion": {
             "id": 1,
             "waiverId": 1,
             "versionNumber": 1,
             "bodyHtml": "string",
             "fields": [
              {}
             ],
             "sourcePdfKey": "string",
             "sourcePdfPages": 1,
             "effectiveFrom": 1,
             "createdBy": 1,
             "createdOn": 1
            },
            "signatureCounts": {
             "signed": 1,
             "pending": 1,
             "declined": 1,
             "expired": 1,
             "voided": 1
            }
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "waiver",
            "sourceType": "native",
            "signingMode": "sequential",
            "countersignerRequired": false,
            "required": false,
            "expiryDays": 1,
            "autoRenew": false,
            "renewalReminderDays": 1,
            "reminderSchedule": [
             1
            ],
            "archivedOn": 1,
            "createdOn": 1,
            "currentVersion": {
             "id": 1,
             "waiverId": 1,
             "versionNumber": 1,
             "bodyHtml": "string",
             "fields": [
              {}
             ],
             "sourcePdfKey": "string",
             "sourcePdfPages": 1,
             "effectiveFrom": 1,
             "createdBy": 1,
             "createdOn": 1
            },
            "signatureCounts": {
             "signed": 1,
             "pending": 1,
             "declined": 1,
             "expired": 1,
             "voided": 1
            }
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/waivers/{id}/versions": {
   "get": {
    "operationId": "waivers_listVersions",
    "summary": "listVersions",
    "description": "List all published versions of a waiver, newest first.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/waivers.WaiverVersion"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "waiverId": 1,
           "versionNumber": 1,
           "bodyHtml": "string",
           "fields": [
            {
             "key": "string",
             "type": "short_text",
             "label": "string",
             "helpText": "string",
             "required": false,
             "signerRole": "student",
             "prefillFrom": "student.firstname",
             "validation": {},
             "conditional": {},
             "options": [
              {}
             ],
             "position": {},
             "placement": {}
            }
           ],
           "sourcePdfKey": "string",
           "sourcePdfPages": 1,
           "effectiveFrom": 1,
           "createdBy": 1,
           "createdOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Max items per page (1 to 100)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "waivers_publishVersion",
    "summary": "publishVersion",
    "description": "Publish a new immutable version. The payload shape must match the waiver's sourceType: native expects bodyHtml (and optional fields), uploaded_pdf expects sourcePdfKey + sourcePdfPages. Sets currentVersionId atomically. A shape mismatch is refused 400 VALIDATION_ERROR.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/waivers.WaiverVersion"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "waiverId": 1,
            "versionNumber": 1,
            "bodyHtml": "string",
            "fields": [
             {
              "key": "string",
              "type": "short_text",
              "label": "string",
              "helpText": "string",
              "required": false,
              "signerRole": "student",
              "prefillFrom": "student.firstname",
              "validation": {},
              "conditional": {},
              "options": [
               {}
              ],
              "position": {},
              "placement": {}
             }
            ],
            "sourcePdfKey": "string",
            "sourcePdfPages": 1,
            "effectiveFrom": 1,
            "createdBy": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "waiverId": 1,
            "versionNumber": 1,
            "bodyHtml": "string",
            "fields": [
             {
              "key": "string",
              "type": "short_text",
              "label": "string",
              "helpText": "string",
              "required": false,
              "signerRole": "student",
              "prefillFrom": "student.firstname",
              "validation": {},
              "conditional": {},
              "options": [
               {}
              ],
              "position": {},
              "placement": {}
             }
            ],
            "sourcePdfKey": "string",
            "sourcePdfPages": 1,
            "effectiveFrom": 1,
            "createdBy": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "bodyHtml": {
          "type": "string",
          "description": "Required for native waivers; rejected for uploaded_pdf.",
          "maxLength": 500000
         },
         "fields": {
          "type": "array",
          "description": "Field definitions for this version.",
          "items": {
           "$ref": "#/components/schemas/waivers.Field"
          }
         },
         "sourcePdfKey": {
          "type": "string",
          "description": "Storage key from prior PDF upload. Required for uploaded_pdf; rejected for native."
         },
         "sourcePdfPages": {
          "type": "integer",
          "minimum": 1
         },
         "changeNote": {
          "type": "string",
          "description": "Free-text changelog; not shown to signers.",
          "maxLength": 500
         }
        }
       },
       "example": {
        "bodyHtml": "string",
        "fields": [
         {
          "key": "string",
          "type": "short_text",
          "label": "string",
          "helpText": "string",
          "required": false,
          "signerRole": "student",
          "prefillFrom": "student.firstname",
          "validation": {},
          "conditional": {},
          "options": [
           {
            "value": "string",
            "label": "string"
           }
          ],
          "position": {},
          "placement": {}
         }
        ],
        "sourcePdfKey": "string",
        "sourcePdfPages": 1,
        "changeNote": "string"
       }
      }
     }
    }
   }
  },
  "/v1/waivers/{id}/versions/{versionNumber}": {
   "get": {
    "operationId": "waivers_getVersion",
    "summary": "getVersion",
    "description": "Fetch a specific historical version by its version number.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/waivers.WaiverVersion"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "waiverId": 1,
          "versionNumber": 1,
          "bodyHtml": "string",
          "fields": [
           {
            "key": "string",
            "type": "short_text",
            "label": "string",
            "helpText": "string",
            "required": false,
            "signerRole": "student",
            "prefillFrom": "student.firstname",
            "validation": {},
            "conditional": {},
            "options": [
             {}
            ],
            "position": {},
            "placement": {}
           }
          ],
          "sourcePdfKey": "string",
          "sourcePdfPages": 1,
          "effectiveFrom": 1,
          "createdBy": 1,
          "createdOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "versionNumber",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/waivers/templates": {
   "get": {
    "operationId": "waivers_listTemplates",
    "summary": "listTemplates",
    "description": "List the curated waiver template library. Templates supply a starter body + field set keyed by category/locale. Used as a seed via 'fromTemplate' on create.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/waivers.WaiverTemplate"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "slug": "string",
           "name": "string",
           "category": "waiver",
           "description": "string",
           "locale": "string",
           "bodyHtml": "string",
           "fields": [
            {
             "key": "string",
             "type": "short_text",
             "label": "string",
             "helpText": "string",
             "required": false,
             "signerRole": "student",
             "prefillFrom": "student.firstname",
             "validation": {},
             "conditional": {},
             "options": [
              {}
             ],
             "position": {},
             "placement": {}
            }
           ]
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "category",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "waiver",
        "medical",
        "photo_release",
        "membership",
        "behavior",
        "custom"
       ]
      }
     },
     {
      "name": "locale",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by locale (e.g. 'en', 'en-US'). Optional."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/waivers/templates/{slug}": {
   "get": {
    "operationId": "waivers_getTemplate",
    "summary": "getTemplate",
    "description": "Get full template body + fields by slug.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/waivers.WaiverTemplate"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "slug": "string",
          "name": "string",
          "category": "waiver",
          "description": "string",
          "locale": "string",
          "bodyHtml": "string",
          "fields": [
           {
            "key": "string",
            "type": "short_text",
            "label": "string",
            "helpText": "string",
            "required": false,
            "signerRole": "student",
            "prefillFrom": "student.firstname",
            "validation": {},
            "conditional": {},
            "options": [
             {}
            ],
            "position": {},
            "placement": {}
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "slug",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/waivers/source-pdfs/presign": {
   "post": {
    "operationId": "waivers_presignSourcePdf",
    "summary": "presignSourcePdf",
    "description": "Step 1 of source-PDF upload. Returns a short-lived presigned PUT URL and a server-allocated storage key. Direct-to-S3: the server never streams the PDF. PUT the body to uploadUrl, then call /confirm. Used when authoring an uploaded_pdf waiver.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/waivers.SourcePdfPresignResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "uploadUrl": "string",
          "storageKey": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "filename": {
          "type": "string",
          "minLength": 1,
          "maxLength": 255
         },
         "mimeType": {
          "type": "string",
          "description": "Only application/pdf is accepted.",
          "enum": [
           "application/pdf"
          ]
         },
         "pageCount": {
          "type": "integer",
          "description": "Optional. Page count discovered by the client.",
          "minimum": 1,
          "maximum": 500
         }
        },
        "required": [
         "filename",
         "mimeType"
        ]
       },
       "example": {
        "filename": "string",
        "mimeType": "application/pdf"
       }
      }
     }
    }
   }
  },
  "/v1/waivers/source-pdfs/confirm": {
   "post": {
    "operationId": "waivers_confirmSourcePdf",
    "summary": "confirmSourcePdf",
    "description": "Step 2 of source-PDF upload. Verifies the file exists in storage, is tenant-scoped to this school, and parses as a PDF (unreadable files are rejected up-front; the signing-time stamper would fail on them later). Returns the key, a short-lived download URL for the authoring UI's preview pane, and the derived pageCount.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/waivers.SourcePdfConfirmResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "storageKey": "string",
          "downloadUrl": "string",
          "pageCount": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "storageKey": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
         }
        },
        "required": [
         "storageKey"
        ]
       },
       "example": {
        "storageKey": "string"
       }
      }
     }
    }
   }
  },
  "/v1/waivers/source-pdfs/download": {
   "get": {
    "operationId": "waivers_getSourcePdfDownload",
    "summary": "getSourcePdfDownload",
    "description": "Re-issue a short-lived download URL for an existing source PDF. Used when re-opening the authoring UI for an uploaded_pdf waiver.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/waivers.SourcePdfConfirmResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "storageKey": "string",
          "downloadUrl": "string",
          "pageCount": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "storageKey",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/waivers/{id}/requests": {
   "post": {
    "operationId": "waivers_createSignatureRequest",
    "summary": "createSignatureRequest",
    "description": "Invite a single student to sign. Inserts a pending waiver_signatures row and emits 'waiver.requested' so Send fans out the email. Idempotency-Key supported. 409 for a draft waiver (no published version and no legacy body). There is nothing to sign until POST /:id/versions.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer"
         },
         "signerName": {
          "type": "string",
          "description": "Override the student's full name (e.g. parent of a minor).",
          "maxLength": 200
         },
         "signerEmail": {
          "type": "string",
          "description": "Override the student's email on file.",
          "maxLength": 255,
          "format": "email"
         },
         "signerRole": {
          "type": "string",
          "enum": [
           "student",
           "guardian",
           "witness",
           "countersigner"
          ]
         },
         "signerRelationship": {
          "type": "string",
          "description": "How the signer relates to the student (e.g. 'parent', 'guardian').",
          "maxLength": 100
         },
         "expiresIn": {
          "type": "integer",
          "description": "Days from now until the request expires. Falls back to the waiver's configured expiry if omitted.",
          "minimum": 1,
          "maximum": 3650
         },
         "guardian": {
          "type": "object",
          "description": "Optional guardian co-recipient. Auto-detected for minors when omitted (see autoGuardian).",
          "properties": {
           "signerName": {
            "type": "string",
            "maxLength": 200
           },
           "signerEmail": {
            "type": "string",
            "maxLength": 255,
            "format": "email"
           },
           "signerRelationship": {
            "type": "string",
            "maxLength": 100
           }
          },
          "required": [
           "signerEmail"
          ]
         },
         "witness": {
          "type": "object",
          "description": "Optional witness co-recipient. Witnesses are always explicit (never auto-detected).",
          "properties": {
           "signerName": {
            "type": "string",
            "maxLength": 200
           },
           "signerEmail": {
            "type": "string",
            "maxLength": 255,
            "format": "email"
           },
           "signerRelationship": {
            "type": "string",
            "maxLength": 100
           }
          },
          "required": [
           "signerEmail"
          ]
         },
         "autoGuardian": {
          "type": "boolean",
          "description": "When true (default), the server infers a guardian co-recipient for minor students by reading the legacy emergency_info free-text column. Pass false to skip auto-detection.",
          "default": true
         }
        },
        "required": [
         "studentId"
        ]
       },
       "example": {
        "studentId": 1
       }
      }
     }
    }
   }
  },
  "/v1/waivers/{id}/requests:bulk": {
   "post": {
    "operationId": "waivers_bulkSignatureRequests",
    "summary": "bulkSignatureRequests",
    "description": "Bulk-send a waiver to a resolved audience. Audience selectors AND together. Preview returns the resolved recipient list with skip flags (no email, already signed, already pending). On execution, emits 'waiver.requested' once per inserted row. 409 for a draft waiver (no published version and no legacy body), in preview mode too. A minor gets the same guardian row as the single request: invited at once in parallel mode, in turn in sequential mode. The preview reports wouldInviteGuardians and minorsWithoutGuardian; the result reports guardiansInvited.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "audience": {
          "type": "object",
          "description": "AND of any provided selectors. At least one is required.",
          "properties": {
           "allActive": {
            "type": "boolean",
            "description": "Members + trials, excluding leads/deleted/deactivated."
           },
           "tagIds": {
            "type": "array",
            "items": {
             "type": "integer"
            }
           },
           "styleIds": {
            "type": "array",
            "items": {
             "type": "integer"
            }
           },
           "clubIds": {
            "type": "array",
            "items": {
             "type": "integer"
            }
           },
           "studentIds": {
            "type": "array",
            "items": {
             "type": "integer"
            }
           }
          }
         },
         "signerRole": {
          "type": "string",
          "enum": [
           "student",
           "guardian",
           "witness",
           "countersigner"
          ]
         },
         "expiresIn": {
          "type": "integer",
          "minimum": 1,
          "maximum": 3650
         },
         "skipAlreadySigned": {
          "type": "boolean",
          "default": true
         },
         "skipAlreadyPending": {
          "type": "boolean",
          "default": true
         }
        }
       },
       "example": {
        "audience": {
         "allActive": false,
         "tagIds": [
          1
         ],
         "styleIds": [
          1
         ],
         "clubIds": [
          1
         ],
         "studentIds": [
          1
         ]
        },
        "signerRole": "student",
        "expiresIn": 1,
        "skipAlreadySigned": true,
        "skipAlreadyPending": true
       }
      }
     }
    }
   }
  },
  "/v1/waivers/{id}/requests/{signatureId}/resend": {
   "post": {
    "operationId": "waivers_resendSignatureRequest",
    "summary": "resendSignatureRequest",
    "description": "Resend a still-pending request. Bumps requested_on so the reminder clock resets. Emits 'waiver.reminder' (distinct from 'waiver.requested' so Send can wire reminder-specific copy). 409 if the signature is no longer pending.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "signatureId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/waivers/{id}/requests/{signatureId}/cancel": {
   "post": {
    "operationId": "waivers_cancelSignatureRequest",
    "summary": "cancelSignatureRequest",
    "description": "Cancel a still-pending request. Soft-voids the signature row; re-requesting later creates a fresh row to preserve the audit chain. Emits 'waiver.requested.cancelled'.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "signatureId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/waivers/{id}/signatures": {
   "get": {
    "operationId": "waivers_listSignatures",
    "summary": "listSignatures",
    "description": "List signatures (any status) for this waiver. Cursor-paginated descending by id; meta carries `total` (filter-wide, cursor-independent) plus `nextCursor`. Status filtering is legacy-aware: legacy rows without an explicit status column are derived from signedOn/deletedOn/expiresOn timestamps.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/waivers.Signature"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/CursorMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "waiverId": 1,
           "waiverVersionId": 1,
           "studentId": 1,
           "signerRole": "student",
           "signerName": "string",
           "signerEmail": "string",
           "signerRelationship": "string",
           "status": "pending",
           "signatureImageKey": "string",
           "fieldResponses": {},
           "requestedOn": 1,
           "viewedOn": 1,
           "signedOn": 1,
           "declinedOn": 1,
           "expiresOn": 1,
           "declineReason": "string",
           "voidReason": "string",
           "voidedBy": 1,
           "ipAddress": "string",
           "userAgent": "string",
           "geoCountry": "string",
           "requestTokenJti": "string",
           "auditHash": "string",
           "parentSignatureId": 1,
           "createdOn": 1,
           "deletedOn": 1
          }
         ],
         "meta": {
          "count": 1,
          "total": 1,
          "nextCursor": null
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "q",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Free-text search over signer name, signer email, and the linked student's name (substring, case-insensitive)."
     },
     {
      "name": "responseFilters",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "JSON-encoded array (max 5) of response-field predicates, each {fieldKey, valueEquals?, valueContains?, valueDateGte?, valueDateLte?, valueNumberGte?, valueNumberLte?}. ANDed; they match signed responses only."
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "pending",
        "viewed",
        "signed",
        "declined",
        "expired",
        "cancelled",
        "voided"
       ]
      },
      "description": "Filter by signature status (legacy-aware)."
     },
     {
      "name": "signerRole",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "student",
        "guardian",
        "witness",
        "countersigner"
       ]
      },
      "description": "Filter by signer role."
     },
     {
      "name": "signedFrom",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix seconds lower bound on signedOn (inclusive)."
     },
     {
      "name": "signedTo",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix seconds upper bound on signedOn (inclusive)."
     },
     {
      "name": "studentId",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by student id, substring match on the digits (1-10 digits). '332' matches 332, 3320, 1332 and 783321."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Pagination cursor (id of the last item from the previous page)."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Max items per page (1 to 100)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/waivers/{id}/signatures/{signatureId}": {
   "get": {
    "operationId": "waivers_getSignature",
    "summary": "getSignature",
    "description": "Get a single signature with full audit metadata (ip, user agent, geo, field responses, request-token jti, audit hash).",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/waivers.Signature"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "waiverId": 1,
          "waiverVersionId": 1,
          "studentId": 1,
          "signerRole": "student",
          "signerName": "string",
          "signerEmail": "string",
          "signerRelationship": "string",
          "status": "pending",
          "signatureImageKey": "string",
          "fieldResponses": {},
          "requestedOn": 1,
          "viewedOn": 1,
          "signedOn": 1,
          "declinedOn": 1,
          "expiresOn": 1,
          "declineReason": "string",
          "voidReason": "string",
          "voidedBy": 1,
          "ipAddress": "string",
          "userAgent": "string",
          "geoCountry": "string",
          "requestTokenJti": "string",
          "auditHash": "string",
          "parentSignatureId": 1,
          "createdOn": 1,
          "deletedOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "signatureId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/waivers/{id}/prior-version-signers": {
   "get": {
    "operationId": "waivers_listPriorVersionSigners",
    "summary": "listPriorVersionSigners",
    "description": "Students whose LATEST signed signature on this waiver is for a recorded (and therefore, after a publish, prior) version. Powers the post-publish follow-up: these students can be offered a re-request via requests:bulk with an explicit studentIds audience. Students whose latest signature is legacy (no recorded version) count as current and are excluded. One row per student: studentId, firstName, lastName, signedDate (YYYY-MM-DD), versionNumber, plus sendability flags sourced from the requests:bulk lane's own audience resolver so the offer can never drift from the send outcome: hasOpenRequest (unsigned request in flight; it collects the new version by itself, so a fresh send would be skipped), noEmail (no usable email on the profile), reachable (false = outside the lane's base population, e.g. deactivated).",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {}
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/waivers/{id}/signatures:void-bulk": {
   "post": {
    "operationId": "waivers_voidSignaturesBulk",
    "summary": "voidSignaturesBulk",
    "description": "Void multiple signatures in one call. Either pass an explicit signatureIds list, or a filter (status / signedFrom / signedTo). Already-voided rows are skipped. Emits 'waiver.signature.voided' per row voided. Supports ?preview=true to count without mutating. Preview returns the SAME `voided` count the execute will perform, so it can be shown to the user as 'this many will be voided'.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/waivers.VoidBulkResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "resolved": 1,
            "voided": 1,
            "skipped": 1,
            "signatures": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "resolved": 1,
            "voided": 1,
            "skipped": 1,
            "signatures": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "signatureIds": {
          "type": "array",
          "description": "Explicit ids to void. Mutually exclusive in intent with status filter; at least one selector is required.",
          "items": {
           "type": "integer"
          }
         },
         "status": {
          "type": "string",
          "description": "Filter by current status.",
          "enum": [
           "pending",
           "viewed",
           "signed",
           "declined",
           "expired",
           "cancelled",
           "voided"
          ]
         },
         "signedFrom": {
          "type": "integer"
         },
         "signedTo": {
          "type": "integer"
         },
         "reason": {
          "type": "string",
          "description": "Free-text reason; persisted to decline_reason and surfaced on the voided event.",
          "maxLength": 500
         }
        }
       },
       "example": {
        "signatureIds": [
         1
        ],
        "status": "pending",
        "signedFrom": 1,
        "signedTo": 1,
        "reason": "string"
       }
      }
     }
    }
   }
  },
  "/v1/waivers/{id}/signatures/{signatureId}/countersign": {
   "post": {
    "operationId": "waivers_countersignSignature",
    "summary": "countersignSignature",
    "description": "Countersign a pending signature on behalf of the school. The signature row must be in status='pending' with signerRole='countersigner' (created automatically once all signer-side rows are signed). Emits 'waiver.signed'. Returns 409 when one or more signer-side rows are still pending. Supports ?preview=true: the same refusals, nothing stored.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "signatureId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "signerName": {
          "type": "string",
          "description": "Full name of the admin doing the countersign.",
          "maxLength": 200
         },
         "signerRelationship": {
          "type": "string",
          "description": "Role of the admin (e.g. 'principal', 'head instructor').",
          "maxLength": 100
         },
         "signature": {
          "type": "string",
          "description": "Drawn signature PNG data URL, or short typed-signature string."
         },
         "signatureType": {
          "type": "string",
          "enum": [
           "typed",
           "drawn"
          ]
         }
        },
        "required": [
         "signerName"
        ]
       },
       "example": {
        "signerName": "string"
       }
      }
     }
    }
   }
  },
  "/v1/waivers/{id}/signatures/{signatureId}/request-countersign": {
   "post": {
    "operationId": "waivers_requestCountersign",
    "summary": "requestCountersign",
    "description": "Add a countersignature slot to a fully-signed chain: mints the pending signerRole='countersigner' row that the countersign endpoint operates on. For chains sent without countersignerRequired (or predating it). Returns the existing pending countersigner row instead of duplicating when one is already open. 409 when the chain has unsigned signer-side rows or the target signature isn't signed.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "signatureId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/waivers/{id}/signatures/{signatureId}/pdf": {
   "get": {
    "operationId": "waivers_getSignaturePdf",
    "summary": "getSignaturePdf",
    "description": "Stream the signed waiver PDF (waiver body + certificate of completion appendix). Rendered on demand from the signature row every time; nothing is cached, so a renderer fix reaches every download at once. Returns 409 when the signature isn't yet in status='signed'. Response is a binary stream: Content-Type application/pdf, Content-Disposition: attachment.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "signatureId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/waivers/{id}/export-signed": {
   "post": {
    "operationId": "waivers_exportSignedCopies",
    "summary": "exportSignedCopies",
    "description": "Every signed copy of the waiver as one zip, built in the background as an operation: the answer is 202 with { operationId, label }, followed through GET /v1/operations/:id, whose file.downloadUrl is a short-lived signed link to the zip; the zip is kept for seven days. One PDF per student who signed (the newest signed copy, archived students included), in a folder named after the waiver as \"First Last.pdf\"; a copy that could not be rendered is named in a short text file. Refused (409) when nobody has signed. Same permission as the single signed PDF.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "id",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Waiver id"
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/waivers/responses/search": {
   "get": {
    "operationId": "waivers_searchResponses",
    "summary": "searchResponses",
    "description": "Search field responses across all signed signatures in the school. fieldKey is required; value predicates AND together. Cursor-paginated by index id, newest first.",
    "tags": [
     "waivers"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/waivers.ResponseSearchHit"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/CursorMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "signatureId": 1,
           "waiverId": 1,
           "waiverName": "string",
           "studentId": 1,
           "studentName": "string",
           "signerName": "string",
           "signedOn": 1,
           "fieldKey": "string",
           "fieldLabel": "string",
           "fieldType": "short_text",
           "valueText": "string",
           "valueDate": "2026-11-05",
           "valueNumber": "string"
          }
         ],
         "meta": {
          "count": 1,
          "total": 1,
          "nextCursor": null
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "fieldKey",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "Field key (immutable id) to search; snake_case, ^[a-z][a-z0-9_]{0,49}$. Anchored to one key per query. Pick from the waiver version's fields."
     },
     {
      "name": "waiverId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Narrow the search to one waiver. Optional."
     },
     {
      "name": "valueEquals",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Case-insensitive equality on the indexed text value. Applies to short_text/long_text/email/phone/radio/dropdown/checkbox/checkbox_group/date."
     },
     {
      "name": "valueContains",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Case-insensitive substring match on the indexed text value. Wildcards (% _) in the query are auto-escaped."
     },
     {
      "name": "valueDateGte",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Inclusive lower bound on indexed date value, YYYY-MM-DD. Date fields only. Legacy midnight-UTC unix-second values are accepted and normalised."
     },
     {
      "name": "valueDateLte",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Inclusive upper bound on indexed date value, YYYY-MM-DD. Date fields only. Legacy midnight-UTC unix-second values are accepted and normalised."
     },
     {
      "name": "valueNumberGte",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Inclusive lower bound on indexed numeric value. Number fields only."
     },
     {
      "name": "valueNumberLte",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Inclusive upper bound on indexed numeric value. Number fields only."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Pagination cursor (id of the last hit from the previous page)."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Max hits per page (1 to 100)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/certificates": {
   "get": {
    "operationId": "certificates_list",
    "summary": "list",
    "description": "List all certificate templates for the school",
    "tags": [
     "certificates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/certificates.CertTemplate"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "name": "string",
           "baseTemplateId": "string",
           "primaryColor": "0123456789abcdef0123456789abcdef",
           "secondaryColor": "0123456789abcdef0123456789abcdef",
           "citationText": "string",
           "instructor1UserId": 1,
           "instructor2UserId": 1,
           "showSecondSig": false,
           "segmentFilterId": 1,
           "isDefault": false
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "certificates_create",
    "summary": "create",
    "description": "Create a certificate template",
    "tags": [
     "certificates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/certificates.CertTemplate"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "baseTemplateId": "string",
            "primaryColor": "0123456789abcdef0123456789abcdef",
            "secondaryColor": "0123456789abcdef0123456789abcdef",
            "citationText": "string",
            "instructor1UserId": 1,
            "instructor2UserId": 1,
            "showSecondSig": false,
            "segmentFilterId": 1,
            "isDefault": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "baseTemplateId": "string",
            "primaryColor": "0123456789abcdef0123456789abcdef",
            "secondaryColor": "0123456789abcdef0123456789abcdef",
            "citationText": "string",
            "instructor1UserId": 1,
            "instructor2UserId": 1,
            "showSecondSig": false,
            "segmentFilterId": 1,
            "isDefault": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string"
         },
         "baseTemplateId": {
          "type": "string",
          "description": "One of t01..t08 incl t03 ja/zh/ko"
         },
         "primaryColor": {
          "type": "string",
          "format": "hex"
         },
         "secondaryColor": {
          "type": "string",
          "format": "hex"
         },
         "citationText": {
          "type": "string"
         },
         "instructor1UserId": {
          "type": "number"
         },
         "instructor2UserId": {
          "type": "number"
         },
         "showSecondSig": {
          "type": "boolean"
         },
         "segmentFilterId": {
          "type": "number",
          "description": "Optional segment ID gating which students this template applies to"
         },
         "isDefault": {
          "type": "boolean"
         }
        },
        "required": [
         "name",
         "baseTemplateId",
         "primaryColor",
         "secondaryColor",
         "citationText"
        ]
       },
       "example": {
        "name": "string",
        "baseTemplateId": "string",
        "primaryColor": "0123456789abcdef0123456789abcdef",
        "secondaryColor": "0123456789abcdef0123456789abcdef",
        "citationText": "string"
       }
      }
     }
    }
   }
  },
  "/v1/certificates/{id}": {
   "get": {
    "operationId": "certificates_get",
    "summary": "get",
    "description": "Get a single certificate template",
    "tags": [
     "certificates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/certificates.CertTemplate"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "name": "string",
          "baseTemplateId": "string",
          "primaryColor": "0123456789abcdef0123456789abcdef",
          "secondaryColor": "0123456789abcdef0123456789abcdef",
          "citationText": "string",
          "instructor1UserId": 1,
          "instructor2UserId": 1,
          "showSecondSig": false,
          "segmentFilterId": 1,
          "isDefault": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "certificates_update",
    "summary": "update",
    "description": "Update a certificate template. Every create field, all optional.",
    "tags": [
     "certificates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/certificates.CertTemplate"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "baseTemplateId": "string",
            "primaryColor": "0123456789abcdef0123456789abcdef",
            "secondaryColor": "0123456789abcdef0123456789abcdef",
            "citationText": "string",
            "instructor1UserId": 1,
            "instructor2UserId": 1,
            "showSecondSig": false,
            "segmentFilterId": 1,
            "isDefault": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "baseTemplateId": "string",
            "primaryColor": "0123456789abcdef0123456789abcdef",
            "secondaryColor": "0123456789abcdef0123456789abcdef",
            "citationText": "string",
            "instructor1UserId": 1,
            "instructor2UserId": 1,
            "showSecondSig": false,
            "segmentFilterId": 1,
            "isDefault": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string"
         },
         "baseTemplateId": {
          "type": "string",
          "description": "One of t01..t08 incl t03 ja/zh/ko"
         },
         "primaryColor": {
          "type": "string",
          "format": "hex"
         },
         "secondaryColor": {
          "type": "string",
          "format": "hex"
         },
         "citationText": {
          "type": "string"
         },
         "instructor1UserId": {
          "type": "number"
         },
         "instructor2UserId": {
          "type": "number"
         },
         "showSecondSig": {
          "type": "boolean"
         },
         "segmentFilterId": {
          "type": "number",
          "description": "Optional segment ID gating which students this template applies to"
         },
         "isDefault": {
          "type": "boolean"
         }
        }
       },
       "example": {
        "name": "string",
        "baseTemplateId": "string",
        "primaryColor": "0123456789abcdef0123456789abcdef",
        "secondaryColor": "0123456789abcdef0123456789abcdef",
        "citationText": "string",
        "instructor1UserId": 1,
        "instructor2UserId": 1,
        "showSecondSig": false,
        "segmentFilterId": 1,
        "isDefault": false
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "certificates_delete",
    "summary": "delete",
    "description": "Soft-delete a certificate template (requires ?confirm=true)",
    "tags": [
     "certificates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/certificates/render": {
   "post": {
    "operationId": "certificates_render",
    "summary": "render",
    "description": "Atomically render a certificate. Cache key = (schoolId, promotionId, certTemplateId). Returns immediately with status='cached' on hit; otherwise enqueues render and returns status='success' (pending until worker uploads).",
    "tags": [
     "certificates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/certificates.CertRenderResponse"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "success",
          "storageKey": "string",
          "downloadUrl": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "promotionId": {
          "type": "number"
         },
         "certTemplateId": {
          "type": "number"
         }
        },
        "required": [
         "promotionId",
         "certTemplateId"
        ]
       },
       "example": {
        "promotionId": 1,
        "certTemplateId": 1
       }
      }
     }
    }
   }
  },
  "/v1/certificates/render/batch": {
   "post": {
    "operationId": "certificates_renderBatch",
    "summary": "renderBatch",
    "description": "Start up to 200 renders with one template as one operation. Like `render`, each certificate already rendered is reused; the answer is { operationId, label, queued, estimatedMinutes } to follow under GET /v1/operations/:id, where every finished row carries a short-lived PDF link; queued is how many renders, every school's included, sit ahead of or among these, and estimatedMinutes the wait that implies. Each row's own state is still at renderStatus.",
    "tags": [
     "certificates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "certTemplateId": {
          "type": "number"
         },
         "entries": {
          "type": "array",
          "description": "1-200 of { promotionId, studentName }; the name is the row's label in the operation.",
          "items": {}
         }
        },
        "required": [
         "certTemplateId",
         "entries"
        ]
       },
       "example": {
        "certTemplateId": 1,
        "entries": []
       }
      }
     }
    }
   }
  },
  "/v1/certificates/render/status": {
   "get": {
    "operationId": "certificates_renderStatus",
    "summary": "renderStatus",
    "description": "Poll a render's state for (promotionId, certTemplateId): 'cached' (download ready), 'pending' (rendering), or 'error'. Pair with the render op's atomic+cached semantics.",
    "tags": [
     "certificates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "promotionId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "student_ranks id of the promotion."
     },
     {
      "name": "certTemplateId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Certificate template id."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/certificates/base-templates": {
   "get": {
    "operationId": "certificates_base_templates",
    "summary": "base_templates",
    "description": "List the 10 base template designs (t01..t08 incl t03 ja/zh/ko)",
    "tags": [
     "certificates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/certificates/belt-presets": {
   "get": {
    "operationId": "certificates_belt_presets",
    "summary": "belt_presets",
    "description": "List the 9 belt colour presets (white..black)",
    "tags": [
     "certificates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/study": {
   "get": {
    "operationId": "study_list",
    "summary": "list",
    "description": "List curriculum grouped by rank for a single style.",
    "tags": [
     "study"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Style to list curriculum for."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "study_create",
    "summary": "create",
    "description": "Create a curriculum item. Send as multipart/form-data when uploading a file. Supports ?preview=true for dry-run validation.",
    "tags": [
     "study"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "properties": {
         "title": {
          "type": "string",
          "description": "Item title (max 100)."
         },
         "rankId": {
          "type": "integer",
          "description": "Rank the item belongs to."
         },
         "link": {
          "type": "string",
          "description": "External URL (mutually exclusive with file)."
         },
         "file": {
          "type": "string",
          "description": "PDF or image (≤4MB).",
          "format": "binary"
         }
        },
        "required": [
         "title",
         "rankId"
        ]
       },
       "example": {
        "title": "string",
        "rankId": 1
       }
      }
     }
    }
   }
  },
  "/v1/study/{id}": {
   "get": {
    "operationId": "study_get",
    "summary": "get",
    "description": "Get a single curriculum item with download URL if a file is attached.",
    "tags": [
     "study"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "study_update",
    "summary": "update",
    "description": "Update a curriculum item. Multipart accepted for re-uploading the file. Supports ?preview=true for dry-run.",
    "tags": [
     "study"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "properties": {
         "title": {
          "type": "string"
         },
         "rankId": {
          "type": "integer"
         },
         "link": {
          "type": "string"
         },
         "file": {
          "type": "string",
          "format": "binary"
         },
         "removeFile": {
          "type": "boolean",
          "description": "Unattach the current file without supplying a new one."
         }
        }
       },
       "example": {
        "title": "string",
        "rankId": 1,
        "link": "string",
        "file": "(file contents)",
        "removeFile": false
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "study_delete",
    "summary": "delete",
    "description": "Soft-delete a curriculum item and (best-effort) remove its bucket file. Supports ?preview=true; requires ?confirm=true to execute.",
    "tags": [
     "study"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/study/reorder": {
   "patch": {
    "operationId": "study_reorder",
    "summary": "reorder",
    "description": "Persist a new display order for a batch of items within one rank. Supports ?preview=true to inspect ownership before persisting.",
    "tags": [
     "study"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "items": {
          "type": "array",
          "description": "Array of { id, order } pairs.",
          "items": {}
         }
        },
        "required": [
         "items"
        ]
       },
       "example": {
        "items": []
       }
      }
     }
    }
   }
  },
  "/v1/study/{id}/download": {
   "get": {
    "operationId": "study_download",
    "summary": "download",
    "description": "Mint a short-lived signed URL for the item's stored file.",
    "tags": [
     "study"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/events": {
   "get": {
    "operationId": "events_list",
    "summary": "list",
    "description": "List events with pagination and filters. from and to (YYYY-MM-DD) keep events that run between them: a single event by its date, a recurring class on any of its weekdays.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.EventSummary"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "type": "single",
           "venueId": 1,
           "venueOverride": "string",
           "venueName": "string",
           "startTime": "18:00",
           "endTime": "18:00",
           "startDate": "2026-11-05",
           "endDate": "2026-11-05",
           "isGrading": false,
           "days": 1,
           "capacity": 1,
           "price": 1,
           "visibility": 1,
           "allowDropins": false
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Only events at this venue"
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Only events open to this style"
     },
     {
      "name": "type",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "single",
        "recurring"
       ]
      },
      "description": "One-off events or recurring classes"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Range start (YYYY-MM-DD)"
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Range end (YYYY-MM-DD)"
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Name contains"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 20
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "events_create",
    "summary": "create",
    "description": "Create a new event. Use ?preview=true for dry run.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.EventDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "type": "single",
            "days": 1,
            "startTime": "18:00",
            "endTime": "18:00",
            "startDate": "2026-11-05",
            "endDate": "2026-11-05",
            "venueId": 1,
            "venueOverride": "string",
            "venueAddress": "string",
            "venueSuburb": "string",
            "venueState": "string",
            "venuePostcode": "string",
            "venueCountry": "string",
            "venueLat": 1,
            "venueLng": 1,
            "venueName": "string",
            "meetingUrl": "string",
            "capacity": 1,
            "minAge": 1,
            "maxAge": 1,
            "openToAllStudents": false,
            "price": 1,
            "allowDropins": false,
            "selfEnrollable": false,
            "visibility": 1,
            "noShowFee": 1,
            "noShowConsumesPass": false,
            "notifications": false,
            "waiverId": 1,
            "createdOn": 1,
            "enrollmentCount": 1,
            "bookingCount": 1,
            "isGrading": false,
            "trialEligible": false,
            "allStyles": false,
            "styles": [],
            "needsStyle": false,
            "ranks": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "type": "single",
            "days": 1,
            "startTime": "18:00",
            "endTime": "18:00",
            "startDate": "2026-11-05",
            "endDate": "2026-11-05",
            "venueId": 1,
            "venueOverride": "string",
            "venueAddress": "string",
            "venueSuburb": "string",
            "venueState": "string",
            "venuePostcode": "string",
            "venueCountry": "string",
            "venueLat": 1,
            "venueLng": 1,
            "venueName": "string",
            "meetingUrl": "string",
            "capacity": 1,
            "minAge": 1,
            "maxAge": 1,
            "openToAllStudents": false,
            "price": 1,
            "allowDropins": false,
            "selfEnrollable": false,
            "visibility": 1,
            "noShowFee": 1,
            "noShowConsumesPass": false,
            "notifications": false,
            "waiverId": 1,
            "createdOn": 1,
            "enrollmentCount": 1,
            "bookingCount": 1,
            "isGrading": false,
            "trialEligible": false,
            "allStyles": false,
            "styles": [],
            "needsStyle": false,
            "ranks": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Event name",
          "maxLength": 250
         },
         "description": {
          "type": "string",
          "description": "Event description",
          "maxLength": 1500
         },
         "type": {
          "type": "string",
          "enum": [
           "single",
           "recurring"
          ],
          "default": "single"
         },
         "days": {
          "type": "integer",
          "description": "Bitmask of recurring weekdays, summed. Day values: Sun=1, Mon=2, Tue=4, Wed=8, Thu=16, Fri=32, Sat=64 (the same order the legacy system uses). Example: Tue+Thu = 4+16 = 20; Mon+Wed+Fri = 42. Use 0 for single (non-recurring) events.",
          "minimum": 0,
          "maximum": 127
         },
         "startTime": {
          "type": "string",
          "description": "Start time as HH:MM 24-hour (e.g., '18:00' for 6:00 PM)",
          "format": "time"
         },
         "endTime": {
          "type": "string",
          "description": "End time as HH:MM 24-hour (e.g., '19:00')",
          "format": "time"
         },
         "startDate": {
          "type": "string",
          "description": "Start date as YYYY-MM-DD (e.g., '2025-06-10'). For recurring events, the first date on/after which occurrences begin.",
          "format": "date"
         },
         "endDate": {
          "type": "string",
          "description": "End date for recurring events as YYYY-MM-DD (omit for open-ended)",
          "format": "date"
         },
         "venueId": {
          "type": "integer",
          "description": "Location/venue ID"
         },
         "venueOverride": {
          "type": "string",
          "description": "Off-site venue label, for a class at a place that is not a school venue; a venueId clears it, and an off-site label clears the venueId. One-off or recurring.",
          "maxLength": 255
         },
         "venueAddress": {
          "type": "string",
          "description": "off-site street address (with venueOverride)",
          "maxLength": 255
         },
         "venueSuburb": {
          "type": "string",
          "description": "off-site suburb",
          "maxLength": 100
         },
         "venueState": {
          "type": "string",
          "description": "off-site state",
          "maxLength": 100
         },
         "venuePostcode": {
          "type": "string",
          "description": "off-site postcode",
          "maxLength": 20
         },
         "venueCountry": {
          "type": "string",
          "description": "off-site country",
          "maxLength": 100
         },
         "venueLat": {
          "type": "number",
          "description": "off-site latitude; looked up from the address when omitted"
         },
         "venueLng": {
          "type": "number",
          "description": "off-site longitude; looked up from the address when omitted"
         },
         "meetingUrl": {
          "type": "string",
          "description": "Video meeting link for virtual classes",
          "format": "url"
         },
         "capacity": {
          "type": "integer",
          "description": "Maximum capacity"
         },
         "minAge": {
          "type": "integer",
          "description": "Youngest age that may book, on the class's day, inclusive. Null = no minimum. A student with no birthday on file may book."
         },
         "maxAge": {
          "type": "integer",
          "description": "Oldest age that may book, on the class's day, inclusive. Null = no maximum."
         },
         "openToAllStudents": {
          "type": "boolean",
          "description": "Every Active Student and Trial is on the event's check-in roster, booked or not. Still filtered by the event's styles. With no venue, the event is offered on every kiosk of the school."
         },
         "allowDropins": {
          "type": "boolean",
          "description": "Allow drop-in bookings (false = roster only). Always true while the event is published to the website widget (visibility bit 1): publishing decides it.",
          "default": true
         },
         "selfEnrollable": {
          "type": "boolean",
          "description": "Stored, and read by nothing: students do not enrol themselves. Staff put a student on the class roster.",
          "default": false
         },
         "price": {
          "type": "integer",
          "description": "Price in cents (for paid events)"
         },
         "noShowFee": {
          "type": "integer",
          "description": "No-show fee in cents",
          "default": 0
         },
         "noShowConsumesPass": {
          "type": "boolean",
          "description": "No-show still consumes a pass",
          "default": false
         },
         "visibility": {
          "type": "integer",
          "description": "Bitmask: 1=widget, 2=app, 4=invite_only",
          "minimum": 0,
          "maximum": 7,
          "default": 0
         },
         "notifications": {
          "type": "boolean",
          "description": "Enable notifications",
          "default": false
         },
         "waiverId": {
          "type": "integer",
          "description": "Required waiver ID (null on update clears it)"
         },
         "styleIds": {
          "type": "array",
          "description": "The styles this class is for, from list_styles_and_ranks. Every class names at least one, or allStyles; a school with a single style needs no answer. Members see and book a class only in a style they belong to. On an update the list replaces the class's styles, but a style stays while any of its ranks is still in rankIds, so send both to drop one.",
          "items": {
           "type": "integer"
          }
         },
         "allStyles": {
          "type": "boolean",
          "description": "A whole-school class (a seminar, a camp). It follows the school's styles, so one added later is included. It stays on until an update sends allStyles: false."
         },
         "rankIds": {
          "type": "array",
          "description": "Optional: limit a style to these ranks. A rank names its style.",
          "items": {
           "type": "integer"
          }
         },
         "trialEligible": {
          "type": "boolean",
          "description": "Leads and students on trial are offered this class, and only classes like it",
          "default": false
         }
        },
        "required": [
         "name",
         "startTime",
         "endTime",
         "startDate"
        ]
       },
       "example": {
        "name": "string",
        "startTime": "18:00",
        "endTime": "18:00",
        "startDate": "2026-11-05"
       }
      }
     }
    }
   }
  },
  "/v1/events/{id}": {
   "get": {
    "operationId": "events_get",
    "summary": "get",
    "description": "Get event details by ID",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/events.EventDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "description": "string",
          "type": "single",
          "days": 1,
          "startTime": "18:00",
          "endTime": "18:00",
          "startDate": "2026-11-05",
          "endDate": "2026-11-05",
          "venueId": 1,
          "venueOverride": "string",
          "venueAddress": "string",
          "venueSuburb": "string",
          "venueState": "string",
          "venuePostcode": "string",
          "venueCountry": "string",
          "venueLat": 1,
          "venueLng": 1,
          "venueName": "string",
          "meetingUrl": "string",
          "capacity": 1,
          "minAge": 1,
          "maxAge": 1,
          "openToAllStudents": false,
          "price": 1,
          "allowDropins": false,
          "selfEnrollable": false,
          "visibility": 1,
          "noShowFee": 1,
          "noShowConsumesPass": false,
          "notifications": false,
          "waiverId": 1,
          "createdOn": 1,
          "enrollmentCount": 1,
          "bookingCount": 1,
          "isGrading": false,
          "trialEligible": false,
          "allStyles": false,
          "styles": [],
          "needsStyle": false,
          "ranks": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "events_update",
    "summary": "update",
    "description": "Update an event. Use ?preview=true for dry run. Every create field is optional here; updateScope says which occurrences of a recurring class take the change.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.EventDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "type": "single",
            "days": 1,
            "startTime": "18:00",
            "endTime": "18:00",
            "startDate": "2026-11-05",
            "endDate": "2026-11-05",
            "venueId": 1,
            "venueOverride": "string",
            "venueAddress": "string",
            "venueSuburb": "string",
            "venueState": "string",
            "venuePostcode": "string",
            "venueCountry": "string",
            "venueLat": 1,
            "venueLng": 1,
            "venueName": "string",
            "meetingUrl": "string",
            "capacity": 1,
            "minAge": 1,
            "maxAge": 1,
            "openToAllStudents": false,
            "price": 1,
            "allowDropins": false,
            "selfEnrollable": false,
            "visibility": 1,
            "noShowFee": 1,
            "noShowConsumesPass": false,
            "notifications": false,
            "waiverId": 1,
            "createdOn": 1,
            "enrollmentCount": 1,
            "bookingCount": 1,
            "isGrading": false,
            "trialEligible": false,
            "allStyles": false,
            "styles": [],
            "needsStyle": false,
            "ranks": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "type": "single",
            "days": 1,
            "startTime": "18:00",
            "endTime": "18:00",
            "startDate": "2026-11-05",
            "endDate": "2026-11-05",
            "venueId": 1,
            "venueOverride": "string",
            "venueAddress": "string",
            "venueSuburb": "string",
            "venueState": "string",
            "venuePostcode": "string",
            "venueCountry": "string",
            "venueLat": 1,
            "venueLng": 1,
            "venueName": "string",
            "meetingUrl": "string",
            "capacity": 1,
            "minAge": 1,
            "maxAge": 1,
            "openToAllStudents": false,
            "price": 1,
            "allowDropins": false,
            "selfEnrollable": false,
            "visibility": 1,
            "noShowFee": 1,
            "noShowConsumesPass": false,
            "notifications": false,
            "waiverId": 1,
            "createdOn": 1,
            "enrollmentCount": 1,
            "bookingCount": 1,
            "isGrading": false,
            "trialEligible": false,
            "allStyles": false,
            "styles": [],
            "needsStyle": false,
            "ranks": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Event name",
          "maxLength": 250
         },
         "description": {
          "type": "string",
          "description": "Event description",
          "maxLength": 1500
         },
         "type": {
          "type": "string",
          "enum": [
           "single",
           "recurring"
          ],
          "default": "single"
         },
         "days": {
          "type": "integer",
          "description": "Bitmask of recurring weekdays, summed. Day values: Sun=1, Mon=2, Tue=4, Wed=8, Thu=16, Fri=32, Sat=64 (the same order the legacy system uses). Example: Tue+Thu = 4+16 = 20; Mon+Wed+Fri = 42. Use 0 for single (non-recurring) events.",
          "minimum": 0,
          "maximum": 127
         },
         "startTime": {
          "type": "string",
          "description": "Start time as HH:MM 24-hour (e.g., '18:00' for 6:00 PM)",
          "format": "time"
         },
         "endTime": {
          "type": "string",
          "description": "End time as HH:MM 24-hour (e.g., '19:00')",
          "format": "time"
         },
         "startDate": {
          "type": "string",
          "description": "Start date as YYYY-MM-DD (e.g., '2025-06-10'). For recurring events, the first date on/after which occurrences begin.",
          "format": "date"
         },
         "endDate": {
          "type": "string",
          "description": "End date for recurring events as YYYY-MM-DD (omit for open-ended)",
          "format": "date"
         },
         "venueId": {
          "type": "integer",
          "description": "Location/venue ID"
         },
         "venueOverride": {
          "type": "string",
          "description": "Off-site venue label, for a class at a place that is not a school venue; a venueId clears it, and an off-site label clears the venueId. One-off or recurring.",
          "maxLength": 255
         },
         "venueAddress": {
          "type": "string",
          "description": "off-site street address (with venueOverride)",
          "maxLength": 255
         },
         "venueSuburb": {
          "type": "string",
          "description": "off-site suburb",
          "maxLength": 100
         },
         "venueState": {
          "type": "string",
          "description": "off-site state",
          "maxLength": 100
         },
         "venuePostcode": {
          "type": "string",
          "description": "off-site postcode",
          "maxLength": 20
         },
         "venueCountry": {
          "type": "string",
          "description": "off-site country",
          "maxLength": 100
         },
         "venueLat": {
          "type": "number",
          "description": "off-site latitude; looked up from the address when omitted"
         },
         "venueLng": {
          "type": "number",
          "description": "off-site longitude; looked up from the address when omitted"
         },
         "meetingUrl": {
          "type": "string",
          "description": "Video meeting link for virtual classes",
          "format": "url"
         },
         "capacity": {
          "type": "integer",
          "description": "Maximum capacity"
         },
         "minAge": {
          "type": "integer",
          "description": "Youngest age that may book, on the class's day, inclusive. Null = no minimum. A student with no birthday on file may book."
         },
         "maxAge": {
          "type": "integer",
          "description": "Oldest age that may book, on the class's day, inclusive. Null = no maximum."
         },
         "openToAllStudents": {
          "type": "boolean",
          "description": "Every Active Student and Trial is on the event's check-in roster, booked or not. Still filtered by the event's styles. With no venue, the event is offered on every kiosk of the school."
         },
         "allowDropins": {
          "type": "boolean",
          "description": "Allow drop-in bookings (false = roster only). Always true while the event is published to the website widget (visibility bit 1): publishing decides it.",
          "default": true
         },
         "selfEnrollable": {
          "type": "boolean",
          "description": "Stored, and read by nothing: students do not enrol themselves. Staff put a student on the class roster.",
          "default": false
         },
         "price": {
          "type": "integer",
          "description": "Price in cents (for paid events)"
         },
         "noShowFee": {
          "type": "integer",
          "description": "No-show fee in cents",
          "default": 0
         },
         "noShowConsumesPass": {
          "type": "boolean",
          "description": "No-show still consumes a pass",
          "default": false
         },
         "visibility": {
          "type": "integer",
          "description": "Bitmask: 1=widget, 2=app, 4=invite_only",
          "minimum": 0,
          "maximum": 7,
          "default": 0
         },
         "notifications": {
          "type": "boolean",
          "description": "Enable notifications",
          "default": false
         },
         "waiverId": {
          "type": "integer",
          "description": "Required waiver ID (null on update clears it)"
         },
         "styleIds": {
          "type": "array",
          "description": "The styles this class is for, from list_styles_and_ranks. Every class names at least one, or allStyles; a school with a single style needs no answer. Members see and book a class only in a style they belong to. On an update the list replaces the class's styles, but a style stays while any of its ranks is still in rankIds, so send both to drop one.",
          "items": {
           "type": "integer"
          }
         },
         "allStyles": {
          "type": "boolean",
          "description": "A whole-school class (a seminar, a camp). It follows the school's styles, so one added later is included. It stays on until an update sends allStyles: false."
         },
         "rankIds": {
          "type": "array",
          "description": "Optional: limit a style to these ranks. A rank names its style.",
          "items": {
           "type": "integer"
          }
         },
         "trialEligible": {
          "type": "boolean",
          "description": "Leads and students on trial are offered this class, and only classes like it",
          "default": false
         },
         "updateScope": {
          "type": "string",
          "description": "For a recurring class: this occurrence only (an exception on fromDate), this and later ones (the class is split at fromDate), or every occurrence",
          "enum": [
           "single",
           "future",
           "all"
          ],
          "default": "all"
         },
         "fromDate": {
          "type": "string",
          "description": "The occurrence updateScope single or future starts from (YYYY-MM-DD)",
          "format": "date"
         }
        }
       },
       "example": {
        "name": "string",
        "description": "string",
        "type": "single",
        "days": 1,
        "startTime": "18:00",
        "endTime": "18:00",
        "startDate": "2026-11-05",
        "endDate": "2026-11-05",
        "venueId": 1,
        "venueOverride": "string",
        "venueAddress": "string",
        "venueSuburb": "string",
        "venueState": "string",
        "venuePostcode": "string",
        "venueCountry": "string",
        "venueLat": 1,
        "venueLng": 1,
        "meetingUrl": "https://example.com",
        "capacity": 1,
        "minAge": 1,
        "maxAge": 1,
        "openToAllStudents": false,
        "allowDropins": true,
        "selfEnrollable": false,
        "price": 1,
        "noShowFee": 0,
        "noShowConsumesPass": false,
        "visibility": 0,
        "notifications": false,
        "waiverId": 1,
        "styleIds": [
         1
        ],
        "allStyles": false,
        "rankIds": [
         1
        ],
        "trialEligible": false,
        "updateScope": "all",
        "fromDate": "2026-11-05"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "events_delete",
    "summary": "delete",
    "description": "Delete/cancel an event. Requires ?confirm=true. Query: mode (single|future|all), date (YYYY-MM-DD), notify (boolean: email the booked and enrolled students), reason (optional text added to that email, max 500)",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/events/{id}/duplicate": {
   "post": {
    "operationId": "events_duplicate",
    "summary": "duplicate",
    "description": "Create a copy of an existing event. Use ?preview=true for dry run.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.EventDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "type": "single",
            "days": 1,
            "startTime": "18:00",
            "endTime": "18:00",
            "startDate": "2026-11-05",
            "endDate": "2026-11-05",
            "venueId": 1,
            "venueOverride": "string",
            "venueAddress": "string",
            "venueSuburb": "string",
            "venueState": "string",
            "venuePostcode": "string",
            "venueCountry": "string",
            "venueLat": 1,
            "venueLng": 1,
            "venueName": "string",
            "meetingUrl": "string",
            "capacity": 1,
            "minAge": 1,
            "maxAge": 1,
            "openToAllStudents": false,
            "price": 1,
            "allowDropins": false,
            "selfEnrollable": false,
            "visibility": 1,
            "noShowFee": 1,
            "noShowConsumesPass": false,
            "notifications": false,
            "waiverId": 1,
            "createdOn": 1,
            "enrollmentCount": 1,
            "bookingCount": 1,
            "isGrading": false,
            "trialEligible": false,
            "allStyles": false,
            "styles": [],
            "needsStyle": false,
            "ranks": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "type": "single",
            "days": 1,
            "startTime": "18:00",
            "endTime": "18:00",
            "startDate": "2026-11-05",
            "endDate": "2026-11-05",
            "venueId": 1,
            "venueOverride": "string",
            "venueAddress": "string",
            "venueSuburb": "string",
            "venueState": "string",
            "venuePostcode": "string",
            "venueCountry": "string",
            "venueLat": 1,
            "venueLng": 1,
            "venueName": "string",
            "meetingUrl": "string",
            "capacity": 1,
            "minAge": 1,
            "maxAge": 1,
            "openToAllStudents": false,
            "price": 1,
            "allowDropins": false,
            "selfEnrollable": false,
            "visibility": 1,
            "noShowFee": 1,
            "noShowConsumesPass": false,
            "notifications": false,
            "waiverId": 1,
            "createdOn": 1,
            "enrollmentCount": 1,
            "bookingCount": 1,
            "isGrading": false,
            "trialEligible": false,
            "allStyles": false,
            "styles": [],
            "needsStyle": false,
            "ranks": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Override name (default: original + ' (Copy)')"
         },
         "startDate": {
          "type": "string",
          "description": "New start date as YYYY-MM-DD",
          "format": "date"
         },
         "includeEnrollments": {
          "type": "boolean",
          "description": "Copy existing roster enrollments",
          "default": false
         }
        }
       },
       "example": {
        "name": "string",
        "startDate": "2026-11-05",
        "includeEnrollments": false
       }
      }
     }
    }
   }
  },
  "/v1/events/{id}/occurrences": {
   "get": {
    "operationId": "events_getOccurrences",
    "summary": "getOccurrences",
    "description": "Expand a recurring event into individual date occurrences within a range. Returns dates with exception overrides applied.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.Occurrence"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "date": "2026-11-05",
           "startTime": "18:00",
           "endTime": "18:00",
           "cancelled": false,
           "hasException": false,
           "venueId": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "Range start (YYYY-MM-DD)"
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "Range end (YYYY-MM-DD)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/events/{id}/attendees": {
   "get": {
    "operationId": "events_getAttendees",
    "summary": "getAttendees",
    "description": "Get enriched attendee list for an event occurrence (enrollments + bookings merged with rank, email, billing status).",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.Attendee"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "studentId": 1,
           "studentName": "string",
           "source": "enrollment",
           "attendanceStatus": "attended",
           "rankName": "string",
           "email": "string"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "Occurrence date (YYYY-MM-DD)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/events/{id}/waiver-check": {
   "get": {
    "operationId": "events_waiverCheck",
    "summary": "waiverCheck",
    "description": "Which of these students have not signed the event's waiver. Use it before booking or enrolling to see who would be refused with WAIVER_REQUIRED. waiver is null when the event needs none; missing lists the ids without a current signature. Only the school's own students are checked.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/events.EventWaiverCheck"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "waiver": {},
          "missing": [
           {}
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "studentIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "Comma-separated student ids, at most 50"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/events/{id}/attendees/export": {
   "get": {
    "operationId": "events_exportAttendees",
    "summary": "exportAttendees",
    "description": "Download a class occurrence's roster as CSV: enrolled and booked students, anyone checked in or marked, and guests booked with no student record. v1's columns (status, name, email, mobile, phone, belt size, rank, next rank) under a heading line naming the class; email and phone columns follow the caller's student permissions. Requires Students.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "Occurrence date (YYYY-MM-DD)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/events/bookings": {
   "get": {
    "operationId": "events_listBookings",
    "summary": "listBookings",
    "description": "List bookings.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.Booking"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "eventId": 1,
           "eventName": "string",
           "studentId": 1,
           "studentName": "string",
           "eventDate": "2026-11-05",
           "status": "pending",
           "paidOn": 1,
           "transactionId": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "One student's bookings"
     },
     {
      "name": "eventId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "One event's bookings"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Occurrences on or after (YYYY-MM-DD)"
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Occurrences on or before (YYYY-MM-DD)"
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "upcoming",
        "attended",
        "cancelled",
        "no_show"
       ]
      }
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 20
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "events_createBooking",
    "summary": "createBooking",
    "description": "Create a booking for an event occurrence. Nothing is charged for a pay-as-you-go member at booking: their plan's session is charged when they attend. Returns 409 WAIVER_REQUIRED when the event has a waiver attached and the student lacks a current signed signature for it. Returns 409 CONFLICT, with the reason in the message, when the student already has an active booking for that class, the class does not run on that date, or the student is outside its age range; nothing is written.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.BookingResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "booking": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "booking": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, WAIVER_REQUIRED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "WAIVER_REQUIRED",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "eventId": {
          "type": "integer",
          "description": "Event ID"
         },
         "studentId": {
          "type": "integer",
          "description": "Student ID"
         },
         "eventDate": {
          "type": "string",
          "description": "Date of the occurrence (YYYY-MM-DD)",
          "format": "date"
         }
        },
        "required": [
         "eventId",
         "studentId",
         "eventDate"
        ]
       },
       "example": {
        "eventId": 1,
        "studentId": 1,
        "eventDate": "2026-11-05"
       }
      }
     }
    }
   }
  },
  "/v1/events/bookings/{id}": {
   "delete": {
    "operationId": "events_cancelBooking",
    "summary": "cancelBooking",
    "description": "Cancel a booking. Cancelling never refunds: the response is {cancelled, wasPaid}, and wasPaid=true means the booking carried a payment (a class's own price) that the school keeps and may refund from the member's billing. Surface that to the user. Supports ?preview=true: returns {wasPaid} WITHOUT cancelling, so callers can say so first. A no-show that used a pass answers 409 NO_SHOW_PASS_DECISION_REQUIRED until the request carries ?noShowPass=return (give the pass back) or ?noShowPass=keep.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "noShowPass",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "return",
        "keep"
       ]
      },
      "description": "For a no-show that used a pass: give the pass back, or keep it. Asked for when absent."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/events/bookings/{id}/reschedule": {
   "post": {
    "operationId": "events_rescheduleBooking",
    "summary": "rescheduleBooking",
    "description": "Move a booking to a different occurrence of the same event. Preserves the original payment or pass: no refund or recharge.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.Booking"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "eventId": 1,
            "eventName": "string",
            "studentId": 1,
            "studentName": "string",
            "eventDate": "2026-11-05",
            "status": "pending",
            "paidOn": 1,
            "transactionId": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "eventId": 1,
            "eventName": "string",
            "studentId": 1,
            "studentName": "string",
            "eventDate": "2026-11-05",
            "status": "pending",
            "paidOn": 1,
            "transactionId": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "eventDate": {
          "type": "string",
          "description": "New occurrence date (YYYY-MM-DD)",
          "format": "date"
         }
        },
        "required": [
         "eventDate"
        ]
       },
       "example": {
        "eventDate": "2026-11-05"
       }
      }
     }
    }
   }
  },
  "/v1/events/bookings/upcoming": {
   "get": {
    "operationId": "events_getUpcomingSchedule",
    "summary": "getUpcomingSchedule",
    "description": "Get a student's upcoming schedule: combines bookings and enrollment-based occurrences into a unified timeline.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.UpcomingEntry"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "eventId": 1,
           "eventName": "string",
           "date": "2026-11-05",
           "startTime": "18:00",
           "endTime": "18:00",
           "source": "enrollment",
           "venueName": "string"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Student ID"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/events/{id}/enrollments": {
   "get": {
    "operationId": "events_listEnrollments",
    "summary": "listEnrollments",
    "description": "List students enrolled in an event roster",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.Enrollment"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "eventId": 1,
           "studentId": 1,
           "studentName": "string",
           "enrolledOn": 1,
           "enrolledByName": "string"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "events_enrollStudent",
    "summary": "enrollStudent",
    "description": "Put a student on an event's roster: a standing seat at every class. Returns 409 WAIVER_REQUIRED when the event has a waiver attached and the student lacks a current signed signature for it. Returns 409 ROSTER_OVERBOOKS_DATES (details.dates: date, rostered, booked, capacity) when bookings already made would take a coming date over capacity; nothing is written until the request is repeated with acceptOverbookedDates: true.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.Enrollment"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "eventId": 1,
            "studentId": 1,
            "studentName": "string",
            "enrolledOn": 1,
            "enrolledByName": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "eventId": 1,
            "studentId": 1,
            "studentName": "string",
            "enrolledOn": 1,
            "enrolledByName": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer",
          "description": "Student to enroll"
         },
         "acceptOverbookedDates": {
          "type": "boolean",
          "description": "Roster the student even though the dates named by ROSTER_OVERBOOKS_DATES will run over capacity. Ask the person first."
         }
        },
        "required": [
         "studentId"
        ]
       },
       "example": {
        "studentId": 1
       }
      }
     }
    }
   }
  },
  "/v1/events/bookings/bulk": {
   "post": {
    "operationId": "events_bulkCreateBookings",
    "summary": "bulkCreateBookings",
    "description": "Book many students onto one occurrence, in list order: a seat while the class has one. Past the last seat the rest are left out unless waitlistOverflow is true, when they join the waitlist and get the normal waitlist email. The dry run names each student's outcome and charge (a pay-as-you-go plan reads its session price, charged at check-in), and who is skipped and why. The run is queued as an operation: the answer is { operationId, label }, followed through GET /v1/operations/:id.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "eventId": {
          "type": "integer"
         },
         "eventDate": {
          "type": "string",
          "description": "The occurrence (YYYY-MM-DD)",
          "format": "date"
         },
         "studentIds": {
          "type": "array",
          "description": "The selection, in the order seats are given (1 to 10,000)",
          "items": {
           "type": "integer"
          }
         },
         "waitlistOverflow": {
          "type": "boolean",
          "description": "Students past the last seat join the waitlist. Default false: they are left out and named in the result."
         }
        },
        "required": [
         "eventId",
         "eventDate",
         "studentIds"
        ]
       },
       "example": {
        "eventId": 1,
        "eventDate": "2026-11-05",
        "studentIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/events/{id}/enrollments/bulk": {
   "post": {
    "operationId": "events_bulkEnroll",
    "summary": "bulkEnroll",
    "description": "Put several students on an event's roster. Returns 409 ROSTER_OVERBOOKS_DATES, as the single enrol does, when the batch would take a coming date over capacity; nothing is written until repeated with acceptOverbookedDates: true.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "Array of student IDs (1 to 10,000)",
          "items": {
           "description": "integer"
          }
         },
         "acceptOverbookedDates": {
          "type": "boolean",
          "description": "Roster the students even though the dates named by ROSTER_OVERBOOKS_DATES will run over capacity. Ask the person first."
         }
        },
        "required": [
         "studentIds"
        ]
       },
       "example": {
        "studentIds": [
         {}
        ]
       }
      }
     }
    }
   }
  },
  "/v1/events/{id}/enrollments/{studentId}": {
   "delete": {
    "operationId": "events_unenrollStudent",
    "summary": "unenrollStudent",
    "description": "Remove a student from an event roster. A student not on it is refused 409 CONFLICT with error.data.reason NOT_ENROLLED.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/events/{id}/occurrences/{date}/exception": {
   "get": {
    "operationId": "events_getException",
    "summary": "getException",
    "description": "Get exception details for a specific occurrence. :date is the occurrence's date, YYYY-MM-DD (unix seconds are also accepted).",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/events.Exception"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "eventId": 1,
          "exceptionDate": "2026-11-05",
          "cancelled": false,
          "startTime": "18:00",
          "endTime": "18:00",
          "venueId": 1,
          "venueOverride": "string",
          "notes": "string",
          "notifySent": false,
          "createdOn": 1,
          "createdBy": 1,
          "cancelledBookings": [
           {}
          ],
          "reinstated": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "events_createException",
    "summary": "createException",
    "description": "Create an exception to override a specific occurrence. Use to cancel a single class, change venue/time, or add notes.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.Exception"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "eventId": 1,
            "exceptionDate": "2026-11-05",
            "cancelled": false,
            "startTime": "18:00",
            "endTime": "18:00",
            "venueId": 1,
            "venueOverride": "string",
            "notes": "string",
            "notifySent": false,
            "createdOn": 1,
            "createdBy": 1,
            "cancelledBookings": [
             {}
            ],
            "reinstated": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "eventId": 1,
            "exceptionDate": "2026-11-05",
            "cancelled": false,
            "startTime": "18:00",
            "endTime": "18:00",
            "venueId": 1,
            "venueOverride": "string",
            "notes": "string",
            "notifySent": false,
            "createdOn": 1,
            "createdBy": 1,
            "cancelledBookings": [
             {}
            ],
            "reinstated": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "cancelled": {
          "type": "boolean",
          "description": "Cancel this occurrence",
          "default": false
         },
         "startTime": {
          "type": "string",
          "description": "Override start time, HH:MM",
          "format": "time"
         },
         "endTime": {
          "type": "string",
          "description": "Override end time, HH:MM",
          "format": "time"
         },
         "venueId": {
          "type": "integer",
          "description": "Override venue ID"
         },
         "venueOverride": {
          "type": "string",
          "description": "This date's off-site venue label; a venueId clears it",
          "maxLength": 255
         },
         "venueAddress": {
          "type": "string",
          "description": "off-site street address (with venueOverride)",
          "maxLength": 255
         },
         "venueSuburb": {
          "type": "string",
          "description": "off-site suburb",
          "maxLength": 100
         },
         "venueState": {
          "type": "string",
          "description": "off-site state",
          "maxLength": 100
         },
         "venuePostcode": {
          "type": "string",
          "description": "off-site postcode",
          "maxLength": 20
         },
         "venueCountry": {
          "type": "string",
          "description": "off-site country",
          "maxLength": 100
         },
         "venueLat": {
          "type": "number",
          "description": "off-site latitude; looked up from the address when omitted"
         },
         "venueLng": {
          "type": "number",
          "description": "off-site longitude; looked up from the address when omitted"
         },
         "notes": {
          "type": "string",
          "description": "Notes for this occurrence",
          "maxLength": 2000
         },
         "notifyEnrolled": {
          "type": "boolean",
          "description": "Send notification to enrolled students",
          "default": false
         }
        }
       },
       "example": {
        "cancelled": false,
        "startTime": "18:00",
        "endTime": "18:00",
        "venueId": 1,
        "venueOverride": "string",
        "venueAddress": "string",
        "venueSuburb": "string",
        "venueState": "string",
        "venuePostcode": "string",
        "venueCountry": "string",
        "venueLat": 1,
        "venueLng": 1,
        "notes": "string",
        "notifyEnrolled": false
       }
      }
     }
    }
   },
   "patch": {
    "operationId": "events_updateException",
    "summary": "updateException",
    "description": "Update an existing exception. All fields optional. Setting cancelled to false un-cancels the date: the dry run lists the bookings its cancellation cancelled (restorableBookings), and the commit puts them back only with restoreBookings true, emailing those members only with notifyMembers true as well. A booking the member cancelled themselves is never put back.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.Exception"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "eventId": 1,
            "exceptionDate": "2026-11-05",
            "cancelled": false,
            "startTime": "18:00",
            "endTime": "18:00",
            "venueId": 1,
            "venueOverride": "string",
            "notes": "string",
            "notifySent": false,
            "createdOn": 1,
            "createdBy": 1,
            "cancelledBookings": [
             {}
            ],
            "reinstated": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "eventId": 1,
            "exceptionDate": "2026-11-05",
            "cancelled": false,
            "startTime": "18:00",
            "endTime": "18:00",
            "venueId": 1,
            "venueOverride": "string",
            "notes": "string",
            "notifySent": false,
            "createdOn": 1,
            "createdBy": 1,
            "cancelledBookings": [
             {}
            ],
            "reinstated": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "cancelled": {
          "type": "boolean",
          "description": "Cancel this occurrence",
          "default": false
         },
         "startTime": {
          "type": "string",
          "description": "Override start time, HH:MM",
          "format": "time"
         },
         "endTime": {
          "type": "string",
          "description": "Override end time, HH:MM",
          "format": "time"
         },
         "venueId": {
          "type": "integer",
          "description": "Override venue ID"
         },
         "venueOverride": {
          "type": "string",
          "description": "This date's off-site venue label; a venueId clears it",
          "maxLength": 255
         },
         "venueAddress": {
          "type": "string",
          "description": "off-site street address (with venueOverride)",
          "maxLength": 255
         },
         "venueSuburb": {
          "type": "string",
          "description": "off-site suburb",
          "maxLength": 100
         },
         "venueState": {
          "type": "string",
          "description": "off-site state",
          "maxLength": 100
         },
         "venuePostcode": {
          "type": "string",
          "description": "off-site postcode",
          "maxLength": 20
         },
         "venueCountry": {
          "type": "string",
          "description": "off-site country",
          "maxLength": 100
         },
         "venueLat": {
          "type": "number",
          "description": "off-site latitude; looked up from the address when omitted"
         },
         "venueLng": {
          "type": "number",
          "description": "off-site longitude; looked up from the address when omitted"
         },
         "notes": {
          "type": "string",
          "description": "Notes for this occurrence",
          "maxLength": 2000
         },
         "notifyEnrolled": {
          "type": "boolean",
          "description": "Send notification to enrolled students",
          "default": false
         },
         "restoreBookings": {
          "type": "boolean",
          "description": "Put back the bookings this date's cancellation cancelled (never one the member cancelled)",
          "default": false
         },
         "notifyMembers": {
          "type": "boolean",
          "description": "With restoreBookings: email those members that the class is back on",
          "default": false
         }
        }
       },
       "example": {
        "cancelled": false,
        "startTime": "18:00",
        "endTime": "18:00",
        "venueId": 1,
        "venueOverride": "string",
        "venueAddress": "string",
        "venueSuburb": "string",
        "venueState": "string",
        "venuePostcode": "string",
        "venueCountry": "string",
        "venueLat": 1,
        "venueLng": 1,
        "notes": "string",
        "notifyEnrolled": false,
        "restoreBookings": false,
        "notifyMembers": false
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "events_deleteException",
    "summary": "deleteException",
    "description": "Remove an exception (restore occurrence to default behavior). Removing a cancellation is an un-cancel: the optional body answers what happens to the bookings the cancellation cancelled, as on updateException.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "restoreBookings": {
          "type": "boolean",
          "description": "Put back the bookings this date's cancellation cancelled (never one the member cancelled)",
          "default": false
         },
         "notifyMembers": {
          "type": "boolean",
          "description": "With restoreBookings: email those members that the class is back on",
          "default": false
         }
        }
       },
       "example": {
        "restoreBookings": false,
        "notifyMembers": false
       }
      }
     }
    }
   }
  },
  "/v1/events/{id}/occurrences/{date}/attendance": {
   "post": {
    "operationId": "events_markAttendance",
    "summary": "markAttendance",
    "description": "Mark a single student's attendance status for an event occurrence. Marking a rostered member attended with no booking makes one; where the class has its own price and the member's plan does not stand in for it, that price is recorded as owed on the booking and no pay-as-you-go session is charged, as a check-in does. The answer carries classPriceOwedCents when it did.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.AttendanceMarkResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "studentId": 1,
            "action": "attended",
            "bookingId": 1,
            "attendanceId": 1,
            "passDeducted": false,
            "passesRemaining": 1,
            "classHasNoStyle": false,
            "feeCharged": false,
            "feeAmount": 1,
            "payg": {},
            "classPriceOwedCents": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "studentId": 1,
            "action": "attended",
            "bookingId": 1,
            "attendanceId": 1,
            "passDeducted": false,
            "passesRemaining": 1,
            "classHasNoStyle": false,
            "feeCharged": false,
            "feeAmount": 1,
            "payg": {},
            "classPriceOwedCents": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer",
          "description": "Student ID"
         },
         "action": {
          "type": "string",
          "description": "Attendance action",
          "enum": [
           "attended",
           "no_show",
           "excused",
           "clear"
          ]
         },
         "excusedReason": {
          "type": "string",
          "description": "Reason (required when action is 'excused')",
          "maxLength": 255
         },
         "override": {
          "type": "boolean",
          "description": "Admin override: skip validation checks"
         }
        },
        "required": [
         "studentId",
         "action"
        ]
       },
       "example": {
        "studentId": 1,
        "action": "attended"
       }
      }
     }
    }
   }
  },
  "/v1/events/{id}/occurrences/{date}/attendance/bulk": {
   "post": {
    "operationId": "events_bulkMarkAttendance",
    "summary": "bulkMarkAttendance",
    "description": "Bulk mark attendance for multiple students on an event occurrence.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "actions": {
          "type": "array",
          "description": "Array of attendance actions (max 200)",
          "items": {
           "description": "{ studentId: integer, action: attended|no_show|excused|clear, excusedReason?: string }"
          }
         }
        },
        "required": [
         "actions"
        ]
       },
       "example": {
        "actions": [
         {}
        ]
       }
      }
     }
    }
   }
  },
  "/v1/events/{id}/occurrences/{date}/no-shows": {
   "get": {
    "operationId": "events_getNoShowCandidates",
    "summary": "getNoShowCandidates",
    "description": "Get students expected but not yet attended for an event occurrence (enrolled or booked, no attendance marked).",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.NoShowCandidate"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "studentId": 1,
           "studentName": "string",
           "source": "enrollment"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/events/needing-style": {
   "get": {
    "operationId": "events_listNeedingStyle",
    "summary": "listNeedingStyle",
    "description": "The classes still running that have no style and are not whole-school classes. Members cannot be matched to them until someone sets styleIds or allStyles on each.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.ClassNeedingStyle"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "type": "single",
           "days": 1,
           "startDate": "2026-11-05",
           "startTime": "18:00",
           "endTime": "18:00"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/events/no-shows/repeat": {
   "get": {
    "operationId": "events_getRepeatNoShows",
    "summary": "getRepeatNoShows",
    "description": "Get students with repeat no-shows across all events within a time window.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.RepeatNoShow"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "studentId": 1,
           "studentName": "string",
           "noShowCount": 1,
           "events": []
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "threshold",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 3
      },
      "description": "Minimum no-show count to include (default 3)"
     },
     {
      "name": "days",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 30
      },
      "description": "Lookback window in days (default 30)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/events/{id}/occurrences/{date}/waitlist": {
   "get": {
    "operationId": "events_listWaitlist",
    "summary": "listWaitlist",
    "description": "List waitlist entries for a specific occurrence. :date is the occurrence's date, YYYY-MM-DD (unix seconds are also accepted).",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.WaitlistEntry"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "eventId": 1,
           "studentId": 1,
           "studentName": "string",
           "eventDate": "2026-11-05",
           "addedOn": 1,
           "position": 1,
           "promotedOn": 1,
           "promotedToBookingId": 1,
           "removedOn": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "includePromoted",
      "in": "query",
      "schema": {
       "type": "boolean",
       "default": false
      },
      "description": "Include already-promoted entries"
     },
     {
      "name": "includeRemoved",
      "in": "query",
      "schema": {
       "type": "boolean",
       "default": false
      },
      "description": "Include removed entries"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "events_addToWaitlist",
    "summary": "addToWaitlist",
    "description": "Add a student to the waitlist. Student will be placed at the end of the queue.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.WaitlistEntry"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "eventId": 1,
            "studentId": 1,
            "studentName": "string",
            "eventDate": "2026-11-05",
            "addedOn": 1,
            "position": 1,
            "promotedOn": 1,
            "promotedToBookingId": 1,
            "removedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "eventId": 1,
            "studentId": 1,
            "studentName": "string",
            "eventDate": "2026-11-05",
            "addedOn": 1,
            "position": 1,
            "promotedOn": 1,
            "promotedToBookingId": 1,
            "removedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer",
          "description": "Student to add"
         }
        },
        "required": [
         "studentId"
        ]
       },
       "example": {
        "studentId": 1
       }
      }
     }
    }
   }
  },
  "/v1/events/{id}/occurrences/{date}/place-open": {
   "get": {
    "operationId": "events_placeOpen",
    "summary": "placeOpen",
    "description": "A class date's free places and its waitlist queue, in order. Each person is marked blocked when they cannot take a place now: 'waiver' (the class's waiver is unsigned) or 'rostered' (already on the class roster).",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/events.PlaceOpen"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "eventId": 1,
          "eventName": "string",
          "date": "2026-11-05",
          "startTime": "string",
          "capacity": 1,
          "placesFree": 1,
          "waiver": {},
          "queue": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/events/{id}/occurrences/{date}/waitlist/{waitlistId}": {
   "delete": {
    "operationId": "events_removeFromWaitlist",
    "summary": "removeFromWaitlist",
    "description": "Remove a student from the waitlist",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "waitlistId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/events/{id}/occurrences/{date}/waitlist/{waitlistId}/promote": {
   "post": {
    "operationId": "events_promoteFromWaitlist",
    "summary": "promoteFromWaitlist",
    "description": "Promote a waitlist entry to a booking. Creates a booking for the student. Returns { promoted: boolean, booking: BookingSummary }.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.PromoteResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "promoted": false,
            "booking": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "promoted": false,
            "booking": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "waitlistId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/events/{id}/occurrences/{date}/invitations": {
   "get": {
    "operationId": "events_listInviteCandidates",
    "summary": "listInviteCandidates",
    "description": "Students eligible for this occurrence (:date is YYYY-MM-DD) and where each stands: open (can be invited), booked, rostered, invited (no answer yet), declined (said no; can be asked again) or no_email.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/events.InviteCandidate"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "studentId": 1,
           "firstName": "string",
           "lastName": "string",
           "rank": {},
           "state": "open",
           "invitedOn": 1,
           "declinedOn": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "events_inviteStudents",
    "summary": "inviteStudents",
    "description": "Invite students to one occurrence (:date is YYYY-MM-DD). Each is emailed at once with a link to say yes or no; an invitation holds no seat until they say yes. Students who are booked, rostered, already invited or have no email are skipped with the reason.",
    "tags": [
     "events"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/events.InviteResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "invited": [],
            "skipped": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "invited": [],
            "skipped": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "Students to invite (1 to 10,000)",
          "items": {}
         }
        },
        "required": [
         "studentIds"
        ]
       },
       "example": {
        "studentIds": []
       }
      }
     }
    }
   }
  },
  "/v1/calendar": {
   "get": {
    "operationId": "calendar_view",
    "summary": "view",
    "description": "Get aggregated calendar view. Query: view (day|week|month|agenda) and date (YYYY-MM-DD) pick the range, or from and to give it exactly (at most 92 days); venueIds, instructorIds, styleIds, includePrivate filter it",
    "tags": [
     "calendar"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/calendar.CalendarView"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "view": "day",
          "rangeStart": 1,
          "rangeEnd": 1,
          "occurrences": [
           {
            "eventId": 1,
            "eventName": "string",
            "eventType": "single",
            "date": 1,
            "startTime": 1,
            "endTime": 1,
            "venueId": 1,
            "venueName": "string",
            "meetingUrl": "string",
            "capacity": 1,
            "price": 1,
            "enrolledCount": 1,
            "bookedCount": 1,
            "availableSpots": 1,
            "isCancelled": false,
            "needsStyle": false,
            "exception": {}
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "First day of an explicit range (YYYY-MM-DD). Send with to; replaces view and date."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Last day of the range, inclusive (YYYY-MM-DD). At most 92 days after from."
     },
     {
      "name": "view",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "day",
        "week",
        "month",
        "agenda"
       ],
       "default": "week"
      }
     },
     {
      "name": "date",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Reference date (YYYY-MM-DD). Defaults to today."
     },
     {
      "name": "venueIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Comma-separated venue IDs to filter"
     },
     {
      "name": "instructorIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Comma-separated instructor IDs to filter"
     },
     {
      "name": "styleIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Comma-separated style IDs to filter"
     },
     {
      "name": "includePrivate",
      "in": "query",
      "schema": {
       "type": "boolean",
       "default": true
      },
      "description": "Include events with visibility=0"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/calendar/export": {
   "get": {
    "operationId": "calendar_export",
    "summary": "export",
    "description": "Export calendar data as iCal (.ics) file or JSON. Uses the same view/date/venue filters as the view endpoint.",
    "tags": [
     "calendar"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/calendar.CalendarView"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "view": "day",
          "rangeStart": 1,
          "rangeEnd": 1,
          "occurrences": [
           {
            "eventId": 1,
            "eventName": "string",
            "eventType": "single",
            "date": 1,
            "startTime": 1,
            "endTime": 1,
            "venueId": 1,
            "venueName": "string",
            "meetingUrl": "string",
            "capacity": 1,
            "price": 1,
            "enrolledCount": 1,
            "bookedCount": 1,
            "availableSpots": 1,
            "isCancelled": false,
            "needsStyle": false,
            "exception": {}
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "view",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "day",
        "week",
        "month",
        "agenda"
       ],
       "default": "week"
      }
     },
     {
      "name": "date",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Reference date (YYYY-MM-DD). Defaults to today."
     },
     {
      "name": "venueIds",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Comma-separated venue IDs to filter"
     },
     {
      "name": "format",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "ics",
        "json"
       ],
       "default": "ics"
      },
      "description": "Export format. 'ics' returns a downloadable.ics file, 'json' returns structured data."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/calendar/feed.ics": {
   "get": {
    "operationId": "calendar_feed",
    "summary": "feed",
    "description": "Admin-authed iCal preview of the feed (next 30 days of public events, text/calendar). External calendar apps cannot send auth headers. Subscribe them to the tokenized public URL from the feedUrl operation instead.",
    "tags": [
     "calendar"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/calendar/feed-url": {
   "get": {
    "operationId": "calendar_feedUrl",
    "summary": "feedUrl",
    "description": "The school's subscribable public feed URL (/v1/public/calendar/:token/feed.ics). The URL carries a signed per-school token since calendar apps can't authenticate; paste it into Google/Apple/Outlook as a calendar subscription.",
    "tags": [
     "calendar"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/calendar/feed-url/rotate": {
   "post": {
    "operationId": "calendar_feedUrlRotate",
    "summary": "feedUrlRotate",
    "description": "Revoke the current feed URL and mint a new one. Previously issued URLs stop working immediately; existing calendar-app subscriptions must be re-added with the new URL. ?preview=true is a dry run that mints nothing.",
    "tags": [
     "calendar"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/plans": {
   "get": {
    "operationId": "billing_listPlans",
    "summary": "listPlans",
    "description": "List billing plans with filtering, sorting, and pagination. Returns enriched plans with style associations, subscriber counts, and gateway linkage info.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.BillingPlan"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "name": "string",
           "type": "recurring",
           "amount": 1,
           "billingPeriod": "week",
           "billingInterval": 1,
           "attendanceFrequency": 1,
           "attendancePeriod": "string",
           "quantity": 1,
           "expiryDuration": 1,
           "expiryPeriod": "string",
           "paygAmountPerSession": 1,
           "chargeTrigger": "attendance",
           "styleIds": [
            1
           ],
           "subscriberCount": 1,
           "gatewayLinked": false,
           "createdOn": 1793836800,
           "deletedOn": 1793836800
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "type",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "recurring",
        "passes",
        "one_time",
        "payg"
       ]
      },
      "description": "Filter by plan type"
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter plans associated with this style ID"
     },
     {
      "name": "archived",
      "in": "query",
      "schema": {
       "type": "boolean",
       "default": false
      },
      "description": "Include archived (soft-deleted) plans. Default: false"
     },
     {
      "name": "gatewayLinked",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Filter to plans that are gateway-linked (Stripe/GoCardless) or local-only"
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Search by plan name (partial match)"
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string",
       "default": "-createdOn"
      },
      "description": "Sort field with optional - prefix for descending. Default: -createdOn Allowed fields: name, amount, type, createdOn"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "Page number (1-indexed). Default: 1"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 20
      },
      "description": "Items per page (max 100). Default: 20"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "billing_createPlan",
    "summary": "createPlan",
    "description": "Create a new billing plan. Amount is in cents. billingPeriod is required for recurring plans, quantity is required for passes plans.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.BillingPlan"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "type": "recurring",
            "amount": 1,
            "billingPeriod": "week",
            "billingInterval": 1,
            "attendanceFrequency": 1,
            "attendancePeriod": "string",
            "quantity": 1,
            "expiryDuration": 1,
            "expiryPeriod": "string",
            "paygAmountPerSession": 1,
            "chargeTrigger": "attendance",
            "styleIds": [
             1
            ],
            "subscriberCount": 1,
            "gatewayLinked": false,
            "createdOn": 1793836800,
            "deletedOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "type": "recurring",
            "amount": 1,
            "billingPeriod": "week",
            "billingInterval": 1,
            "attendanceFrequency": 1,
            "attendancePeriod": "string",
            "quantity": 1,
            "expiryDuration": 1,
            "expiryPeriod": "string",
            "paygAmountPerSession": 1,
            "chargeTrigger": "attendance",
            "styleIds": [
             1
            ],
            "subscriberCount": 1,
            "gatewayLinked": false,
            "createdOn": 1793836800,
            "deletedOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Plan name",
          "minLength": 1,
          "maxLength": 300
         },
         "type": {
          "type": "string",
          "description": "Plan type",
          "enum": [
           "recurring",
           "passes",
           "one_time",
           "payg"
          ]
         },
         "amount": {
          "type": "integer",
          "description": "Amount in cents (must be positive)",
          "minimum": 1
         },
         "billingPeriod": {
          "type": "string",
          "description": "Required for recurring plans",
          "enum": [
           "week",
           "month",
           "year"
          ]
         },
         "billingInterval": {
          "type": "integer",
          "description": "Billing interval (e.g., 2 = every 2 months). Default: 1",
          "minimum": 1,
          "default": 1
         },
         "attendanceFrequency": {
          "type": "integer",
          "description": "Max attendance per period (null = unlimited). Optional."
         },
         "attendancePeriod": {
          "type": "string",
          "description": "Attendance period unit. Optional.",
          "enum": [
           "day",
           "week",
           "month",
           "year"
          ]
         },
         "quantity": {
          "type": "integer",
          "description": "Total passes. Required for passes plans."
         },
         "expiryDuration": {
          "type": "integer",
          "description": "Expiry duration for passes/one_time. Optional."
         },
         "expiryPeriod": {
          "type": "string",
          "description": "Expiry period unit. Optional.",
          "enum": [
           "day",
           "week",
           "month",
           "year"
          ]
         },
         "styleIds": {
          "type": "array",
          "description": "Style IDs to associate with this plan. Default: []",
          "items": {
           "type": "integer"
          }
         },
         "paygAmountPerSession": {
          "type": "integer",
          "description": "Price per class in cents. Required for payg plans.",
          "minimum": 1
         },
         "chargeTrigger": {
          "type": "string",
          "description": "When a payg plan charges a class: when the member attends. This is the only value. To take payment when a class is booked, put a price on the class instead; \"booking\" and \"both\" are refused.",
          "enum": [
           "attendance"
          ],
          "default": "attendance"
         }
        },
        "required": [
         "name",
         "type",
         "amount"
        ]
       },
       "example": {
        "name": "string",
        "type": "recurring",
        "amount": 1
       }
      }
     }
    }
   }
  },
  "/v1/billing/plans/filters": {
   "get": {
    "operationId": "billing_planFilters",
    "summary": "planFilters",
    "description": "Get available filter options for the plans list. Returns plan types (recurring, passes, one_time), billing periods (week, month, year), and the school's martial arts styles ({ id, name }).",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.PlanFilterOptions"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "types": [],
          "billingPeriods": [],
          "styles": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/plans/{id}": {
   "get": {
    "operationId": "billing_getPlan",
    "summary": "getPlan",
    "description": "Get a single billing plan by ID with style associations and active subscriber count.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.BillingPlan"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "name": "string",
          "type": "recurring",
          "amount": 1,
          "billingPeriod": "week",
          "billingInterval": 1,
          "attendanceFrequency": 1,
          "attendancePeriod": "string",
          "quantity": 1,
          "expiryDuration": 1,
          "expiryPeriod": "string",
          "paygAmountPerSession": 1,
          "chargeTrigger": "attendance",
          "styleIds": [
           1
          ],
          "subscriberCount": 1,
          "gatewayLinked": false,
          "createdOn": 1793836800,
          "deletedOn": 1793836800
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "billing_updatePlan",
    "summary": "updatePlan",
    "description": "Update non-price fields of a billing plan. Price changes are not supported in this phase.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.BillingPlan"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "type": "recurring",
            "amount": 1,
            "billingPeriod": "week",
            "billingInterval": 1,
            "attendanceFrequency": 1,
            "attendancePeriod": "string",
            "quantity": 1,
            "expiryDuration": 1,
            "expiryPeriod": "string",
            "paygAmountPerSession": 1,
            "chargeTrigger": "attendance",
            "styleIds": [
             1
            ],
            "subscriberCount": 1,
            "gatewayLinked": false,
            "createdOn": 1793836800,
            "deletedOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "type": "recurring",
            "amount": 1,
            "billingPeriod": "week",
            "billingInterval": 1,
            "attendanceFrequency": 1,
            "attendancePeriod": "string",
            "quantity": 1,
            "expiryDuration": 1,
            "expiryPeriod": "string",
            "paygAmountPerSession": 1,
            "chargeTrigger": "attendance",
            "styleIds": [
             1
            ],
            "subscriberCount": 1,
            "gatewayLinked": false,
            "createdOn": 1793836800,
            "deletedOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Plan name",
          "minLength": 1,
          "maxLength": 300
         },
         "attendanceFrequency": {
          "type": "integer",
          "description": "Max attendance per period (null = unlimited)"
         },
         "attendancePeriod": {
          "type": "string",
          "description": "Attendance period unit",
          "enum": [
           "day",
           "week",
           "month",
           "year"
          ]
         },
         "expiryDuration": {
          "type": "integer",
          "description": "Expiry duration"
         },
         "expiryPeriod": {
          "type": "string",
          "description": "Expiry period unit",
          "enum": [
           "day",
           "week",
           "month",
           "year"
          ]
         },
         "styleIds": {
          "type": "array",
          "description": "Replace associated style IDs",
          "items": {
           "type": "integer"
          }
         }
        }
       },
       "example": {
        "name": "string",
        "attendanceFrequency": 1,
        "attendancePeriod": "day",
        "expiryDuration": 1,
        "expiryPeriod": "day",
        "styleIds": [
         1
        ]
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "billing_archivePlan",
    "summary": "archivePlan",
    "description": "Archive (soft-delete) a billing plan. Returns cascade effects showing active subscription count. Requires ?confirm=true if subscriptions exist, and a plan with members on it is refused (409) unless ?cancelSubscribers=true is sent too: it is never archived with members left billing on it. With ?cancelSubscribers=true every active subscription is cancelled through the gateway-first cancel lane first; if any cancel fails the plan is NOT archived and the failures are returned.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "cancelSubscribers",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Cancel all active subscriptions on the plan (gateway-first) before archiving. Default false: subscribers stay on the archived plan."
     },
     {
      "name": "atPeriodEnd",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "With cancelSubscribers: schedule each subscription to end at its own current period end instead of cancelling immediately. Subscribers keep billing until then. A pass pack, a one-time plan or a pay-as-you-go plan has no billing period: with this set nobody on it is cancelled and the answer carries keptSubscriptions. A pack or one-time plan is kept until it is used up or expires. A pay-as-you-go plan never runs out: each member stays on it, charged for each class they attend, until they are removed. Refused (409) while one of them is still confirming a payment."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}": {
   "get": {
    "operationId": "billing_getStudentBilling",
    "summary": "getStudentBilling",
    "description": "Get a student's billing data including active plans/subscriptions and recent transactions.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.StudentBillingData"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "currency": {},
          "plans": [
           {}
          ],
          "transactions": [
           {}
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 10
      },
      "description": "Max number of transactions to return. Default: 10, Max: 100"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/profile": {
   "get": {
    "operationId": "billing_getBillingProfile",
    "summary": "getBillingProfile",
    "description": "Get a student's combined gateway billing profile. Returns Stripe (balance, payment methods, default) and GoCardless (mandates, status) connection details.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.BillingProfile"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "stripe": {},
          "gocardless": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/gateway/status": {
   "get": {
    "operationId": "billing_getGatewayStatus",
    "summary": "getGatewayStatus",
    "description": "Check connected payment gateways for the school. Returns Stripe and GoCardless connection status.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/gateway/stripe/connect": {
   "post": {
    "operationId": "billing_stripeConnect",
    "summary": "stripeConnect",
    "description": "Initiate Stripe Connect OAuth flow. Returns an authorization URL to redirect the user to.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "redirectUri": {
          "type": "string",
          "description": "URL to redirect back to after OAuth completes"
         }
        },
        "required": [
         "redirectUri"
        ]
       },
       "example": {
        "redirectUri": "string"
       }
      }
     }
    }
   }
  },
  "/v1/billing/gateway/stripe/callback": {
   "get": {
    "operationId": "billing_stripeCallback",
    "summary": "stripeCallback",
    "description": "Handle Stripe Connect OAuth callback. Exchanges authorization code for credentials and redirects to admin.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "code",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Authorization code from Stripe"
     },
     {
      "name": "state",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "CSRF state token"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/gateway/stripe/disconnect": {
   "post": {
    "operationId": "billing_stripeDisconnect",
    "summary": "stripeDisconnect",
    "description": "Disconnect Stripe from the school. Requires ?confirm=true; ?preview=true is a dry run naming the members billed through Stripe (liveMembers, plans) and what the subscriptions=cancel|keep choice will do.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/gateway/gocardless/connect": {
   "post": {
    "operationId": "billing_gocardlessConnect",
    "summary": "gocardlessConnect",
    "description": "Initiate GoCardless Partner OAuth flow. Returns an authorization URL.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "redirectUri": {
          "type": "string",
          "description": "URL to redirect back to after OAuth completes"
         }
        },
        "required": [
         "redirectUri"
        ]
       },
       "example": {
        "redirectUri": "string"
       }
      }
     }
    }
   }
  },
  "/v1/billing/gateway/gocardless/callback": {
   "get": {
    "operationId": "billing_gocardlessCallback",
    "summary": "gocardlessCallback",
    "description": "Handle GoCardless OAuth callback. Exchanges code for credentials and redirects to admin.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "code",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Authorization code from GoCardless"
     },
     {
      "name": "state",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "CSRF state token"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/gateway/gocardless/disconnect": {
   "post": {
    "operationId": "billing_gocardlessDisconnect",
    "summary": "gocardlessDisconnect",
    "description": "Disconnect GoCardless from the school. Requires ?confirm=true; ?preview=true is a dry run naming the members billed through GoCardless (liveMembers, plans) and what the subscriptions=cancel|keep choice will do.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/gateway/sync": {
   "post": {
    "operationId": "billing_syncScan",
    "summary": "syncScan",
    "description": "Scan a payment gateway for customers and match them to local students and plans. Returns match results for review before confirming.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "gateway": {
          "type": "string",
          "description": "Which gateway to scan. Defaults to stripe.",
          "enum": [
           "stripe",
           "gocardless"
          ]
         }
        }
       },
       "example": {
        "gateway": "stripe"
       }
      }
     }
    }
   }
  },
  "/v1/billing/gateway/sync/import/{jobId}/execute": {
   "post": {
    "operationId": "billing_syncImportExecute",
    "summary": "syncImportExecute",
    "description": "Execute a planned gateway import run: writes the manifest's customers, subscriptions and payment history. Refused without ?confirm=true. The run must be in the planned phase.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "jobId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/gateway/sync/confirm": {
   "post": {
    "operationId": "billing_syncConfirm",
    "summary": "syncConfirm",
    "description": "Confirm sync matches and wire up billing relationships. Creates external references and subscriptions for confirmed student matches.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "confirmedMatches": {
          "type": "object",
          "description": "Mapping of gateway customer ID to local student ID"
         },
         "plansToCreate": {
          "type": "array",
          "description": "Gateway plans to create as local billing plans",
          "items": {}
         },
         "resolvedAmbiguous": {
          "type": "object",
          "description": "Resolved ambiguous matches (gateway customer ID to selected student ID)"
         },
         "includeHistory": {
          "type": "boolean",
          "description": "Whether to import historical transactions. Default: false",
          "default": false
         }
        },
        "required": [
         "confirmedMatches"
        ]
       },
       "example": {
        "confirmedMatches": {}
       }
      }
     }
    }
   }
  },
  "/v1/billing/gateway/sync/status": {
   "get": {
    "operationId": "billing_syncStatus",
    "summary": "syncStatus",
    "description": "Get the last sync scan results, including match summary and scan timestamp.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/subscriptions": {
   "get": {
    "operationId": "billing_listSubscriptions",
    "summary": "listSubscriptions",
    "description": "List all subscriptions for a student with computed status (active, paused, overdue, etc).",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.Subscription"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "planId": 1,
           "studentId": 1,
           "familyId": 1,
           "shopOrderId": 1,
           "externalId": "string",
           "type": "string",
           "status": "draft",
           "gatewayStatus": "string",
           "mandateStatus": "string",
           "nextPaymentOn": 1,
           "overdueAmountCents": 1,
           "discount": 1,
           "discountType": 0,
           "automaticTxns": false,
           "emailReceipt": false,
           "passesRemaining": 1,
           "startOn": 1793836800,
           "endOn": 1793836800,
           "pausedOn": 1793836800,
           "cancelledOn": 1793836800,
           "cancelAtPeriodEnd": false,
           "scheduledCancelDate": 1793836800,
           "plan": {}
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "billing_assignPlan",
    "summary": "assignPlan",
    "description": "Assign a billing plan to a student, creating a subscription. For gateway-linked plans (Stripe/GoCardless), creates the subscription on the gateway. When the plan is set up but something after it did not get done (a payment already made that could not be recorded, a payment request that could not be sent, a card check that could not be started), the answer carries `unfinished`: sentences to show the person. The plan stands; do not assign it again.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.Subscription"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "planId": 1,
            "studentId": 1,
            "familyId": 1,
            "shopOrderId": 1,
            "externalId": "string",
            "type": "string",
            "status": "draft",
            "gatewayStatus": "string",
            "mandateStatus": "string",
            "nextPaymentOn": 1,
            "overdueAmountCents": 1,
            "discount": 1,
            "discountType": 0,
            "automaticTxns": false,
            "emailReceipt": false,
            "passesRemaining": 1,
            "startOn": 1793836800,
            "endOn": 1793836800,
            "pausedOn": 1793836800,
            "cancelledOn": 1793836800,
            "cancelAtPeriodEnd": false,
            "scheduledCancelDate": 1793836800,
            "plan": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "planId": 1,
            "studentId": 1,
            "familyId": 1,
            "shopOrderId": 1,
            "externalId": "string",
            "type": "string",
            "status": "draft",
            "gatewayStatus": "string",
            "mandateStatus": "string",
            "nextPaymentOn": 1,
            "overdueAmountCents": 1,
            "discount": 1,
            "discountType": 0,
            "automaticTxns": false,
            "emailReceipt": false,
            "passesRemaining": 1,
            "startOn": 1793836800,
            "endOn": 1793836800,
            "pausedOn": 1793836800,
            "cancelledOn": 1793836800,
            "cancelAtPeriodEnd": false,
            "scheduledCancelDate": 1793836800,
            "plan": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "planId": {
          "type": "integer",
          "description": "ID of the billing plan to assign"
         },
         "startOn": {
          "type": "string",
          "description": "Subscription start day. Defaults to now. A day, YYYY-MM-DD, in the school's zone. A Unix timestamp is also accepted and re-anchored to school midnight of the day it falls on there.",
          "format": "date"
         },
         "endOn": {
          "type": "string",
          "description": "Subscription end day. Optional (null = no end). A day, YYYY-MM-DD, in the school's zone. A Unix timestamp is also accepted and re-anchored to school midnight of the day it falls on there.",
          "format": "date"
         },
         "discount": {
          "type": "number",
          "description": "Discount value (percentage 0-100, or fixed CENTS when discountType is 1, for example 1500 for $15.00). Optional."
         },
         "discountType": {
          "type": "integer",
          "description": "0 = percentage (10 = 10% off), 1 = fixed amount in cents (1500 = $15.00 off; 15 is fifteen cents).",
          "enum": [
           0,
           1
          ]
         },
         "paymentMethod": {
          "type": "string",
          "description": "Determines whether the plan bills through a gateway or locally. The offline keys are stored as v1's words.",
          "enum": [
           "cash",
           "cheque",
           "credit_card_offline",
           "direct_debit_offline",
           "standing_order_offline",
           "credit_card_stripe",
           "direct_debit_gocardless"
          ]
         },
         "paymentMethodId": {
          "type": "string",
          "description": "The stored Stripe card (pm_...) the plan is charged against; one of the billing student's cards (GET /students/:studentId/payment-methods), else refused. Omitted, the customer's default card. The subscription keeps this card when the default changes later, and every charge the assignment makes (first period, pass pack, setup fee) goes on it."
         },
         "paymentRouting": {
          "type": "string",
          "description": "Who pays: 'self' = the student, 'family' = the billing-responsible family member. Default self.",
          "enum": [
           "self",
           "family"
          ]
         },
         "billingAnchorDay": {
          "type": "integer",
          "description": "A billing day, 1 to 28, on a monthly or yearly plan: every payment after the first falls on it (Stripe billing_cycle_anchor, the GoCardless debit's day). Omit for anniversary billing from the start date. Refused on a weekly plan."
         },
         "prorateFirst": {
          "type": "boolean",
          "description": "With a billing day: charge the first, partial period pro rata (the days from the first charge to the billing day, over that period; default true) or at the full price now (false). A card plan starting later can only be pro rata. The preview (?preview=true) answers `schedule`: the first payment, each payment after it, and the same in plain language."
         },
         "automaticRecording": {
          "type": "boolean",
          "description": "Automatic Transaction Recording, for a recurring plan with an offline paymentMethod: each payment is recorded as paid on the day it falls due, under the chosen method, with no receipt. Default false. Ignored for a gateway method (Stripe and GoCardless record their own payments) and for a plan that is not recurring."
         },
         "emailReceipt": {
          "type": "boolean",
          "description": "Whether the plan emails receipts. With it on, a receipt follows each payment a Stripe or GoCardless subscription collects (a recurring plan's first invoice and each renewal), a pay-as-you-go session charged to a card, and a card charge the assignment takes on its own for a pass pack, a one-off plan or a setup fee. A pro rata first period, a backdated plan's catch-up charge, a payment collected by a retry and a Direct Debit taken on its own send none either way. Default true when left out. An offline plan sends no receipts whatever this says."
         },
         "backdate": {
          "type": "object",
          "description": "A recurring plan whose startOn is a past day: what already happened, so only what is owed is taken. { firstPayment: \"taken\" | \"charge\" | \"owing\", paidBy?: offline method key (cash, cheque, credit_card_offline, direct_debit_offline, standing_order_offline), missed?: \"charge\" | \"paid\" | \"request\" | \"owing\" }. firstPayment is the first period from the start day; missed answers every period that began since and before today. taken and paid are recorded as paid on each period's first day (paidBy says how, required on a Stripe or GoCardless plan; an offline plan uses its own method). charge (Stripe, GoCardless) takes them now in one charge before the plan is created. request (Stripe, GoCardless) sends one invoice, a line a period. owing (offline) leaves them owing on the plan card. A Stripe or GoCardless plan's own billing starts at the next payment due. An offline plan with no backdate records the first payment and leaves the rest owing; a Stripe or GoCardless plan must say (400 BACKDATE_CHOICE_INVALID). The preview (?preview=true) answers schedule.backdated: the periods and the same in plain language."
         },
         "oneOffAmount": {
          "type": "integer",
          "description": "One-off amount in CENTS (setup fee or manual first payment). Creates a transaction when provided."
         }
        },
        "required": [
         "planId",
         "paymentMethod"
        ]
       },
       "example": {
        "planId": 1,
        "paymentMethod": "cash"
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}": {
   "get": {
    "operationId": "billing_getSubscription",
    "summary": "getSubscription",
    "description": "Get detailed subscription info including plan data, gateway state, and cancel-at-period-end flag.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.Subscription"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "planId": 1,
          "studentId": 1,
          "familyId": 1,
          "shopOrderId": 1,
          "externalId": "string",
          "type": "string",
          "status": "draft",
          "gatewayStatus": "string",
          "mandateStatus": "string",
          "nextPaymentOn": 1,
          "overdueAmountCents": 1,
          "discount": 1,
          "discountType": 0,
          "automaticTxns": false,
          "emailReceipt": false,
          "passesRemaining": 1,
          "startOn": 1793836800,
          "endOn": 1793836800,
          "pausedOn": 1793836800,
          "cancelledOn": 1793836800,
          "cancelAtPeriodEnd": false,
          "scheduledCancelDate": 1793836800,
          "plan": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "billing_updateSubscription",
    "summary": "updateSubscription",
    "description": "Update subscription fields (discount, discountType, endOn). Discount changes propagate to the payment gateway BEFORE the local row is written: Stripe swaps the subscription coupon, GoCardless cancels and recreates the subscription at the new effective amount (its externalId changes). If the gateway call fails the edit fails and nothing changes locally. An end day goes to the gateway first too. Moving an end day later, or removing it, is refused with 409 PLAN_COLLISION when the plan would then run at the same time as another plan the member holds on the same style. A discount change starts with the member's next period. Periods already begun keep the price they had. A pass pack or one-off plan is paid for once, when it is assigned, so a change to its discount is refused with 409 DISCOUNT_NOT_CHANGEABLE and nothing is changed.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.Subscription"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "planId": 1,
            "studentId": 1,
            "familyId": 1,
            "shopOrderId": 1,
            "externalId": "string",
            "type": "string",
            "status": "draft",
            "gatewayStatus": "string",
            "mandateStatus": "string",
            "nextPaymentOn": 1,
            "overdueAmountCents": 1,
            "discount": 1,
            "discountType": 0,
            "automaticTxns": false,
            "emailReceipt": false,
            "passesRemaining": 1,
            "startOn": 1793836800,
            "endOn": 1793836800,
            "pausedOn": 1793836800,
            "cancelledOn": 1793836800,
            "cancelAtPeriodEnd": false,
            "scheduledCancelDate": 1793836800,
            "plan": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "planId": 1,
            "studentId": 1,
            "familyId": 1,
            "shopOrderId": 1,
            "externalId": "string",
            "type": "string",
            "status": "draft",
            "gatewayStatus": "string",
            "mandateStatus": "string",
            "nextPaymentOn": 1,
            "overdueAmountCents": 1,
            "discount": 1,
            "discountType": 0,
            "automaticTxns": false,
            "emailReceipt": false,
            "passesRemaining": 1,
            "startOn": 1793836800,
            "endOn": 1793836800,
            "pausedOn": 1793836800,
            "cancelledOn": 1793836800,
            "cancelAtPeriodEnd": false,
            "scheduledCancelDate": 1793836800,
            "plan": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, DISCOUNT_NOT_CHANGEABLE, PLAN_COLLISION",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "DISCOUNT_NOT_CHANGEABLE",
     "PLAN_COLLISION",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "discount": {
          "type": "number",
          "description": "New discount value (percentage 0-100, or fixed CENTS when discountType is 1, for example 1500 for $15.00)"
         },
         "discountType": {
          "type": "integer",
          "description": "0 = percentage (10 = 10% off), 1 = fixed amount in cents (1500 = $15.00 off; 15 is fifteen cents).",
          "enum": [
           0,
           1
          ]
         },
         "endOn": {
          "type": "string",
          "description": "New end day (null to remove). A day, YYYY-MM-DD, in the school's zone. A Unix timestamp is also accepted and re-anchored to school midnight of the day it falls on there.",
          "format": "date"
         },
         "automaticRecording": {
          "type": "boolean",
          "description": "Turn Automatic Transaction Recording on or off for an offline recurring plan. Turned on, the nightly job records each payment that falls due from then on. Refused with 400 GATEWAY_UNSUPPORTED_OPTION on a Stripe or GoCardless plan."
         },
         "emailReceipt": {
          "type": "boolean",
          "description": "Turn receipts on or off for a Stripe or GoCardless plan: payments collected from then on are, or are not, followed by an emailed receipt. Refused with 400 GATEWAY_UNSUPPORTED_OPTION on an offline plan, which sends none."
         }
        }
       },
       "example": {
        "discount": 1,
        "discountType": 0,
        "endOn": "2026-11-05",
        "automaticRecording": false,
        "emailReceipt": false
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "billing_cancelSubscription",
    "summary": "cancelSubscription",
    "description": "Cancel a subscription. Three modes: immediate (default), atPeriodEnd (end of billing cycle), or cancelAt (specific future date). Cannot combine atPeriodEnd and cancelAt. A pass pack, a one-time plan or a pay-as-you-go plan has no billing period, so atPeriodEnd is refused for one (400); cancel it now or with cancelAt. Requires ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "atPeriodEnd": {
          "type": "boolean",
          "description": "If true, cancel at end of current billing period instead of immediately. Refused for a pass pack, a one-time plan or a pay-as-you-go plan, which have no billing period. Default: false."
         },
         "cancelAt": {
          "type": "string",
          "description": "Cancel on a specific future day (e.g. 1 month notice). Must be after today. Cannot be combined with atPeriodEnd. A day, YYYY-MM-DD, in the school's zone. A Unix timestamp is also accepted and re-anchored to school midnight of the day it falls on there.",
          "format": "date"
         }
        }
       },
       "example": {
        "atPeriodEnd": false,
        "cancelAt": "2026-11-05"
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/pause": {
   "post": {
    "operationId": "billing_pauseSubscription",
    "summary": "pauseSubscription",
    "description": "Pause a subscription. For Stripe, uses pause_collection. For GoCardless, uses adapter pause. For local, sets pausedOn timestamp. A body that cannot be read (an unknown field, a date that is not a day, a day not after today) is refused with 400 and nothing is paused. The preview and the answer carry scheduledResumeOn: the resume day, or null for none. Only a plan that bills on a schedule can be paused: a pass pack or a one-time plan is refused with 409 PLAN_NOT_PAUSABLE, in the preview too.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, PLAN_NOT_PAUSABLE",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PLAN_NOT_PAUSABLE",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "scheduledResumeOn": {
          "type": "string",
          "description": "Optional. The day the plan resumes by itself, YYYY-MM-DD in the school's zone, after today. Leave out to pause until someone resumes it.",
          "format": "date"
         }
        }
       },
       "example": {
        "scheduledResumeOn": "2026-11-05"
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/check-payment": {
   "post": {
    "operationId": "billing_checkPlanPayment",
    "summary": "checkPlanPayment",
    "description": "Check a plan whose status is confirming_payment: the gateway did not answer for the charge its assignment made. Asks the gateway what happened. outcome 'finished' = the payment was there and the plan is set up; 'waiting' = no answer yet, or the gateway could not be asked; 'cleared' = the gateway holds nothing for it half an hour on, so the plan was removed and can be assigned again; 'not_waiting' = the plan is not waiting on a payment. When a finished plan clashes with another plan the member holds, the answer also carries `clash` (both plans' names) and the message says so: tell the person, who cancels one of them. It never takes a payment the gateway does not already hold. The nightly reconciliation runs the same check.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/resume": {
   "post": {
    "operationId": "billing_resumeSubscription",
    "summary": "resumeSubscription",
    "description": "Resume a paused subscription. Clears pausedOn and sets resumedOn timestamp. Resumes gateway-side subscription if applicable. A card or Direct Debit plan the migration marked (paused before the school moved from the old system, which paused by cancelling: retired_external_id set) is given a new subscription on the payer's saved card or mandate, with its discount, tax and end date; the first payment is taken on the plan's stored next payment date when that is still ahead, else at once. Refused with 409 NO_GATEWAY_SUBSCRIPTION when the payer has no saved card or no active mandate, or when the card needs its owner to approve the payment; refused with 409 GATEWAY_API_ERROR when the card is declined. Nothing is left at the gateway on a refusal and the plan stays paused. A gateway plan with no subscription and no such marker is refused with 409 NO_GATEWAY_SUBSCRIPTION and listed for review (gateway_link_missing); it is never rebuilt. The preview refuses the same way, and for a rebuilt plan carries wouldBecome.restart { payerName, chargesNow, firstChargeAt }. A student who is a lead or inactive, on a paid plan that this makes charge again, becomes an active student in the same write; the preview says so in wouldBecome.becomesActive { studentId, from, note } (null otherwise).",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/schedule-resume": {
   "post": {
    "operationId": "billing_scheduleSubscriptionResume",
    "summary": "scheduleSubscriptionResume",
    "description": "Set, move or clear the date an already-paused subscription resumes on. null clears the schedule. Stripe gets the date natively (pause_collection.resumes_at); every gateway records one pending resume action that the nightly worker fires. A student who is a lead or inactive, on a paid plan that this makes charge again, becomes an active student in the same write; the preview says so in wouldBecome.becomesActive { studentId, from, note } (null otherwise).",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "scheduledResumeOn": {
          "type": "string",
          "description": "The day the plan resumes, after today, or null to clear. A day, YYYY-MM-DD, in the school's zone. A Unix timestamp is also accepted and re-anchored to school midnight of the day it falls on there.",
          "format": "date"
         }
        },
        "required": [
         "scheduledResumeOn"
        ]
       },
       "example": {
        "scheduledResumeOn": "2026-11-05"
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/write-off": {
   "post": {
    "operationId": "billing_writeOffSubscription",
    "summary": "writeOffSubscription",
    "description": "Write off a balance owed on a plan. Records a written-off ledger row for the amount (never counted as income) so the plan stops reading overdue. Packs default to the balance on the pack; recurring plans must say the amount. Requires ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "amountCents": {
          "type": "integer",
          "description": "Amount to write off, in cents. Required for recurring plans; defaults to the pack balance otherwise."
         },
         "reason": {
          "type": "string",
          "description": "Why the balance is forgiven (up to 200 characters); kept on the written-off ledger row's description."
         }
        }
       },
       "example": {
        "amountCents": 1,
        "reason": "string"
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/rescind-cancel": {
   "post": {
    "operationId": "billing_rescindCancel",
    "summary": "rescindCancel",
    "description": "Rescind a pending deferred cancellation (atPeriodEnd or cancelAt). Clears the cancel flag on both the local deferred action row and the gateway (Stripe cancel_at / cancel_at_period_end). A student who is a lead or inactive, on a paid plan that this makes charge again, becomes an active student in the same write; the preview says so in wouldBecome.becomesActive { studentId, from, note } (null otherwise).",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/undo-move": {
   "post": {
    "operationId": "billing_undoPlanMove",
    "summary": "undoPlanMove",
    "description": "Undo a move to another plan that is booked for a day: a pass, one-off or pay as you go plan set to move with migratePlanSubscribers and timing on_date. The plan stays on the plan it is on, with its passes and expiry date as they are. Refused when no move is booked. The plan's `pendingMove` in the student's billing says whether one is.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/sync": {
   "post": {
    "operationId": "billing_syncSubscription",
    "summary": "syncSubscription",
    "description": "Force re-sync a single subscription from its payment gateway. Fetches current state and patches local record. ?preview=true names the plan and gateway it would read without calling the gateway, so it cannot say what will change.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/invoices": {
   "get": {
    "operationId": "billing_listInvoices",
    "summary": "listInvoices",
    "description": "List invoices (Stripe-only). Uses cursor-based pagination. Filter by status, studentId, and date range.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.Invoice"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/CursorMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": "string",
           "status": "draft",
           "amountDue": 1,
           "amountPaid": 1,
           "hostedInvoiceUrl": "string",
           "invoicePdf": "string",
           "dueDate": 1793836800,
           "createdAt": 1793836800
          }
         ],
         "meta": {
          "count": 1,
          "total": 1,
          "nextCursor": null
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "draft",
        "open",
        "paid",
        "void",
        "uncollectible"
       ]
      },
      "description": "Filter by invoice status"
     },
     {
      "name": "studentId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter invoices for a specific student"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Only invoices created on or after this date (Unix timestamp in seconds). Also accepted as dateFrom."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Only invoices created on or before this date (Unix timestamp in seconds). Also accepted as dateTo."
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Cursor for next page (Stripe invoice ID from previous response)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 25
      },
      "description": "Items per page (max 100). Default: 25"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "billing_createInvoice",
    "summary": "createInvoice",
    "description": "Create a new draft invoice (Stripe-only). Each item becomes a Stripe InvoiceItem. Supports ?preview=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.Invoice"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": "string",
            "status": "draft",
            "amountDue": 1,
            "amountPaid": 1,
            "hostedInvoiceUrl": "string",
            "invoicePdf": "string",
            "dueDate": 1793836800,
            "createdAt": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": "string",
            "status": "draft",
            "amountDue": 1,
            "amountPaid": 1,
            "hostedInvoiceUrl": "string",
            "invoicePdf": "string",
            "dueDate": 1793836800,
            "createdAt": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer",
          "description": "Student to invoice"
         },
         "items": {
          "type": "array",
          "description": "Line items: { description, amount (cents), quantity }",
          "items": {}
         },
         "daysUntilDue": {
          "type": "integer",
          "description": "Days until due. Default: 14. Max: 365.",
          "default": 14
         },
         "memo": {
          "type": "string",
          "description": "Optional memo/note on the invoice"
         }
        },
        "required": [
         "studentId",
         "items"
        ]
       },
       "example": {
        "studentId": 1,
        "items": []
       }
      }
     }
    }
   }
  },
  "/v1/billing/invoices/{id}": {
   "get": {
    "operationId": "billing_getInvoice",
    "summary": "getInvoice",
    "description": "Get a single invoice by Stripe ID.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.Invoice"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": "string",
          "status": "draft",
          "amountDue": 1,
          "amountPaid": 1,
          "hostedInvoiceUrl": "string",
          "invoicePdf": "string",
          "dueDate": 1793836800,
          "createdAt": 1793836800
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/invoices/{id}/finalize": {
   "post": {
    "operationId": "billing_finalizeInvoice",
    "summary": "finalizeInvoice",
    "description": "Finalize a draft invoice (draft to open). Makes it payable. Requires ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.Invoice"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": "string",
            "status": "draft",
            "amountDue": 1,
            "amountPaid": 1,
            "hostedInvoiceUrl": "string",
            "invoicePdf": "string",
            "dueDate": 1793836800,
            "createdAt": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": "string",
            "status": "draft",
            "amountDue": 1,
            "amountPaid": 1,
            "hostedInvoiceUrl": "string",
            "invoicePdf": "string",
            "dueDate": 1793836800,
            "createdAt": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/invoices/{id}/void": {
   "post": {
    "operationId": "billing_voidInvoice",
    "summary": "voidInvoice",
    "description": "Void an invoice. Only draft or open invoices can be voided. Requires ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/invoices/{id}/send": {
   "post": {
    "operationId": "billing_sendInvoice",
    "summary": "sendInvoice",
    "description": "Send (or re-send) an invoice email to the customer. Only works on open invoices.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.Invoice"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": "string",
            "status": "draft",
            "amountDue": 1,
            "amountPaid": 1,
            "hostedInvoiceUrl": "string",
            "invoicePdf": "string",
            "dueDate": 1793836800,
            "createdAt": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": "string",
            "status": "draft",
            "amountDue": 1,
            "amountPaid": 1,
            "hostedInvoiceUrl": "string",
            "invoicePdf": "string",
            "dueDate": 1793836800,
            "createdAt": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/invoices/{id}/pdf": {
   "get": {
    "operationId": "billing_getInvoicePdf",
    "summary": "getInvoicePdf",
    "description": "Get the PDF download URL for an invoice.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/payments": {
   "get": {
    "operationId": "billing_listStudentPayments",
    "summary": "listStudentPayments",
    "description": "List payment history for a student. Offset-paginated.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.Transaction"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "studentId": 1,
           "subscriptionId": 1,
           "paymentMethod": "string",
           "amount": 1,
           "description": "string",
           "taxAmount": 1,
           "status": "pending",
           "automatic": false,
           "gateway": "stripe",
           "createdOn": 1793836800,
           "failedOn": 1793836800,
           "retriedOn": 1793836800,
           "refundedOn": 1793836800
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Sort field. Default: -createdOn Allowed fields: createdOn, amount"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 20
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "billing_recordPayment",
    "summary": "recordPayment",
    "description": "Record a payment. Offline methods are v1's list; Stripe or GoCardless charges through the gateway. A gateway charge of the same amount for the same member is not sent while an earlier one is unanswered: the earlier one is checked first. If it went through, the answer is that payment with `alreadyTaken: true` and nothing new is charged; if it is not known yet the call is refused with ONE_OFF_BEING_CHECKED (show the person the message; do not send it again). Supports ?preview=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, ONE_OFF_BEING_CHECKED, GATEWAY_API_ERROR",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "ONE_OFF_BEING_CHECKED",
     "GATEWAY_API_ERROR",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "amount": {
          "type": "integer",
          "description": "The money received (or charged), in cents, tax included (must be positive). Tax is worked out from inside it on every school, never added on top."
         },
         "paymentMethod": {
          "type": "string",
          "description": "Payment method: a gateway, or one of the offline methods",
          "enum": [
           "Stripe",
           "GoCardless",
           "Cash",
           "Cheque",
           "Credit Card",
           "Direct Debit",
           "Standing Order"
          ]
         },
         "description": {
          "type": "string",
          "description": "Description of the payment"
         },
         "subscriptionId": {
          "type": "integer",
          "description": "Optional subscription this payment applies to"
         },
         "taxAmount": {
          "type": "integer",
          "description": "Tax amount in cents. Default: 0",
          "default": 0
         },
         "paymentMethodId": {
          "type": "string",
          "description": "Stripe only: the stored card (pm_...) to charge, from GET /students/:id/payment-methods. Omit to charge the default card."
         }
        },
        "required": [
         "amount",
         "paymentMethod",
         "description"
        ]
       },
       "example": {
        "amount": 1,
        "paymentMethod": "Stripe",
        "description": "string"
       }
      }
     }
    }
   }
  },
  "/v1/billing/transactions": {
   "get": {
    "operationId": "billing_listTransactions",
    "summary": "listTransactions",
    "description": "List school-wide transactions with optional filters. Offset-paginated.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.Transaction"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "studentId": 1,
           "subscriptionId": 1,
           "paymentMethod": "string",
           "amount": 1,
           "description": "string",
           "taxAmount": 1,
           "status": "pending",
           "automatic": false,
           "gateway": "stripe",
           "createdOn": 1793836800,
           "failedOn": 1793836800,
           "retriedOn": 1793836800,
           "refundedOn": 1793836800
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by student"
     },
     {
      "name": "subscriptionId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by subscription"
     },
     {
      "name": "paymentMethod",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by payment method"
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "pending",
        "submitted",
        "successful",
        "failed",
        "retrying",
        "cancelled"
       ]
      },
      "description": "Filter by semantic status"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter from date (Unix timestamp in seconds). Also accepted as dateFrom."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter to date (Unix timestamp in seconds). Also accepted as dateTo."
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string",
       "default": "-createdOn"
      },
      "description": "Allowed fields: createdOn, amount"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 20
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/transactions/{id}/retry": {
   "post": {
    "operationId": "billing_retryTransaction",
    "summary": "retryTransaction",
    "description": "Retry a failed gateway transaction. Initiates a new payment attempt through the original gateway. ?preview=true is a dry run: the same refusals, then the amount and whether account credit, the open Stripe invoice, a card or a Direct Debit would pay it. The gateway is not called.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/transactions/{id}/settle": {
   "post": {
    "operationId": "billing_settleCharge",
    "summary": "settleCharge",
    "description": "Mark an UNPAID charge as collected another way (cash, cheque, a card on the school's own terminal, a direct debit or standing order collected elsewhere). Updates that charge in place rather than inserting a second transaction, so the debt is cleared instead of double-counted. Only pending or failed charges can be settled; already-paid, refunded and written-off charges are rejected. A failed card renewal or Direct Debit is stopped at the payment gateway first, so it is not collected a second time: the Stripe invoice is marked paid outside Stripe, and a Direct Debit not yet with the bank is cancelled. The settle is refused, and nothing changes, when the gateway has already collected the charge, when a Direct Debit is with the bank or about to be retried by GoCardless, or when the gateway cannot be reached. A pay-as-you-go session still being checked with Stripe is refused with 409 until the check settles it. The dry run makes the same checks. Account credit an earlier Retry took for the charge and never finished with is handed back; the dry run shows it as creditReturnedCents.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "paymentMethod": {
          "type": "string",
          "description": "How the money was actually collected. Gateway methods are deliberately excluded: to charge a card, use the retry operation.",
          "enum": [
           "Cash",
           "Cheque",
           "Credit Card",
           "Direct Debit",
           "Standing Order"
          ]
         }
        },
        "required": [
         "paymentMethod"
        ]
       },
       "example": {
        "paymentMethod": "Cash"
       }
      }
     }
    }
   }
  },
  "/v1/billing/transactions/{id}/cancel": {
   "post": {
    "operationId": "billing_cancelCharge",
    "summary": "cancelCharge",
    "description": "Write off an UNPAID charge the school has decided not to collect. Sets the charge to cancelled (it stays in the ledger as a record of the decision) rather than deleting it. Only pending or failed charges can be cancelled. A failed card renewal or Direct Debit is stopped at the payment gateway first: the Stripe invoice is voided, and a Direct Debit not yet with the bank is cancelled. The write-off is refused, and nothing changes, when the gateway has already collected the charge, when a Direct Debit is with the bank or about to be retried by GoCardless, or when the gateway cannot be reached. A pay-as-you-go session still being checked with Stripe is refused with 409 until the check settles it. The dry run makes the same checks. Account credit an earlier Retry took for the charge and never finished with is handed back; the dry run shows it as creditReturnedCents.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/transactions/{transactionId}/check-payment": {
   "post": {
    "operationId": "billing_checkPaygSessionPayment",
    "summary": "checkPaygSessionPayment",
    "description": "Check a pay-as-you-go session charge that is still being checked with Stripe (checking: true on the member's payments list): Stripe did not answer when the session's card was charged. Asks Stripe what happened. outcome 'settled' = Stripe has the payment and the session is no longer owed; 'refused' = the card was declined, the session is still owed and its charge can be retried; 'never_taken' = Stripe holds nothing half an hour on, so the card was not charged and the session stays owed; 'waiting' = no answer yet, or Stripe could not be asked; 'not_waiting' = the charge is not being checked. state is where the row stands after the check: paid, failed, owed, checking, cancelled or gone. description is the row's description after the check (null when the row is gone). While a session is being checked, settle and cancel refuse it (409). It never takes a payment. The nightly reconciliation runs the same check.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "transactionId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/billing/transactions/{id}/receipt": {
   "get": {
    "operationId": "billing_getTransactionReceipt",
    "summary": "getTransactionReceipt",
    "description": "Get a formatted receipt for a transaction, including line items, school info, and payment method details.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.TransactionReceipt"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "date": 1,
          "amount": 1,
          "currency": "string",
          "description": "string",
          "paymentMethod": "string",
          "studentName": "string",
          "studentEmail": "string",
          "receiptName": "string",
          "receiptEmail": "string",
          "receiptPaidFor": "string",
          "schoolName": "string",
          "receiptUrl": "string",
          "planName": "string",
          "cardBrand": "string",
          "cardLast4": "string",
          "lineItems": [],
          "familyName": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/transactions/{id}/receipt/email": {
   "post": {
    "operationId": "billing_sendReceiptEmail",
    "summary": "sendReceiptEmail",
    "description": "Send a receipt email for a transaction (delivered immediately via the designed receipt template). Optionally override the recipient email address.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "email": {
          "type": "string",
          "description": "Override recipient email. If omitted it goes to the person who paid: the family's billing member for a plan the family pays, else the student. Refused when that person has no address",
          "format": "email"
         }
        }
       },
       "example": {
        "email": "jo@example.com"
       }
      }
     }
    }
   }
  },
  "/v1/billing/refund": {
   "post": {
    "operationId": "billing_processRefund",
    "summary": "processRefund",
    "description": "Process a refund against an existing transaction. A Stripe or GoCardless payment is refunded at the gateway. If the gateway refuses, nothing is recorded and its reason is given. If the gateway does not answer, the answer is 409 GATEWAY_REFUND_UNCONFIRMED: the refund is recorded as pending and settles by itself once the gateway confirms it or shows it was never made; do not send another refund for it (sending the same refund again is safe: it is the same refund, never a second one), and tell the person it is not yet known. 409 REFUND_ALREADY_SENT means a refund of that amount on that payment was sent earlier without an answer and has since gone through: nothing was refunded now. Tell the person. Only if they say another refund of the same amount is meant, send it again with newRefund: true. The answer's gatewayRefund says what happened: 'pushed' (money moved at the gateway), 'not_applicable' (an offline payment), or 'no_reference' (an old payment with no gateway id: the refund is recorded but no money moved, and the school must refund it in its Stripe or GoCardless dashboard; tell the person). The preview carries the same field. Supports ?preview=true and ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, GATEWAY_REFUND_UNCONFIRMED, REFUND_ALREADY_SENT, ALREADY_REFUNDED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "GATEWAY_REFUND_UNCONFIRMED",
     "REFUND_ALREADY_SENT",
     "ALREADY_REFUNDED",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "transactionId": {
          "type": "integer",
          "description": "The transaction ID to refund"
         },
         "amount": {
          "type": "integer",
          "description": "Partial refund amount in cents (omit for full refund)"
         },
         "reason": {
          "type": "string",
          "description": "Reason for the refund"
         },
         "newRefund": {
          "type": "boolean",
          "description": "Only after a 409 REFUND_ALREADY_SENT, and only when the person has said another refund of the same amount is meant: true sends it as a new refund. Leave it out otherwise."
         }
        },
        "required": [
         "transactionId"
        ]
       },
       "example": {
        "transactionId": 1
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/add-passes": {
   "post": {
    "operationId": "billing_addPasses",
    "summary": "addPasses",
    "description": "Add passes to a pass-based subscription. Returns new passesRemaining count and whether the subscription was reactivated (had 0 passes).",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "count": {
          "type": "integer",
          "description": "Number of passes to add",
          "minimum": 1
         },
         "reason": {
          "type": "string",
          "description": "Optional reason for the adjustment"
         }
        },
        "required": [
         "count"
        ]
       },
       "example": {
        "count": 1
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/deduct-passes": {
   "post": {
    "operationId": "billing_deductPasses",
    "summary": "deductPasses",
    "description": "Deduct passes from a pass-based subscription. Throws INSUFFICIENT_PASSES if the deduction would go below 0.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "count": {
          "type": "integer",
          "description": "Number of passes to deduct",
          "minimum": 1
         },
         "reason": {
          "type": "string",
          "description": "Optional reason for the adjustment"
         }
        },
        "required": [
         "count"
        ]
       },
       "example": {
        "count": 1
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/payment-methods": {
   "get": {
    "operationId": "billing_listPaymentMethods",
    "summary": "listPaymentMethods",
    "description": "List payment methods for a student. For Stripe schools: returns cards and SEPA debit methods with default flag and expiry status. For GoCardless schools: returns the student's bank mandate with bank account details. Returns [] if student has no gateway reference. Related actions: setupPaymentMethod, createBillingPortal.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.PaymentMethod"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": "string",
           "gateway": "stripe",
           "type": "card",
           "isDefault": false,
           "details": {
            "brand": "string",
            "last4": "string",
            "expMonth": 1,
            "expYear": 1,
            "bankName": "string",
            "accountNumberEnding": "string",
            "scheme": "string"
           },
           "status": "active",
           "mandateState": "string",
           "nextPossibleChargeDate": "string",
           "createdAt": 1793836800
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/payment-methods/setup": {
   "post": {
    "operationId": "billing_setupPaymentMethod",
    "summary": "setupPaymentMethod",
    "description": "Start a payment method setup session. For Stripe: creates a Checkout Session in setup mode and returns a hosted URL. For GoCardless: creates a Billing Request Flow and returns an authorisation URL. The student is redirected to enter card/bank details, then returned to returnUrl.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.SetupSession"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "url": "string",
          "gateway": "stripe"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "returnUrl": {
          "type": "string",
          "description": "URL to redirect the student back to after setup completes or is cancelled",
          "format": "url"
         }
        },
        "required": [
         "returnUrl"
        ]
       },
       "example": {
        "returnUrl": "https://example.com"
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/payment-requests": {
   "post": {
    "operationId": "billing_sendPaymentRequest",
    "summary": "sendPaymentRequest",
    "description": "Send the member a link, by email or SMS, to add or update their card (Stripe) or Direct Debit (GoCardless) themselves. The link opens a page with the school's name; its button opens a fresh Stripe or GoCardless setup page, so card and bank details are only typed there. A saved Stripe card becomes the member's default. The link works for 7 days; a new one retires the member's unfinished earlier link for the same gateway. Fails when the member has no address for the chosen channel, or the message could not be sent.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.PaymentRequest"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "gateway": "stripe",
            "channel": "email",
            "sentOn": 1793836800,
            "openedOn": 1793836800,
            "completedOn": 1793836800,
            "expiresOn": 1793836800,
            "status": "sent"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "gateway": "stripe",
            "channel": "email",
            "sentOn": 1793836800,
            "openedOn": 1793836800,
            "completedOn": 1793836800,
            "expiresOn": 1793836800,
            "status": "sent"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "channel": {
          "type": "string",
          "enum": [
           "email",
           "sms"
          ]
         },
         "gateway": {
          "type": "string",
          "description": "Which gateway the details are for",
          "enum": [
           "stripe",
           "gocardless"
          ]
         },
         "message": {
          "type": "string",
          "description": "Optional note shown above the link (max 500 chars)"
         }
        },
        "required": [
         "channel",
         "gateway"
        ]
       },
       "example": {
        "channel": "email",
        "gateway": "stripe"
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/payment-requests/link": {
   "post": {
    "operationId": "billing_getPaymentRequestLink",
    "summary": "getPaymentRequestLink",
    "description": "The member's payment-details link to show as a QR code or copy, without sending it: the same page an emailed link opens, whose button opens a fresh Stripe or GoCardless setup page. Reuses the member's live shown link while it has at least 6 of its 7 days left, otherwise makes a new one. Never retires, and is never retired by, a link sent by email or SMS.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.PaymentRequestLink"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "gateway": "stripe",
          "channel": "link",
          "sentOn": 1793836800,
          "openedOn": 1793836800,
          "completedOn": 1793836800,
          "expiresOn": 1793836800,
          "status": "sent",
          "url": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "gateway": {
          "type": "string",
          "description": "Which gateway the details are for",
          "enum": [
           "stripe",
           "gocardless"
          ]
         }
        },
        "required": [
         "gateway"
        ]
       },
       "example": {
        "gateway": "stripe"
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/payment-requests/latest": {
   "get": {
    "operationId": "billing_getPaymentRequest",
    "summary": "getPaymentRequest",
    "description": "The member's latest live payment-details link sent by email or SMS, or null: gateway, channel, sent / opened / completed / expired.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.PaymentRequest"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "gateway": "stripe",
          "channel": "email",
          "sentOn": 1793836800,
          "openedOn": 1793836800,
          "completedOn": 1793836800,
          "expiresOn": 1793836800,
          "status": "sent"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/payment-methods/setup-intent": {
   "post": {
    "operationId": "billing_createSetupIntent",
    "summary": "createSetupIntent",
    "description": "Create a Stripe SetupIntent for inline card collection (embedded Elements). Returns a client secret for Stripe.js initialization. Stripe only: GoCardless mandates use the redirect flow via setupPaymentMethod.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.SetupIntent"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "clientSecret": "string",
          "publishableKey": "string",
          "stripeAccountId": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/payment-methods/{pmId}": {
   "delete": {
    "operationId": "billing_detachPaymentMethod",
    "summary": "detachPaymentMethod",
    "description": "Detach (remove) a payment method from a student. For Stripe: detaches the card/SEPA debit. For GoCardless: cancels the mandate. Throws PAYMENT_METHOD_IS_DEFAULT if the method is the default and the student has active subscriptions. Set a new default first. Requires ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "pmId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/payment-methods/{pmId}/default": {
   "post": {
    "operationId": "billing_setDefaultPaymentMethod",
    "summary": "setDefaultPaymentMethod",
    "description": "Set a payment method as the customer default for future invoices. The student's live Stripe plans move onto it too (each plan's own card pin is cleared so it charges the default), except a plan put on its own card with setSubscriptionPaymentMethod. Throws GATEWAY_API_ERROR if a plan could not be moved (safe to retry). Stripe only: GoCardless has one mandate per student which is always the default. Throws GATEWAY_UNSUPPORTED_OPTION for GoCardless schools.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "pmId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/subscriptions/{subId}/payment-method": {
   "get": {
    "operationId": "billing_getSubscriptionPaymentMethod",
    "summary": "getSubscriptionPaymentMethod",
    "description": "The card a Stripe subscription is charged against: { paymentMethodId } is its own card when one was picked or pinned, else null for the customer's default; { pinned } says whether a later default change leaves it. Read from Stripe.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.SubscriptionPaymentMethod"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "subscriptionId": 1,
          "paymentMethodId": "string",
          "pinned": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "billing_setSubscriptionPaymentMethod",
    "summary": "setSubscriptionPaymentMethod",
    "description": "Override the payment method for a specific Stripe subscription. This overrides the customer-level default for just this subscription, and it stays on this card when the default changes later. Stripe only. The card must be one of the student's stored Stripe cards.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "subId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "paymentMethodId": {
          "type": "string",
          "description": "Stripe payment method ID (pm_xxx)"
         }
        },
        "required": [
         "paymentMethodId"
        ]
       },
       "example": {
        "paymentMethodId": "string"
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/mandates": {
   "get": {
    "operationId": "billing_listMandates",
    "summary": "listMandates",
    "description": "List GoCardless mandates for a student. Returns richer mandate-specific info including mandateState and nextPossibleChargeDate. Returns [] for non-GoCardless schools or students without a mandate reference.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.PaymentMethod"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": "string",
           "gateway": "stripe",
           "type": "card",
           "isDefault": false,
           "details": {
            "brand": "string",
            "last4": "string",
            "expMonth": 1,
            "expYear": 1,
            "bankName": "string",
            "accountNumberEnding": "string",
            "scheme": "string"
           },
           "status": "active",
           "mandateState": "string",
           "nextPossibleChargeDate": "string",
           "createdAt": 1793836800
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/mandates/{mandateId}": {
   "delete": {
    "operationId": "billing_cancelMandate",
    "summary": "cancelMandate",
    "description": "Cancels the member's Direct Debit and ends every live GoCardless plan this member pays for (their own, and family plans they pay). A plan of theirs that another family member pays for is left running. GoCardless takes no more payments from their bank account, and the plans end today as the school's own cancel. ?preview=true returns { mandateId, plans: [{ subscriptionId, name, amount (cents), nextDebitOn }], kept: [{ subscriptionId, name, paidBy: { studentId, firstName } }] } and changes nothing: plans are the ones that end, kept the ones left running. ?confirm=true acts; a bare DELETE is refused. A cancel GoCardless refuses changes nothing. 409 GATEWAY_API_ERROR when GoCardless did not answer: nothing was changed, and the same call again checks and finishes. 409 MANDATE_CANCEL_UNFINISHED when GoCardless cancelled the direct debit and ending the plans here stopped part-way: the same call again finishes. 404 GATEWAY_CUSTOMER_NOT_FOUND when the mandate is not this member's. To pay by direct debit again the member sets up a new one.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, MANDATE_CANCEL_UNFINISHED, GATEWAY_API_ERROR",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "MANDATE_CANCEL_UNFINISHED",
     "GATEWAY_API_ERROR",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "mandateId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/billing-portal": {
   "post": {
    "operationId": "billing_createBillingPortal",
    "summary": "createBillingPortal",
    "description": "Create a Stripe Billing Portal session. Returns a URL to redirect the student to Stripe's hosted portal where they can manage payment methods, view invoices, and update billing info. Stripe only.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.PortalSession"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "url": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "returnUrl": {
          "type": "string",
          "description": "URL to redirect the student back to after exiting the portal",
          "format": "url"
         }
        },
        "required": [
         "returnUrl"
        ]
       },
       "example": {
        "returnUrl": "https://example.com"
       }
      }
     }
    }
   }
  },
  "/v1/billing/plans/{id}/update-price": {
   "post": {
    "operationId": "billing_updatePlanPrice",
    "summary": "updatePlanPrice",
    "description": "Change a plan's price for everyone on it. Stripe Prices are immutable, so a new Price object is created and the old one preserved in version history. ?preview=true returns the members per gateway; ?confirm=true sets the new price and starts the rollout as a queued billing job, returning { jobId, version, total } (jobId is null when nobody needs changing): poll GET /v1/billing/jobs/:jobId for each member's result. Months before the change keep the old price. A pass pack or one-off plan is paid for once, so those on the plan when its price changes keep the price they had and the new price is for those sold from then on. To keep some members on the old price, create a new plan and move the others with the plan migration instead. Card members booked to move onto this plan at their next payment are included and arrive at the new price; card members booked to move off it keep that move, so migrate_at_renewal skips them with a `note`.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.PriceUpdateResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "currentAmount": 1,
            "newAmount": 1,
            "cascade": "string",
            "affectedSubscriptions": {},
            "version": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "currentAmount": 1,
            "newAmount": 1,
            "cascade": "string",
            "affectedSubscriptions": {},
            "version": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "newAmount": {
          "type": "integer",
          "description": "New price amount in cents",
          "minimum": 1
         },
         "cascade": {
          "type": "string",
          "description": "When existing members move. migrate_now: Stripe moves now with proration; GoCardless and offline members from their next payment. migrate_at_renewal: Stripe at its next renewal (a subscription schedule); GoCardless and offline members from their next payment.",
          "enum": [
           "migrate_now",
           "migrate_at_renewal"
          ]
         }
        },
        "required": [
         "newAmount",
         "cascade"
        ]
       },
       "example": {
        "newAmount": 1,
        "cascade": "migrate_now"
       }
      }
     }
    }
   }
  },
  "/v1/billing/plans/{id}/versions": {
   "get": {
    "operationId": "billing_getPlanVersions",
    "summary": "getPlanVersions",
    "description": "Get price version history for a plan. Shows all price changes, cascade strategies used, and migration status.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.PlanPriceVersion"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "planId": 1,
           "previousAmount": 1,
           "newAmount": 1,
           "cascadeStrategy": "grandfather",
           "status": "migrating",
           "migratedCount": 1,
           "totalToMigrate": 1,
           "version": 1,
           "createdAt": 1793836800,
           "completedAt": 1793836800
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/plans/{id}/subscribers": {
   "get": {
    "operationId": "billing_listPlanSubscribers",
    "summary": "listPlanSubscribers",
    "description": "List all active subscribers on a plan with enriched per-student detail: student name, email, gateway, discounted amount, fixed-discount flag, style restrictions, transaction aggregates (total paid, last payment), and overdue status.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.PlanSubscriber"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "subscriptionId": 1,
           "studentId": 1,
           "studentName": "string",
           "email": "string",
           "gateway": "stripe",
           "type": "string",
           "externalId": "string",
           "discount": 1,
           "discountType": 1,
           "discountedAmountCents": 1,
           "hasFixedDiscount": false,
           "startOn": 1,
           "gatewayStatus": "string",
           "styleIds": [],
           "totalPaidCents": 1,
           "lastPaymentOn": 1,
           "lastPaymentStatus": "successful",
           "isOverdue": false
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/plans/{id}/history": {
   "get": {
    "operationId": "billing_getPlanHistory",
    "summary": "getPlanHistory",
    "description": "Audit history of a plan, newest first: created, edited (changed fields before and after), price changed, members migrated, archived. Each entry names who acted (an admin, an API key, MCP, Martialytics staff, Franchise HQ, or the system). Rows are kept about a year.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.AuditEntry"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "userId": 1,
           "source": "admin",
           "apiKeyId": 1,
           "impersonatorId": 1,
           "actorName": "string",
           "action": "string",
           "subjectType": "string",
           "subjectId": "string",
           "studentId": 1,
           "before": {},
           "after": {},
           "reason": "string",
           "createdOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Entries to return (1-500, default 100)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/history": {
   "get": {
    "operationId": "billing_getStudentBillingHistory",
    "summary": "getStudentBillingHistory",
    "description": "Audit history of a member's billing, newest first: plans assigned, changed, paused, resumed, cancelled; payments recorded and refunded; charges cancelled or written off; credit and balance adjustments; payment methods removed. Each entry names who acted and, where the action asked for one, the admin's reason. Rows are kept about a year.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.AuditEntry"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "userId": 1,
           "source": "admin",
           "apiKeyId": 1,
           "impersonatorId": 1,
           "actorName": "string",
           "action": "string",
           "subjectType": "string",
           "subjectId": "string",
           "studentId": 1,
           "before": {},
           "after": {},
           "reason": "string",
           "createdOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Entries to return (1-500, default 100)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/plans/{id}/migrate": {
   "post": {
    "operationId": "billing_migratePlanSubscribers",
    "summary": "migratePlanSubscribers",
    "description": "Migrate all active subscribers from one plan to another. Plans must be compatible types (both recurring, both passes, etc). Stripe: updates subscription item to new price. GoCardless: cancel old + create new sub. Local: re-links to target plan. A plan whose end date has passed is moved too and stays ended, with its end date unchanged: the preview lists those members in `warnings.endedPlans`, and each one's result carries a `note`. A pass, one-off or pay as you go plan has no billing cycle: it moves now (`immediate`) or on a day you pick (`on_date` with `effectiveDate`), never at `next_billing_cycle`. It stays the same plan record, so the passes a member has left move with them and the pack keeps its expiry date. A pass pack or one-off plan also keeps the price it was sold at: what it owes does not change with the plan. One still waiting on its payment is not moved: it is skipped (`skipped: true`, with a `note`) and nothing is changed for it. Until the day, the member's plan shows the move as `pendingMove`, and undoPlanMove cancels it. A card member moved at `next_billing_cycle` is booked at Stripe: their plan shows `pendingMove` (not undoable) until their next payment. Moving them again replaces that booking: the preview lists them in `warnings.bookedMoves`, and a member moved `immediate` has the booked move cancelled, said in their result's `note`. A member whose Stripe subscription holds a change Martialytics did not make is skipped (`skipped: true`, with a `note`) and nothing is changed for them. Supports ?preview=true and ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.QueuedOperation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "operationId": 1,
            "label": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "operationId": 1,
            "label": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "targetPlanId": {
          "type": "integer",
          "description": "Target plan ID to migrate subscribers to"
         },
         "timing": {
          "type": "string",
          "description": "When members move. immediate: now. next_billing_cycle: at each member's next payment (recurring plans only). on_date: on effectiveDate (pass, one-off and pay as you go plans only).",
          "enum": [
           "immediate",
           "next_billing_cycle",
           "on_date"
          ],
          "default": "immediate"
         },
         "effectiveDate": {
          "type": "string",
          "description": "The day of an on_date move, YYYY-MM-DD on the school's calendar. It must be after today. Sent only with timing on_date.",
          "format": "date"
         }
        },
        "required": [
         "targetPlanId"
        ]
       },
       "example": {
        "targetPlanId": 1
       }
      }
     }
    }
   }
  },
  "/v1/billing/overdue": {
   "get": {
    "operationId": "billing_getOverdueSubscriptions",
    "summary": "getOverdueSubscriptions",
    "description": "Detect overdue subscriptions using transaction-based aging. Compares expected payments (based on billing period) against actual successful transactions. Buckets into aging tiers: 7d, 14d, 30d, 60d, 90d+. Primarily targets local subscriptions; gateway subs with failed transactions are flagged separately.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.OverdueResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "buckets": [
           {
            "tier": "7d",
            "count": 1,
            "totalOwedCents": 1,
            "subscriptions": [
             {}
            ]
           }
          ],
          "totalOverdue": 1,
          "totalOwedCents": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "tier",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "7d",
        "14d",
        "30d",
        "60d",
        "90d+"
       ]
      },
      "description": "Filter by overdue aging tier"
     },
     {
      "name": "gateway",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "stripe",
        "gocardless",
        "local"
       ]
      },
      "description": "Filter by gateway type"
     },
     {
      "name": "planId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by billing plan ID"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/overdue/remind": {
   "post": {
    "operationId": "billing_sendOverdueReminder",
    "summary": "sendOverdueReminder",
    "description": "Send overdue payment reminder emails for specified subscriptions. One email per student, listing their selected overdue subscriptions with amounts, delivered immediately. `queued` in the response is the number of emails sent.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "subscriptionIds": {
          "type": "array",
          "description": "Subscription IDs to send reminders for (1 to 500 items)",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "subscriptionIds"
        ]
       },
       "example": {
        "subscriptionIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/billing/subscriptions/bulk/assign": {
   "post": {
    "operationId": "billing_bulkAssign",
    "summary": "bulkAssign",
    "description": "Assign one plan to many students. Each student's saved default card is charged where there is one; anyone without a card gets a smart invoice emailed; a student already on the plan is skipped and other plans stack. A pass pack can be held more than once: a student who already holds it is skipped unless named in buyAgainStudentIds. The dry run says who the run will reach and who is skipped, from the school's records; it asks no gateway, so whether each student is charged or emailed (or fails with no card and no email) is decided as the operation reaches them and shown in its rows.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "The selection (1 to 10,000)",
          "items": {
           "type": "integer"
          }
         },
         "planId": {
          "type": "integer"
         },
         "startOn": {
          "type": "string",
          "description": "Start day; omitted means now",
          "format": "date"
         },
         "discount": {
          "type": "number",
          "description": "Percentage 0-100, or fixed cents when discountType is 1"
         },
         "discountType": {
          "type": "integer",
          "enum": [
           0,
           1
          ]
         },
         "billingAnchorDay": {
          "type": "integer",
          "description": "Fixed billing day 1-28 on a monthly or yearly plan"
         },
         "prorateFirst": {
          "type": "boolean",
          "description": "With a billing day, charge the first partial period pro rata (default true)"
         },
         "buyAgainStudentIds": {
          "type": "array",
          "description": "For a pass pack: the chosen students who already hold it and are to be bought another. A student who holds the pack and is not named here is skipped, and their row in the dry run carries passesLeft. Default: none.",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "studentIds",
         "planId"
        ]
       },
       "example": {
        "studentIds": [
         1
        ],
        "planId": 1
       }
      }
     }
    }
   }
  },
  "/v1/billing/subscriptions/bulk/pause": {
   "post": {
    "operationId": "billing_bulkPause",
    "summary": "bulkPause",
    "description": "Pause multiple subscriptions at once. Each item runs on its own; partial failures are reported. Reuses the single-subscription pause logic per item, so a pass pack or a one-time plan fails its row (the preview says so). Supports ?preview=true and ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.QueuedOperation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "operationId": 1,
            "label": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "operationId": 1,
            "label": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "subscriptionIds": {
          "type": "array",
          "description": "Subscription IDs to pause (1 to 10,000 items)",
          "items": {
           "type": "integer"
          }
         },
         "scheduledResumeOn": {
          "type": "string",
          "description": "Optional day (YYYY-MM-DD) every paused plan resumes on its own",
          "format": "date"
         }
        },
        "required": [
         "subscriptionIds"
        ]
       },
       "example": {
        "subscriptionIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/billing/subscriptions/bulk/resume": {
   "post": {
    "operationId": "billing_bulkResume",
    "summary": "bulkResume",
    "description": "Resume multiple paused subscriptions at once. Each item runs on its own; partial failures are reported. Supports ?preview=true and ?confirm=true. The preview checks each plan from the school's records and asks no gateway: a plan that restarts at the gateway and finds no saved card or Direct Debit fails its own row in the run, with the reason.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.QueuedOperation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "operationId": 1,
            "label": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "operationId": 1,
            "label": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "subscriptionIds": {
          "type": "array",
          "description": "Subscription IDs to resume (1 to 10,000 items)",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "subscriptionIds"
        ]
       },
       "example": {
        "subscriptionIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/billing/subscriptions/bulk/cancel": {
   "post": {
    "operationId": "billing_bulkCancel",
    "summary": "bulkCancel",
    "description": "Cancel multiple subscriptions at once. Supports atPeriodEnd or cancelAt for deferred cancellation. Each item runs on its own; partial failures are reported. Supports ?preview=true and ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.QueuedOperation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "operationId": 1,
            "label": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "operationId": 1,
            "label": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "subscriptionIds": {
          "type": "array",
          "description": "Subscription IDs to cancel (1 to 10,000 items)",
          "items": {
           "type": "integer"
          }
         },
         "atPeriodEnd": {
          "type": "boolean",
          "description": "If true, cancel at end of current billing period. A pass pack, a one-time plan or a pay-as-you-go plan has no billing period: that item is refused and the rest run. Default: false",
          "default": false
         },
         "cancelAt": {
          "type": "string",
          "description": "Cancel on a specific future day. Cannot be combined with atPeriodEnd. A day, YYYY-MM-DD, in the school's zone. A Unix timestamp is also accepted and re-anchored to school midnight of the day it falls on there.",
          "format": "date"
         }
        },
        "required": [
         "subscriptionIds"
        ]
       },
       "example": {
        "subscriptionIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/billing/subscriptions/bulk/discount": {
   "post": {
    "operationId": "billing_bulkDiscount",
    "summary": "bulkDiscount",
    "description": "Apply or remove discounts on multiple subscriptions at once. Each discount propagates to its payment gateway BEFORE the local row is written (Stripe: coupon swap; GoCardless: cancel and recreate at the new effective amount, its externalId changes), each subscription on its own: one whose gateway call fails keeps its old value and is reported in results. A discount change starts with the member's next period. Periods already begun keep the price they had. A pass pack or one-off plan is paid for once, at assignment: the preview marks it wouldSucceed false and the run skips it. Discount value: percentage 0-100 or fixed CENTS. Set discount to null to remove. Supports ?preview=true and ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.QueuedOperation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "operationId": 1,
            "label": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "operationId": 1,
            "label": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "subscriptionIds": {
          "type": "array",
          "description": "Subscription IDs to update (1 to 10,000 items)",
          "items": {
           "type": "integer"
          }
         },
         "discount": {
          "type": "number",
          "description": "Discount value (null to remove). Percentage (0-100) or fixed amount in CENTS depending on discountType."
         },
         "discountType": {
          "type": "integer",
          "description": "0 = percentage, 1 = fixed amount in cents. Null to remove discount.",
          "enum": [
           0,
           1
          ]
         }
        },
        "required": [
         "subscriptionIds"
        ]
       },
       "example": {
        "subscriptionIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/billing/payments/bulk": {
   "post": {
    "operationId": "billing_bulkRecordPayments",
    "summary": "bulkRecordPayments",
    "description": "Record multiple manual payments at once. Each payment is processed independently with per-item error handling. Max 100 payments per batch. Supports ?preview=true and ?confirm=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.QueuedOperation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "operationId": 1,
            "label": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "operationId": 1,
            "label": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "payments": {
          "type": "array",
          "description": "Array of payment objects (1 to 10,000 items): { studentId, amount (cents), paymentMethod, description, subscriptionId?, taxAmount? }",
          "items": {}
         }
        },
        "required": [
         "payments"
        ]
       },
       "example": {
        "payments": []
       }
      }
     }
    }
   }
  },
  "/v1/billing/counts": {
   "get": {
    "operationId": "billing_getBillingCounts",
    "summary": "getBillingCounts",
    "description": "Get aggregated billing statistics for the school. Includes active/paused/overdue subscription counts, total monthly revenue (MRR normalized from weekly/yearly), outstanding amounts, and breakdowns by gateway and plan type.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.BillingCounts"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "activeSubscriptions": 1,
          "pausedSubscriptions": 1,
          "overdueSubscriptions": 1,
          "totalMonthlyRevenue": 1,
          "totalOutstanding": 1,
          "studentsByPlanType": {},
          "gatewayBreakdown": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/analytics": {
   "get": {
    "operationId": "billing_getAnalyticsDashboard",
    "summary": "getAnalyticsDashboard",
    "description": "Revenue summary: MRR, ARR, churn rate, new subscriptions, revenue this month, ARPU, payment method breakdown, and revenue by plan type. Cached for 15 minutes.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.AnalyticsDashboard"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "mrr": 1,
          "arr": 1,
          "activeSubscriptions": 1,
          "newSubscriptionsThisMonth": 1,
          "churnRate": 1,
          "churnedThisMonth": 1,
          "revenueThisMonth": 1,
          "outstandingAmount": 1,
          "averageRevenuePerStudent": 1,
          "paymentMethodBreakdown": {},
          "revenueByPlanType": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/analytics/mrr": {
   "get": {
    "operationId": "billing_getMrrTimeSeries",
    "summary": "getMrrTimeSeries",
    "description": "MRR time series over the last N months. Each data point shows MRR at month-end and active subscription count. Uses current plan amounts (known approximation). Cached for 15 minutes.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.MrrDataPoint"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "month": "string",
           "mrr": 1,
           "activeSubscriptions": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "months",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 12
      },
      "description": "Number of months of history (min 1, max 24). Default: 12"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/analytics/churn": {
   "get": {
    "operationId": "billing_getChurnAnalysis",
    "summary": "getChurnAnalysis",
    "description": "Churn analysis with voluntary/involuntary classification. Voluntary = cancelled with no preceding failed transaction. Involuntary = preceded by a failed transaction (status codes 6-9). Includes per-plan and per-gateway breakdown.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.ChurnAnalysis"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "churnRate": 1,
          "totalChurned": 1,
          "voluntary": 1,
          "involuntary": 1,
          "byPlan": [],
          "byGateway": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Start of analysis period (Unix seconds). Default: start of current month. Also accepted as dateFrom."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "End of analysis period (Unix seconds). Default: now. Also accepted as dateTo."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/analytics/revenue": {
   "get": {
    "operationId": "billing_getRevenueBreakdown",
    "summary": "getRevenueBreakdown",
    "description": "Revenue breakdown by plan, gateway, and payment method. Queries successful (status 4/5), non-refunded transactions in the date range.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.RevenueBreakdown"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "total": 1,
          "byPlan": [],
          "byGateway": {},
          "byPaymentMethod": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Start of period (Unix seconds). Default: start of current month. Also accepted as dateFrom."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "End of period (Unix seconds). Default: now. Also accepted as dateTo."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/payouts": {
   "get": {
    "operationId": "billing_listPayouts",
    "summary": "listPayouts",
    "description": "List payouts from connected payment gateways. Fetches from Stripe and/or GoCardless in parallel, merges and sorts by date. Returns empty array if no gateways connected.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.Payout"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": "string",
           "gateway": "stripe",
           "amount": 1,
           "currency": "string",
           "status": "string",
           "arrivalDate": 1793836800,
           "createdAt": 1793836800,
           "description": "string",
           "transactionCount": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Start of date range (Unix seconds). Default: 30 days ago. Also accepted as dateFrom."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "End of date range (Unix seconds). Default: now. Also accepted as dateTo."
     },
     {
      "name": "gateway",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "stripe",
        "gocardless"
       ]
      },
      "description": "Filter to a specific gateway"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 25
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/payouts/reconcile": {
   "get": {
    "operationId": "billing_getReconciliationReport",
    "summary": "getReconciliationReport",
    "description": "Cross-gateway reconciliation report. Matches payout items to local transactions. Returns per-gateway summaries with matched/unmatched counts and fee totals. Max 90-day range.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.ReconciliationReport"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "period": {},
          "stripe": {},
          "gocardless": {},
          "unmatchedLocal": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Start of period (Unix seconds). Default: 30 days ago. Also accepted as dateFrom."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "End of period (Unix seconds). Default: now. Also accepted as dateTo."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/payouts/{gateway}/{id}": {
   "get": {
    "operationId": "billing_getPayoutDetail",
    "summary": "getPayoutDetail",
    "description": "Get detailed payout info with matched local transactions. Gateway is explicit in the URL path (stripe or gocardless). Returns payout metadata plus an array of individual transactions with fee/net amounts and local transaction ID matches.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.PayoutDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": "string",
          "gateway": "stripe",
          "amount": 1,
          "currency": "string",
          "status": "string",
          "arrivalDate": 1793836800,
          "createdAt": 1793836800,
          "transactionCount": 1,
          "transactions": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "gateway",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/disputes": {
   "get": {
    "operationId": "billing_listDisputes",
    "summary": "listDisputes",
    "description": "List Stripe disputes (chargebacks) for this school. Enriched with local student names from charge metadata. Requires Stripe Connect.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.DisputeSummary"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": "string",
           "amount": 1,
           "currency": "string",
           "status": "warning_needs_response",
           "actionability": "actionable",
           "reason": "string",
           "hasEvidence": false,
           "evidenceDueBy": 1793836800,
           "chargeId": "string",
           "studentId": 1,
           "studentName": "string",
           "createdAt": 1793836800
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "warning_needs_response",
        "warning_under_review",
        "warning_closed",
        "needs_response",
        "under_review",
        "won",
        "lost"
       ]
      },
      "description": "Filter by dispute status"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 20
      },
      "description": "Items per page (max 100). Default: 20"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/disputes/{id}": {
   "get": {
    "operationId": "billing_getDisputeDetail",
    "summary": "getDisputeDetail",
    "description": "Get full dispute detail including evidence status, timeline, and available actions. Returns actionability status to indicate if the school can still respond.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.DisputeDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": "string",
          "amount": 1,
          "currency": "string",
          "status": "string",
          "actionability": "string",
          "reason": "string",
          "hasEvidence": false,
          "evidenceDueBy": 1793836800,
          "chargeId": "string",
          "studentId": 1,
          "studentName": "string",
          "createdAt": 1793836800,
          "paymentIntentId": "string",
          "networkReasonCode": "string",
          "evidenceDetails": {},
          "_actions": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/disputes/{id}/evidence": {
   "get": {
    "operationId": "billing_generateEvidence",
    "summary": "generateEvidence",
    "description": "Auto-generate dispute evidence from attendance records. Pulls last 90 days of attendance for the linked student (from charge metadata) and builds a pre-filled evidence bundle with product description, service dates, and attendance documentation.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.DisputeEvidenceBundle"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "productDescription": "string",
          "customerName": "string",
          "customerEmailAddress": "string",
          "customerPurchaseIp": "string",
          "serviceDate": "string",
          "serviceDocumentation": "string",
          "attendanceRecords": [],
          "attendanceSummary": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "billing_submitEvidence",
    "summary": "submitEvidence",
    "description": "Submit dispute evidence to Stripe. Validates the dispute is still actionable and evidence hasn't already been submitted. ?preview=true is a dry run (the same refusals, the generated case files, nothing sent to Stripe); ?confirm=true submits. The evidence fields map directly to Stripe's evidence object.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.DisputeDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": "string",
            "amount": 1,
            "currency": "string",
            "status": "string",
            "actionability": "string",
            "reason": "string",
            "hasEvidence": false,
            "evidenceDueBy": 1793836800,
            "chargeId": "string",
            "studentId": 1,
            "studentName": "string",
            "createdAt": 1793836800,
            "paymentIntentId": "string",
            "networkReasonCode": "string",
            "evidenceDetails": {},
            "_actions": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": "string",
            "amount": 1,
            "currency": "string",
            "status": "string",
            "actionability": "string",
            "reason": "string",
            "hasEvidence": false,
            "evidenceDueBy": 1793836800,
            "chargeId": "string",
            "studentId": 1,
            "studentName": "string",
            "createdAt": 1793836800,
            "paymentIntentId": "string",
            "networkReasonCode": "string",
            "evidenceDetails": {},
            "_actions": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "productDescription": {
          "type": "string",
          "description": "Description of the product/service"
         },
         "customerName": {
          "type": "string",
          "description": "Name of the customer"
         },
         "customerEmailAddress": {
          "type": "string",
          "description": "Customer email address"
         },
         "serviceDate": {
          "type": "string",
          "description": "Date of service (YYYY-MM-DD)"
         },
         "serviceDocumentation": {
          "type": "string",
          "description": "Detailed service documentation (attendance records, etc.)"
         }
        },
        "required": [
         "productDescription",
         "customerName"
        ]
       },
       "example": {
        "productDescription": "string",
        "customerName": "string"
       }
      }
     }
    }
   }
  },
  "/v1/billing/disputes/{id}/polish": {
   "post": {
    "operationId": "billing_polishDisputeStatement",
    "summary": "polishDisputeStatement",
    "description": "Optional AI rewrite of the admin's draft dispute statement. May only restate facts already in the draft; metered on the school's monthly AI allowance (declines when exhausted, like an assistant turn). The deterministic draft remains fully usable without it.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "statement": {
          "type": "string",
          "description": "The current draft statement (40-4000 characters)"
         }
        },
        "required": [
         "statement"
        ]
       },
       "example": {
        "statement": "string"
       }
      }
     }
    }
   }
  },
  "/v1/billing/disputes/{id}/accept": {
   "post": {
    "operationId": "billing_acceptDispute",
    "summary": "acceptDispute",
    "description": "Accept (concede) a dispute. This closes the dispute in Stripe in favor of the cardholder. ?preview=true is a dry run (the same refusals, nothing closed); ?confirm=true accepts. Only available when the dispute is in an actionable state.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.DisputeDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": "string",
            "amount": 1,
            "currency": "string",
            "status": "string",
            "actionability": "string",
            "reason": "string",
            "hasEvidence": false,
            "evidenceDueBy": 1793836800,
            "chargeId": "string",
            "studentId": 1,
            "studentName": "string",
            "createdAt": 1793836800,
            "paymentIntentId": "string",
            "networkReasonCode": "string",
            "evidenceDetails": {},
            "_actions": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": "string",
            "amount": 1,
            "currency": "string",
            "status": "string",
            "actionability": "string",
            "reason": "string",
            "hasEvidence": false,
            "evidenceDueBy": 1793836800,
            "chargeId": "string",
            "studentId": 1,
            "studentName": "string",
            "createdAt": 1793836800,
            "paymentIntentId": "string",
            "networkReasonCode": "string",
            "evidenceDetails": {},
            "_actions": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/portal/config": {
   "get": {
    "operationId": "billing_getPortalConfig",
    "summary": "getPortalConfig",
    "description": "Get the current Stripe Billing Portal configuration for this school. Controls what students can do in the self-service portal (update payment methods, view invoices, cancel subscriptions). The subscriptionPause toggle is a Martialytics setting, not a Stripe one.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.PortalConfig"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "paymentMethodUpdate": false,
          "invoiceHistory": false,
          "subscriptionCancel": {},
          "subscriptionPause": {},
          "updatedAt": 1793836800
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "billing_updatePortalConfig",
    "summary": "updatePortalConfig",
    "description": "Update the Billing Portal configuration. Creates or updates the Stripe portal configuration for Stripe-native features (payment method update, invoice history, subscription cancel). The subscriptionPause toggle is a Martialytics setting, not a Stripe one. Supports ?preview=true.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.PortalConfig"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "paymentMethodUpdate": false,
            "invoiceHistory": false,
            "subscriptionCancel": {},
            "subscriptionPause": {},
            "updatedAt": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "paymentMethodUpdate": false,
            "invoiceHistory": false,
            "subscriptionCancel": {},
            "subscriptionPause": {},
            "updatedAt": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "paymentMethodUpdate": {
          "type": "boolean",
          "description": "Allow payment method updates in portal"
         },
         "invoiceHistory": {
          "type": "boolean",
          "description": "Show invoice history in portal"
         },
         "subscriptionCancel": {
          "type": "object",
          "description": "Cancellation settings: { enabled, mode ('at_period_end'|'immediately'), cancellationReasons[] }"
         },
         "subscriptionPause": {
          "type": "object",
          "description": "Pause toggle (app-level, stored in Redis): { enabled }"
         }
        }
       },
       "example": {
        "paymentMethodUpdate": false,
        "invoiceHistory": false,
        "subscriptionCancel": {},
        "subscriptionPause": {}
       }
      }
     }
    }
   }
  },
  "/v1/billing/smart-invoices": {
   "get": {
    "operationId": "billing_listSmartInvoices",
    "summary": "listSmartInvoices",
    "description": "List smart invoices with optional filters. Smart invoices are pre-subscription payment links sent to students before plan assignment.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.SmartInvoice"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "studentId": 1,
           "studentName": "string",
           "planId": 1,
           "planName": "string",
           "status": "pending",
           "totalAmountCents": 1,
           "currency": "string",
           "discount": 1,
           "discountType": 1,
           "oneOffPayment": 1,
           "startOn": 1,
           "endOn": 1,
           "createdOn": 1,
           "convertedOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by student ID"
     },
     {
      "name": "planId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by plan ID"
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "pending",
        "processing",
        "completed",
        "cancelled",
        "expired"
       ]
      },
      "description": "Filter by invoice status"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 20
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "billing_createSmartInvoice",
    "summary": "createSmartInvoice",
    "description": "Create a smart invoice (a payment request) and optionally email it to the student. Generates a JWT-secured payment link. Requires Stripe connection. Refused with PLAN_COLLISION when the student already holds the plan (or holds it paused), or it clashes with a plan they hold, as assigning it would be; and with SMART_INVOICE_ALREADY_OPEN when they already have an unpaid request for it: resend or cancel that one. One exception: the same plan held on an offline payment method (cash and the like) is not a refusal. Paying the request then ends that plan and starts the card plan, and the dry run says so in `replaces`.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.SmartInvoice"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "studentName": "string",
            "planId": 1,
            "planName": "string",
            "status": "pending",
            "totalAmountCents": 1,
            "currency": "string",
            "discount": 1,
            "discountType": 1,
            "oneOffPayment": 1,
            "startOn": 1,
            "endOn": 1,
            "createdOn": 1,
            "convertedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "studentName": "string",
            "planId": 1,
            "planName": "string",
            "status": "pending",
            "totalAmountCents": 1,
            "currency": "string",
            "discount": 1,
            "discountType": 1,
            "oneOffPayment": 1,
            "startOn": 1,
            "endOn": 1,
            "createdOn": 1,
            "convertedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, PLAN_COLLISION, SMART_INVOICE_ALREADY_OPEN",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PLAN_COLLISION",
     "SMART_INVOICE_ALREADY_OPEN",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer",
          "description": "Student to invoice"
         },
         "planId": {
          "type": "integer",
          "description": "Plan to assign on payment"
         },
         "startOn": {
          "type": "string",
          "description": "Future start day. A day, YYYY-MM-DD, in the school's zone. A Unix timestamp is also accepted and re-anchored to school midnight of the day it falls on there.",
          "format": "date"
         },
         "endOn": {
          "type": "string",
          "description": "End day. A day, YYYY-MM-DD, in the school's zone. A Unix timestamp is also accepted and re-anchored to school midnight of the day it falls on there.",
          "format": "date"
         },
         "discount": {
          "type": "integer",
          "description": "Discount amount",
          "minimum": 0,
          "maximum": 100
         },
         "discountType": {
          "type": "integer",
          "description": "0 = percentage, 1 = fixed amount in cents",
          "enum": [
           0,
           1
          ]
         },
         "oneOffPayment": {
          "type": "integer",
          "description": "Enrollment fee in cents",
          "minimum": 0
         },
         "sendEmail": {
          "type": "boolean",
          "description": "Send email immediately. Default: true",
          "default": true
         }
        },
        "required": [
         "studentId",
         "planId"
        ]
       },
       "example": {
        "studentId": 1,
        "planId": 1
       }
      }
     }
    }
   }
  },
  "/v1/billing/smart-invoices/{id}": {
   "get": {
    "operationId": "billing_getSmartInvoice",
    "summary": "getSmartInvoice",
    "description": "Get a single smart invoice by ID with HATEOAS links.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.SmartInvoice"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "studentId": 1,
          "studentName": "string",
          "planId": 1,
          "planName": "string",
          "status": "pending",
          "totalAmountCents": 1,
          "currency": "string",
          "discount": 1,
          "discountType": 1,
          "oneOffPayment": 1,
          "startOn": 1,
          "endOn": 1,
          "createdOn": 1,
          "convertedOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "delete": {
    "operationId": "billing_cancelSmartInvoice",
    "summary": "cancelSmartInvoice",
    "description": "Cancel a pending smart invoice. Only pending invoices can be cancelled (soft-delete).",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/smart-invoices/{id}/resend": {
   "post": {
    "operationId": "billing_resendSmartInvoice",
    "summary": "resendSmartInvoice",
    "description": "Resend a smart invoice email with a fresh payment link. Only pending or processing invoices can be resent.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.SmartInvoice"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "studentName": "string",
            "planId": 1,
            "planName": "string",
            "status": "pending",
            "totalAmountCents": 1,
            "currency": "string",
            "discount": 1,
            "discountType": 1,
            "oneOffPayment": 1,
            "startOn": 1,
            "endOn": 1,
            "createdOn": 1,
            "convertedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "studentName": "string",
            "planId": 1,
            "planName": "string",
            "status": "pending",
            "totalAmountCents": 1,
            "currency": "string",
            "discount": 1,
            "discountType": 1,
            "oneOffPayment": 1,
            "startOn": 1,
            "endOn": 1,
            "createdOn": 1,
            "convertedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/deferred/process": {
   "post": {
    "operationId": "billing_processDeferredActions",
    "summary": "processDeferredActions",
    "description": "Process pending deferred billing actions whose scheduled time has passed. Handles scheduled cancellations, resumes, and other spool-based operations (e.g. GoCardless cancel-at-period-end).",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.DeferredProcessResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "processed": 1,
            "succeeded": 1,
            "failed": 1,
            "errors": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "processed": 1,
            "succeeded": 1,
            "failed": 1,
            "errors": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/customer-lookup": {
   "post": {
    "operationId": "billing_customerLookup",
    "summary": "customerLookup",
    "description": "Look up gateway customers that match a student. Returns linked status, current linkage, and candidate matches with confidence scores. Used to manually resolve student-to-gateway-customer mapping.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.CustomerLookupResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "linked",
          "linkedCustomer": {},
          "matches": []
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "gateway": {
          "type": "string",
          "description": "Which gateway to search",
          "enum": [
           "stripe",
           "gocardless"
          ]
         }
        },
        "required": [
         "gateway"
        ]
       },
       "example": {
        "gateway": "stripe"
       }
      }
     }
    }
   }
  },
  "/v1/billing/students/{studentId}/customer-link/{gateway}": {
   "delete": {
    "operationId": "billing_unlinkCustomer",
    "summary": "unlinkCustomer",
    "description": "Unlink the student's Stripe customer or GoCardless mandate holder. Supports ?preview=true; requires ?confirm=true. Refused (409 GATEWAY_CUSTOMER_IN_USE) while a live plan billed through that gateway relies on it, the student's own or a family plan they pay for. A plan of theirs that another family member pays for does not count.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "gateway",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/students/{studentId}/link-customer": {
   "post": {
    "operationId": "billing_linkCustomer",
    "summary": "linkCustomer",
    "description": "Link a student to a specific gateway customer ID. Used after customerLookup to confirm the correct match. One customer per student: a customer another student of the school holds is refused (409 GATEWAY_CUSTOMER_IN_USE) and named.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.LinkCustomerResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "linkedCustomerId": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "linkedCustomerId": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "gateway": {
          "type": "string",
          "description": "Target gateway",
          "enum": [
           "stripe",
           "gocardless"
          ]
         },
         "gatewayCustomerId": {
          "type": "string",
          "description": "Gateway customer ID (e.g. cus_xxx for Stripe)"
         }
        },
        "required": [
         "gateway",
         "gatewayCustomerId"
        ]
       },
       "example": {
        "gateway": "stripe",
        "gatewayCustomerId": "string"
       }
      }
     }
    }
   }
  },
  "/v1/billing/jobs": {
   "get": {
    "operationId": "billing_listBillingJobs",
    "summary": "listBillingJobs",
    "description": "List async billing jobs for the current school (plan migrations, bulk operations). Ordered by creation time descending. Supports filtering by job type (e.g. 'migration') and pagination.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/billing.BillingJob"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "type": "string",
           "status": "pending",
           "progress": {},
           "createdAt": 1,
           "completedAt": 1,
           "sourcePlanId": 1,
           "targetPlanId": 1,
           "sourcePlanName": "string",
           "targetPlanName": "string",
           "timing": "immediate",
           "effectiveDate": "2026-11-05",
           "migrationBatchId": "string",
           "failedReason": "string",
           "results": [],
           "triedAgainAt": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "type",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by job type (e.g. 'migration')"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/jobs/{id}": {
   "get": {
    "operationId": "billing_getBillingJob",
    "summary": "getBillingJob",
    "description": "Fetch a single billing job by ID, including real-time progress and per-item results.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/billing.BillingJob"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "type": "string",
          "status": "pending",
          "progress": {},
          "createdAt": 1,
          "completedAt": 1,
          "sourcePlanId": 1,
          "targetPlanId": 1,
          "sourcePlanName": "string",
          "targetPlanName": "string",
          "timing": "immediate",
          "effectiveDate": "2026-11-05",
          "migrationBatchId": "string",
          "failedReason": "string",
          "results": [],
          "triedAgainAt": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/billing/jobs/{id}/stop": {
   "post": {
    "operationId": "billing_stopBillingJob",
    "summary": "stopBillingJob",
    "description": "Stop a billing job (plan migration, price change or tax change) that is still pending or in progress half an hour after it was queued, so the plan it locks can be changed again. Marks it failed and records who stopped it; members it already processed keep their results. Refused (409) for a job that finished or is younger than half an hour.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.BillingJob"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "type": "string",
            "status": "pending",
            "progress": {},
            "createdAt": 1,
            "completedAt": 1,
            "sourcePlanId": 1,
            "targetPlanId": 1,
            "sourcePlanName": "string",
            "targetPlanName": "string",
            "timing": "immediate",
            "effectiveDate": "2026-11-05",
            "migrationBatchId": "string",
            "failedReason": "string",
            "results": [],
            "triedAgainAt": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "type": "string",
            "status": "pending",
            "progress": {},
            "createdAt": 1,
            "completedAt": 1,
            "sourcePlanId": 1,
            "targetPlanId": 1,
            "sourcePlanName": "string",
            "targetPlanName": "string",
            "timing": "immediate",
            "effectiveDate": "2026-11-05",
            "migrationBatchId": "string",
            "failedReason": "string",
            "results": [],
            "triedAgainAt": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/billing/jobs/{id}/try-again": {
   "post": {
    "operationId": "billing_tryAgainBillingJob",
    "summary": "tryAgainBillingJob",
    "description": "Start a finished price change, plan migration or tax change again for the members it did not finish: those who failed, and those `gatewayMoved` (moved at Stripe or GoCardless while our own record was not saved). Members already done are left alone. A member already moved at their gateway is not moved or charged again: only our record is saved. Two calls start one run: the second answers `started: false`. ?preview=true says how many members it would run for; ?confirm=true starts it. Refused (409) when everyone is finished, when the plan's price has changed since a price change ran, or when the school's tax has changed since a tax change ran.",
    "tags": [
     "billing"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/billing.BillingJobTryAgain"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "status": "pending",
            "started": false,
            "members": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "status": "pending",
            "started": false,
            "members": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/invoices": {
   "get": {
    "operationId": "invoices_list",
    "summary": "list",
    "description": "School-wide invoice list, newest first, with student names.",
    "tags": [
     "invoices"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/invoices.InvoiceListRow"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "collecting": false,
           "invoiceNumber": 1,
           "invoiceLabel": "string",
           "status": "draft",
           "studentId": 1,
           "studentName": "string",
           "totalCents": 1,
           "currency": "string",
           "issuedOn": 1793836800,
           "dueOn": 1793836800,
           "paidOn": 1793836800,
           "createdOn": 1793836800
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "draft",
        "sent",
        "paid",
        "overdue",
        "cancelled",
        "unpaid"
       ]
      },
      "description": "Filter by status. 'unpaid' is a convenience filter for sent + overdue."
     },
     {
      "name": "studentId",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Only this student's invoices."
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Page number (default 1)."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Page size (default 20)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "invoices_create",
    "summary": "create",
    "description": "Create an invoice. body.send=true (default) allocates the invoice number and emails the pay link immediately; send=false saves an editable draft.",
    "tags": [
     "invoices"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/invoices.InvoiceDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "invoiceNumber": 1,
            "invoiceLabel": "string",
            "status": "draft",
            "collecting": false,
            "studentId": 1,
            "studentName": "string",
            "totalCents": 1,
            "currency": "string",
            "issuedOn": 1793836800,
            "dueOn": 1793836800,
            "paidOn": 1793836800,
            "createdOn": 1793836800,
            "cancelledOn": 1793836800,
            "taxRate": "string",
            "taxMode": "string",
            "subtotalCents": 1,
            "taxAmountCents": 1,
            "taxName": "string",
            "notes": "string",
            "transactionId": 1,
            "items": [],
            "payUrl": "string",
            "emailStatus": "sent"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "invoiceNumber": 1,
            "invoiceLabel": "string",
            "status": "draft",
            "collecting": false,
            "studentId": 1,
            "studentName": "string",
            "totalCents": 1,
            "currency": "string",
            "issuedOn": 1793836800,
            "dueOn": 1793836800,
            "paidOn": 1793836800,
            "createdOn": 1793836800,
            "cancelledOn": 1793836800,
            "taxRate": "string",
            "taxMode": "string",
            "subtotalCents": 1,
            "taxAmountCents": 1,
            "taxName": "string",
            "notes": "string",
            "transactionId": 1,
            "items": [],
            "payUrl": "string",
            "emailStatus": "sent"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "number"
         },
         "items": {
          "type": "array",
          "description": "1-50 line items: { description, quantity, unitAmountCents }.",
          "items": {}
         },
         "dueOn": {
          "type": "string",
          "description": "Due date (YYYY-MM-DD), resolved to end-of-day in the school's timezone. Optional. Today or later: a date that has already passed is refused (INVOICE_DUE_IN_PAST).",
          "format": "date"
         },
         "notes": {
          "type": "string",
          "maxLength": 1000
         },
         "send": {
          "type": "boolean",
          "description": "Default true."
         }
        },
        "required": [
         "studentId",
         "items"
        ]
       },
       "example": {
        "studentId": 1,
        "items": []
       }
      }
     }
    }
   }
  },
  "/v1/invoices/{id}": {
   "get": {
    "operationId": "invoices_get",
    "summary": "get",
    "description": "Invoice detail: line items, totals, status, and the public pay link once sent.",
    "tags": [
     "invoices"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/invoices.InvoiceDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "invoiceNumber": 1,
          "invoiceLabel": "string",
          "status": "draft",
          "collecting": false,
          "studentId": 1,
          "studentName": "string",
          "totalCents": 1,
          "currency": "string",
          "issuedOn": 1793836800,
          "dueOn": 1793836800,
          "paidOn": 1793836800,
          "createdOn": 1793836800,
          "cancelledOn": 1793836800,
          "taxRate": "string",
          "taxMode": "string",
          "subtotalCents": 1,
          "taxAmountCents": 1,
          "taxName": "string",
          "notes": "string",
          "transactionId": 1,
          "items": [],
          "payUrl": "string",
          "emailStatus": "sent"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "invoices_updateDraft",
    "summary": "updateDraft",
    "description": "Edit a draft (items, due date, notes). Sent invoices are immutable: cancel and re-issue instead.",
    "tags": [
     "invoices"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/invoices.InvoiceDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "invoiceNumber": 1,
            "invoiceLabel": "string",
            "status": "draft",
            "collecting": false,
            "studentId": 1,
            "studentName": "string",
            "totalCents": 1,
            "currency": "string",
            "issuedOn": 1793836800,
            "dueOn": 1793836800,
            "paidOn": 1793836800,
            "createdOn": 1793836800,
            "cancelledOn": 1793836800,
            "taxRate": "string",
            "taxMode": "string",
            "subtotalCents": 1,
            "taxAmountCents": 1,
            "taxName": "string",
            "notes": "string",
            "transactionId": 1,
            "items": [],
            "payUrl": "string",
            "emailStatus": "sent"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "invoiceNumber": 1,
            "invoiceLabel": "string",
            "status": "draft",
            "collecting": false,
            "studentId": 1,
            "studentName": "string",
            "totalCents": 1,
            "currency": "string",
            "issuedOn": 1793836800,
            "dueOn": 1793836800,
            "paidOn": 1793836800,
            "createdOn": 1793836800,
            "cancelledOn": 1793836800,
            "taxRate": "string",
            "taxMode": "string",
            "subtotalCents": 1,
            "taxAmountCents": 1,
            "taxName": "string",
            "notes": "string",
            "transactionId": 1,
            "items": [],
            "payUrl": "string",
            "emailStatus": "sent"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "items": {
          "type": "array",
          "items": {}
         },
         "dueOn": {
          "type": "string",
          "description": "Today or later; a date that has already passed is refused.",
          "format": "date"
         },
         "notes": {
          "type": "string"
         }
        }
       },
       "example": {
        "items": [],
        "dueOn": "2026-11-05",
        "notes": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "invoices_deleteDraft",
    "summary": "deleteDraft",
    "description": "Discard a draft. Sent invoices cancel instead.",
    "tags": [
     "invoices"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/invoices/recipient/{studentId}": {
   "get": {
    "operationId": "invoices_previewRecipient",
    "summary": "previewRecipient",
    "description": "Who the pay-link email will go to: student email with guardian fallback for minors (same resolution as waivers).",
    "tags": [
     "invoices"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/invoices.RecipientPreview"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "recipient": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/invoices/{id}/send": {
   "post": {
    "operationId": "invoices_send",
    "summary": "send",
    "description": "Send a draft (allocates the per-school invoice number, mints the pay link, emails it) or re-send the email for a sent/overdue invoice. A draft whose due date has passed is refused until the date is moved to today or later.",
    "tags": [
     "invoices"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/invoices.InvoiceDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "invoiceNumber": 1,
            "invoiceLabel": "string",
            "status": "draft",
            "collecting": false,
            "studentId": 1,
            "studentName": "string",
            "totalCents": 1,
            "currency": "string",
            "issuedOn": 1793836800,
            "dueOn": 1793836800,
            "paidOn": 1793836800,
            "createdOn": 1793836800,
            "cancelledOn": 1793836800,
            "taxRate": "string",
            "taxMode": "string",
            "subtotalCents": 1,
            "taxAmountCents": 1,
            "taxName": "string",
            "notes": "string",
            "transactionId": 1,
            "items": [],
            "payUrl": "string",
            "emailStatus": "sent"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "invoiceNumber": 1,
            "invoiceLabel": "string",
            "status": "draft",
            "collecting": false,
            "studentId": 1,
            "studentName": "string",
            "totalCents": 1,
            "currency": "string",
            "issuedOn": 1793836800,
            "dueOn": 1793836800,
            "paidOn": 1793836800,
            "createdOn": 1793836800,
            "cancelledOn": 1793836800,
            "taxRate": "string",
            "taxMode": "string",
            "subtotalCents": 1,
            "taxAmountCents": 1,
            "taxName": "string",
            "notes": "string",
            "transactionId": 1,
            "items": [],
            "payUrl": "string",
            "emailStatus": "sent"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/invoices/{id}/mark-paid": {
   "post": {
    "operationId": "invoices_markPaid",
    "summary": "markPaid",
    "description": "Record an offline payment and mark the invoice paid. Writes a normal billing transaction so receipts and reporting pick it up.",
    "tags": [
     "invoices"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/invoices.InvoiceDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "invoiceNumber": 1,
            "invoiceLabel": "string",
            "status": "draft",
            "collecting": false,
            "studentId": 1,
            "studentName": "string",
            "totalCents": 1,
            "currency": "string",
            "issuedOn": 1793836800,
            "dueOn": 1793836800,
            "paidOn": 1793836800,
            "createdOn": 1793836800,
            "cancelledOn": 1793836800,
            "taxRate": "string",
            "taxMode": "string",
            "subtotalCents": 1,
            "taxAmountCents": 1,
            "taxName": "string",
            "notes": "string",
            "transactionId": 1,
            "items": [],
            "payUrl": "string",
            "emailStatus": "sent"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "invoiceNumber": 1,
            "invoiceLabel": "string",
            "status": "draft",
            "collecting": false,
            "studentId": 1,
            "studentName": "string",
            "totalCents": 1,
            "currency": "string",
            "issuedOn": 1793836800,
            "dueOn": 1793836800,
            "paidOn": 1793836800,
            "createdOn": 1793836800,
            "cancelledOn": 1793836800,
            "taxRate": "string",
            "taxMode": "string",
            "subtotalCents": 1,
            "taxAmountCents": 1,
            "taxName": "string",
            "notes": "string",
            "transactionId": 1,
            "items": [],
            "payUrl": "string",
            "emailStatus": "sent"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "paymentMethod": {
          "type": "string",
          "enum": [
           "Cash",
           "Cheque",
           "Credit Card",
           "Direct Debit",
           "Standing Order"
          ]
         }
        },
        "required": [
         "paymentMethod"
        ]
       },
       "example": {
        "paymentMethod": "Cash"
       }
      }
     }
    }
   }
  },
  "/v1/invoices/{id}/collect": {
   "post": {
    "operationId": "invoices_collect",
    "summary": "collect",
    "description": "Charge the student's GoCardless mandate for the invoice total. Asynchronous: the invoice flips to paid when the direct debit confirms via webhook.",
    "tags": [
     "invoices"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/invoices/{id}/cancel": {
   "post": {
    "operationId": "invoices_cancel",
    "summary": "cancel",
    "description": "Cancel a sent/overdue invoice. The public pay link stops working. Refused with 409 while a direct debit is being collected for it (collecting: true): it turns paid when the debit clears, and can be cancelled if the debit fails.",
    "tags": [
     "invoices"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/invoices.InvoiceDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "invoiceNumber": 1,
            "invoiceLabel": "string",
            "status": "draft",
            "collecting": false,
            "studentId": 1,
            "studentName": "string",
            "totalCents": 1,
            "currency": "string",
            "issuedOn": 1793836800,
            "dueOn": 1793836800,
            "paidOn": 1793836800,
            "createdOn": 1793836800,
            "cancelledOn": 1793836800,
            "taxRate": "string",
            "taxMode": "string",
            "subtotalCents": 1,
            "taxAmountCents": 1,
            "taxName": "string",
            "notes": "string",
            "transactionId": 1,
            "items": [],
            "payUrl": "string",
            "emailStatus": "sent"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "invoiceNumber": 1,
            "invoiceLabel": "string",
            "status": "draft",
            "collecting": false,
            "studentId": 1,
            "studentName": "string",
            "totalCents": 1,
            "currency": "string",
            "issuedOn": 1793836800,
            "dueOn": 1793836800,
            "paidOn": 1793836800,
            "createdOn": 1793836800,
            "cancelledOn": 1793836800,
            "taxRate": "string",
            "taxMode": "string",
            "subtotalCents": 1,
            "taxAmountCents": 1,
            "taxName": "string",
            "notes": "string",
            "transactionId": 1,
            "items": [],
            "payUrl": "string",
            "emailStatus": "sent"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/shop/categories": {
   "get": {
    "operationId": "shop_listCategories",
    "summary": "listCategories",
    "description": "List all live shop categories with live-product counts",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/shop.Category"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "colour": "string",
           "position": 1,
           "productCount": 1,
           "createdOn": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "shop_createCategory",
    "summary": "createCategory",
    "description": "Create a new product category",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.Category"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "colour": "string",
            "position": 1,
            "productCount": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "colour": "string",
            "position": 1,
            "productCount": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Category name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 200
         },
         "colour": {
          "type": "string",
          "description": "Colour swatch: typically hex (#RRGGBB), but legacy CSS names are accepted",
          "maxLength": 25
         },
         "position": {
          "type": "integer",
          "description": "Sort position; defaults to bottom of list when omitted",
          "minimum": 0
         }
        },
        "required": [
         "name",
         "colour"
        ]
       },
       "example": {
        "name": "string",
        "colour": "string"
       }
      }
     }
    }
   }
  },
  "/v1/shop/categories/{id}": {
   "get": {
    "operationId": "shop_getCategory",
    "summary": "getCategory",
    "description": "Get a single category with its product count",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/shop.Category"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "colour": "string",
          "position": 1,
          "productCount": 1,
          "createdOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "shop_updateCategory",
    "summary": "updateCategory",
    "description": "Update a category",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.Category"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "colour": "string",
            "position": 1,
            "productCount": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "colour": "string",
            "position": 1,
            "productCount": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
         },
         "colour": {
          "type": "string",
          "maxLength": 25
         },
         "position": {
          "type": "integer",
          "minimum": 0
         }
        }
       },
       "example": {
        "name": "string",
        "colour": "string",
        "position": 1
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "shop_deleteCategory",
    "summary": "deleteCategory",
    "description": "Soft-delete a category. Child products are NOT cascaded: they remain accessible by ID for receipt resolution but disappear from the live catalogue.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/shop/categories/reorder": {
   "post": {
    "operationId": "shop_reorderCategories",
    "summary": "reorderCategories",
    "description": "Reorder categories. Body provides an ordered array of category IDs; the index becomes the new `position`.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "categoryIds": {
          "type": "array",
          "description": "Ordered list of category IDs (1-500)",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "categoryIds"
        ]
       },
       "example": {
        "categoryIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/shop/products": {
   "get": {
    "operationId": "shop_listProducts",
    "summary": "listProducts",
    "description": "List products with aggregated option counts, price ranges, and stock totals. Archived products excluded unless `includeArchived=true`.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/shop.ProductSummary"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "categoryId": 1,
           "name": "string",
           "variantMode": "flat",
           "visibility": "draft",
           "taxExempt": false,
           "position": 1,
           "optionCount": 1,
           "minPriceCents": 1,
           "maxPriceCents": 1,
           "totalStock": 1,
           "primaryImageKey": "string",
           "primaryImageUrl": "string",
           "createdOn": 1,
           "updatedOn": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "categoryId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by category"
     },
     {
      "name": "visibility",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "draft",
        "published",
        "archived"
       ]
      },
      "description": "Filter by visibility state"
     },
     {
      "name": "variantMode",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "flat",
        "matrix"
       ]
      },
      "description": "Filter by variant mode"
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Substring match on product name"
     },
     {
      "name": "includeArchived",
      "in": "query",
      "schema": {
       "type": "boolean",
       "default": false
      },
      "description": "Include archived products"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "shop_createProduct",
    "summary": "createProduct",
    "description": "Create a product. `variantMode='flat'` requires an `options` array; `variantMode='matrix'` requires `attributeAxes` and `basePriceCents`: the Cartesian product of axes auto-generates options.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.Product"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "categoryId": 1,
            "name": "string",
            "description": "string",
            "variantMode": "flat",
            "attributeAxes": [
             {
              "name": "string",
              "values": [
               "string"
              ]
             }
            ],
            "visibility": "draft",
            "taxExempt": false,
            "costCents": 1,
            "position": 1,
            "sourceMasterId": 1,
            "createdOn": 1,
            "updatedOn": 1,
            "options": [
             {
              "id": 1,
              "productId": 1,
              "name": "string",
              "sku": "string",
              "priceCents": 1,
              "quantity": 1,
              "position": 1,
              "attributes": {},
              "createdOn": 1,
              "updatedOn": 1
             }
            ],
            "images": [
             {
              "id": 1,
              "productId": 1,
              "storageKey": "string",
              "position": 1,
              "createdOn": 1
             }
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "categoryId": 1,
            "name": "string",
            "description": "string",
            "variantMode": "flat",
            "attributeAxes": [
             {
              "name": "string",
              "values": [
               "string"
              ]
             }
            ],
            "visibility": "draft",
            "taxExempt": false,
            "costCents": 1,
            "position": 1,
            "sourceMasterId": 1,
            "createdOn": 1,
            "updatedOn": 1,
            "options": [
             {
              "id": 1,
              "productId": 1,
              "name": "string",
              "sku": "string",
              "priceCents": 1,
              "quantity": 1,
              "position": 1,
              "attributes": {},
              "createdOn": 1,
              "updatedOn": 1
             }
            ],
            "images": [
             {
              "id": 1,
              "productId": 1,
              "storageKey": "string",
              "position": 1,
              "createdOn": 1
             }
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "variantMode": {
          "type": "string",
          "description": "'flat' = legacy freeform options; 'matrix' = auto-generated from axes",
          "enum": [
           "flat",
           "matrix"
          ]
         },
         "categoryId": {
          "type": "integer",
          "description": "Owning category"
         },
         "name": {
          "type": "string",
          "description": "Product name (must be unique within the category)",
          "minLength": 1,
          "maxLength": 200
         },
         "description": {
          "type": "string",
          "description": "Rich-text product description"
         },
         "visibility": {
          "type": "string",
          "enum": [
           "draft",
           "published",
           "archived"
          ],
          "default": "published"
         },
         "taxExempt": {
          "type": "boolean",
          "description": "Override school tax settings for this product",
          "default": false
         },
         "costCents": {
          "type": "integer",
          "description": "Wholesale cost in cents: used for margin reports (future)",
          "minimum": 0
         },
         "position": {
          "type": "integer",
          "description": "Sort position; defaults to bottom of the category",
          "minimum": 0
         },
         "options": {
          "type": "array",
          "description": "[flat mode only] Initial options array",
          "items": {
           "type": "object",
           "properties": {
            "name": {
             "type": "string",
             "maxLength": 200
            },
            "priceCents": {
             "type": "integer",
             "minimum": 0
            },
            "sku": {
             "type": "string",
             "maxLength": 200
            },
            "quantity": {
             "type": "integer",
             "description": "Stock count; null = unlimited",
             "minimum": 0
            }
           },
           "required": [
            "name",
            "priceCents"
           ]
          }
         },
         "attributeAxes": {
          "type": "array",
          "description": "[matrix mode only] Axes for the variant matrix. Up to 3 axes, up to 20 values per axis, capped at 100 total combinations.",
          "items": {
           "type": "object",
           "properties": {
            "name": {
             "type": "string",
             "description": "Axis name, e.g. 'Size'"
            },
            "values": {
             "type": "array",
             "description": "Axis values, e.g. ['S','M','L']",
             "items": {
              "type": "string"
             }
            }
           },
           "required": [
            "name",
            "values"
           ]
          }
         },
         "basePriceCents": {
          "type": "integer",
          "description": "[matrix mode only] Base price applied to every auto-generated variant; override per-variant via PATCH /options/:optionId",
          "minimum": 0
         }
        },
        "required": [
         "variantMode",
         "categoryId",
         "name"
        ]
       },
       "example": {
        "variantMode": "flat",
        "categoryId": 1,
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/shop/products/stock": {
   "get": {
    "operationId": "shop_listStockLevels",
    "summary": "listStockLevels",
    "description": "Stock levels across every finite-quantity product option in one call (product, option, remaining quantity). The restock worklist.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "description": "StockLevel"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/shop/products/{id}": {
   "get": {
    "operationId": "shop_getProduct",
    "summary": "getProduct",
    "description": "Get a single product with full options and images",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/shop.Product"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "categoryId": 1,
          "name": "string",
          "description": "string",
          "variantMode": "flat",
          "attributeAxes": [
           {
            "name": "string",
            "values": [
             "string"
            ]
           }
          ],
          "visibility": "draft",
          "taxExempt": false,
          "costCents": 1,
          "position": 1,
          "sourceMasterId": 1,
          "createdOn": 1,
          "updatedOn": 1,
          "options": [
           {
            "id": 1,
            "productId": 1,
            "name": "string",
            "sku": "string",
            "priceCents": 1,
            "quantity": 1,
            "position": 1,
            "attributes": {},
            "createdOn": 1,
            "updatedOn": 1
           }
          ],
          "images": [
           {
            "id": 1,
            "productId": 1,
            "storageKey": "string",
            "position": 1,
            "createdOn": 1
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "shop_updateProduct",
    "summary": "updateProduct",
    "description": "Update product metadata. `variantMode` and `attributeAxes` are immutable post-create in this release. Destructive axis edits will land via a future rebuild endpoint.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.Product"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "categoryId": 1,
            "name": "string",
            "description": "string",
            "variantMode": "flat",
            "attributeAxes": [
             {
              "name": "string",
              "values": [
               "string"
              ]
             }
            ],
            "visibility": "draft",
            "taxExempt": false,
            "costCents": 1,
            "position": 1,
            "sourceMasterId": 1,
            "createdOn": 1,
            "updatedOn": 1,
            "options": [
             {
              "id": 1,
              "productId": 1,
              "name": "string",
              "sku": "string",
              "priceCents": 1,
              "quantity": 1,
              "position": 1,
              "attributes": {},
              "createdOn": 1,
              "updatedOn": 1
             }
            ],
            "images": [
             {
              "id": 1,
              "productId": 1,
              "storageKey": "string",
              "position": 1,
              "createdOn": 1
             }
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "categoryId": 1,
            "name": "string",
            "description": "string",
            "variantMode": "flat",
            "attributeAxes": [
             {
              "name": "string",
              "values": [
               "string"
              ]
             }
            ],
            "visibility": "draft",
            "taxExempt": false,
            "costCents": 1,
            "position": 1,
            "sourceMasterId": 1,
            "createdOn": 1,
            "updatedOn": 1,
            "options": [
             {
              "id": 1,
              "productId": 1,
              "name": "string",
              "sku": "string",
              "priceCents": 1,
              "quantity": 1,
              "position": 1,
              "attributes": {},
              "createdOn": 1,
              "updatedOn": 1
             }
            ],
            "images": [
             {
              "id": 1,
              "productId": 1,
              "storageKey": "string",
              "position": 1,
              "createdOn": 1
             }
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "categoryId": {
          "type": "integer"
         },
         "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
         },
         "description": {
          "type": "string"
         },
         "visibility": {
          "type": "string",
          "enum": [
           "draft",
           "published",
           "archived"
          ]
         },
         "taxExempt": {
          "type": "boolean"
         },
         "costCents": {
          "type": "integer",
          "minimum": 0
         },
         "position": {
          "type": "integer",
          "minimum": 0
         }
        }
       },
       "example": {
        "categoryId": 1,
        "name": "string",
        "description": "string",
        "visibility": "draft",
        "taxExempt": false,
        "costCents": 1,
        "position": 1
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "shop_deleteProduct",
    "summary": "deleteProduct",
    "description": "Soft-delete a product and cascade-soft-delete its options. Order history remains intact via snapshot columns.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/shop/products/{id}/options": {
   "post": {
    "operationId": "shop_createOption",
    "summary": "createOption",
    "description": "Add an option to a flat-mode product. Rejected (409) for matrix products: those gain options only by expanding their axes.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.ProductOption"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "productId": 1,
            "name": "string",
            "sku": "string",
            "priceCents": 1,
            "quantity": 1,
            "position": 1,
            "attributes": {},
            "createdOn": 1,
            "updatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "productId": 1,
            "name": "string",
            "sku": "string",
            "priceCents": 1,
            "quantity": 1,
            "position": 1,
            "attributes": {},
            "createdOn": 1,
            "updatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "maxLength": 200
         },
         "priceCents": {
          "type": "integer",
          "minimum": 0
         },
         "sku": {
          "type": "string",
          "maxLength": 200
         },
         "quantity": {
          "type": "integer",
          "description": "Stock count; null = unlimited",
          "minimum": 0
         },
         "position": {
          "type": "integer",
          "minimum": 0
         }
        },
        "required": [
         "name",
         "priceCents"
        ]
       },
       "example": {
        "name": "string",
        "priceCents": 1
       }
      }
     }
    }
   }
  },
  "/v1/shop/products/{id}/options/{optionId}": {
   "patch": {
    "operationId": "shop_updateOption",
    "summary": "updateOption",
    "description": "Update option fields. In matrix mode, `name` is ignored (derived from axes); `priceCents`/`sku`/`quantity`/`position` always apply.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.ProductOption"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "productId": 1,
            "name": "string",
            "sku": "string",
            "priceCents": 1,
            "quantity": 1,
            "position": 1,
            "attributes": {},
            "createdOn": 1,
            "updatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "productId": 1,
            "name": "string",
            "sku": "string",
            "priceCents": 1,
            "quantity": 1,
            "position": 1,
            "attributes": {},
            "createdOn": 1,
            "updatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "optionId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Flat mode only: ignored in matrix mode",
          "maxLength": 200
         },
         "priceCents": {
          "type": "integer",
          "minimum": 0
         },
         "sku": {
          "type": "string",
          "maxLength": 200
         },
         "quantity": {
          "type": "integer",
          "description": "Stock count; null = unlimited",
          "minimum": 0
         },
         "position": {
          "type": "integer",
          "minimum": 0
         }
        }
       },
       "example": {
        "name": "string",
        "priceCents": 1,
        "sku": "string",
        "quantity": 1,
        "position": 1
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "shop_deleteOption",
    "summary": "deleteOption",
    "description": "Soft-delete an option. Refused for matrix options and for the last option on a flat product.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "optionId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/shop/orders": {
   "get": {
    "operationId": "shop_listOrders",
    "summary": "listOrders",
    "description": "Paginated list of orders for the school. Numeric `search` matches order ID exactly; non-numeric `search` runs LIKE against customer first/last name and email.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/shop.OrderSummary"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "status": "pending_payment",
           "fulfillmentType": "pos",
           "fulfilledBy": "string",
           "customer": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "email": "string"
           },
           "subtotalCents": 1,
           "discountCents": 1,
           "taxCents": 1,
           "shippingCents": 1,
           "totalCents": 1,
           "totalRefundedCents": 1,
           "placedByUserId": 1,
           "createdOn": 1,
           "updatedOn": 1,
           "itemCount": 1,
           "backorderedCount": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Max 10000"
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "pending_payment",
        "paid",
        "ready_for_pickup",
        "shipped",
        "completed",
        "cancelled",
        "refunded"
       ]
      }
     },
     {
      "name": "fulfillmentType",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "pos",
        "pickup",
        "ship"
       ]
      }
     },
     {
      "name": "studentId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter to orders placed for a specific student"
     },
     {
      "name": "placedByUserId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter to orders rung up by a specific staff user (POS attribution)"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Inclusive lower bound on createdOn (unix seconds). Also accepted as fromDate."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Inclusive upper bound on createdOn (unix seconds). Also accepted as toDate."
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Order ID exact match (if numeric) OR customer name/email substring"
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "id",
        "customer",
        "status",
        "fulfillment",
        "items",
        "total",
        "refunded",
        "placed",
        "-id",
        "-customer",
        "-status",
        "-fulfillment",
        "-items",
        "-total",
        "-refunded",
        "-placed"
       ],
       "default": "-placed"
      },
      "description": "Sort field, prefix with '-' for descending. Defaults to -placed (newest first). 'total' sorts by the SAME effective total the response returns, which falls back to the line-item sum when total_cents is null (most rows), not by the raw column. 'status' sorts by lifecycle position (awaiting payment -> paid -> ready -> shipped -> completed -> refunded -> cancelled), not alphabetically. 'customer' places walk-ins last in both directions. Unrecognised values fall back to the default rather than erroring."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "shop_createOrder",
    "summary": "createOrder",
    "description": "Create a POS or online order. Server computes totals from canonical option prices using the school's tax settings; client-supplied prices are ignored. Decrements stock on finite-quantity options. Status is 'paid' for synchronous payment methods (cash, manual_card, store_credit) and 'pending_payment' when paymentMethod='pending' (pickup/ship pre-pay flow).",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.Order"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "status": "pending_payment",
            "fulfillmentType": "pos",
            "fulfilledBy": "string",
            "customer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "subtotalCents": 1,
            "discountCents": 1,
            "taxCents": 1,
            "shippingCents": 1,
            "totalCents": 1,
            "totalRefundedCents": 1,
            "notes": "string",
            "payer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "externalReference": "string",
            "shippingAddress": {},
            "placedByUserId": 1,
            "createdOn": 1,
            "updatedOn": 1,
            "itemCount": 1,
            "backorderedCount": 1,
            "items": [
             {
              "id": 1,
              "optionId": 1,
              "quantity": 1,
              "priceCents": 1,
              "productName": "string",
              "optionName": "string",
              "attributes": {},
              "taxExemptAtSale": false,
              "refundedQuantity": 1,
              "backordered": false
             }
            ],
            "refunds": [
             {
              "id": 1,
              "type": "full",
              "method": "original",
              "amountCents": 1,
              "reason": "string",
              "createdOn": 1,
              "createdByUserId": 1
             }
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "status": "pending_payment",
            "fulfillmentType": "pos",
            "fulfilledBy": "string",
            "customer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "subtotalCents": 1,
            "discountCents": 1,
            "taxCents": 1,
            "shippingCents": 1,
            "totalCents": 1,
            "totalRefundedCents": 1,
            "notes": "string",
            "payer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "externalReference": "string",
            "shippingAddress": {},
            "placedByUserId": 1,
            "createdOn": 1,
            "updatedOn": 1,
            "itemCount": 1,
            "backorderedCount": 1,
            "items": [
             {
              "id": 1,
              "optionId": 1,
              "quantity": 1,
              "priceCents": 1,
              "productName": "string",
              "optionName": "string",
              "attributes": {},
              "taxExemptAtSale": false,
              "refundedQuantity": 1,
              "backordered": false
             }
            ],
            "refunds": [
             {
              "id": 1,
              "type": "full",
              "method": "original",
              "amountCents": 1,
              "reason": "string",
              "createdOn": 1,
              "createdByUserId": 1
             }
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer",
          "description": "Customer student ID. Null/omitted for walk-in POS sales without a member record."
         },
         "payerStudentId": {
          "type": "integer",
          "description": "Student whose on-file payment method is charged when it is not the recipient (a parent paying for a child). Omit when the customer pays. Requires studentId."
         },
         "externalReference": {
          "type": "string",
          "description": "Your own order reference (max 64 chars: letters, digits, space,. _ - # /). Echoed on the gateway payment description, the order, and shop.order.* webhook deliveries."
         },
         "fulfillmentType": {
          "type": "string",
          "description": "'pos' (in-store), 'pickup' (collect later), 'ship' (mail to address)",
          "enum": [
           "pos",
           "pickup",
           "ship"
          ]
         },
         "paymentMethod": {
          "type": "string",
          "description": "Synchronous methods (cash/manual_card/store_credit) mark the order 'paid'; 'pending' parks the order at 'pending_payment' for later capture.",
          "enum": [
           "cash",
           "manual_card",
           "store_credit",
           "pending"
          ]
         },
         "lines": {
          "type": "array",
          "description": "Cart line items. Server resolves prices and snapshots names at sale time.",
          "items": {
           "type": "object",
           "properties": {
            "optionId": {
             "type": "integer",
             "description": "Product option ID"
            },
            "quantity": {
             "type": "integer",
             "description": "Units of this option to sell",
             "minimum": 1,
             "maximum": 999
            }
           },
           "required": [
            "optionId",
            "quantity"
           ]
          }
         },
         "discountCents": {
          "type": "integer",
          "description": "Discount in cents, allocated proportionally across taxable + exempt lines. Defaults to 0."
         },
         "notes": {
          "type": "string",
          "description": "Free-text staff notes (max 2000 chars)."
         },
         "allowOversell": {
          "type": "boolean",
          "description": "Staff till only: sell an item whose stock count is 0 or less. The count goes negative and the order notes say so. Without it a shortfall answers 409 OUT_OF_STOCK."
         },
         "shippingAddress": {
          "type": "object",
          "description": "Required when fulfillmentType='ship'. Frozen on the order row."
         }
        },
        "required": [
         "fulfillmentType",
         "paymentMethod",
         "lines"
        ]
       },
       "example": {
        "fulfillmentType": "pos",
        "paymentMethod": "cash",
        "lines": [
         {
          "optionId": 1,
          "quantity": 1
         }
        ]
       }
      }
     }
    }
   }
  },
  "/v1/shop/orders/{id}": {
   "get": {
    "operationId": "shop_getOrder",
    "summary": "getOrder",
    "description": "Get an order with line items (frozen snapshots) and refund history. `customer` is null for walk-in POS orders without a linked student.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/shop.Order"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "status": "pending_payment",
          "fulfillmentType": "pos",
          "fulfilledBy": "string",
          "customer": {
           "id": 1,
           "firstName": "string",
           "lastName": "string",
           "email": "string"
          },
          "subtotalCents": 1,
          "discountCents": 1,
          "taxCents": 1,
          "shippingCents": 1,
          "totalCents": 1,
          "totalRefundedCents": 1,
          "notes": "string",
          "payer": {
           "id": 1,
           "firstName": "string",
           "lastName": "string",
           "email": "string"
          },
          "externalReference": "string",
          "shippingAddress": {},
          "placedByUserId": 1,
          "createdOn": 1,
          "updatedOn": 1,
          "itemCount": 1,
          "backorderedCount": 1,
          "items": [
           {
            "id": 1,
            "optionId": 1,
            "quantity": 1,
            "priceCents": 1,
            "productName": "string",
            "optionName": "string",
            "attributes": {},
            "taxExemptAtSale": false,
            "refundedQuantity": 1,
            "backordered": false
           }
          ],
          "refunds": [
           {
            "id": 1,
            "type": "full",
            "method": "original",
            "amountCents": 1,
            "reason": "string",
            "createdOn": 1,
            "createdByUserId": 1
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "shop_updateOrder",
    "summary": "updateOrder",
    "description": "Update a live order's fulfillment status, notes, or shipping address. Status transitions are gated by a state machine: pending_payment to cancelled; paid to ready_for_pickup, shipped or completed; ready_for_pickup to completed; shipped to completed. Refunds use a dedicated endpoint, not this one. Shipping address is immutable once an order has shipped or is otherwise terminal.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.Order"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "status": "pending_payment",
            "fulfillmentType": "pos",
            "fulfilledBy": "string",
            "customer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "subtotalCents": 1,
            "discountCents": 1,
            "taxCents": 1,
            "shippingCents": 1,
            "totalCents": 1,
            "totalRefundedCents": 1,
            "notes": "string",
            "payer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "externalReference": "string",
            "shippingAddress": {},
            "placedByUserId": 1,
            "createdOn": 1,
            "updatedOn": 1,
            "itemCount": 1,
            "backorderedCount": 1,
            "items": [
             {
              "id": 1,
              "optionId": 1,
              "quantity": 1,
              "priceCents": 1,
              "productName": "string",
              "optionName": "string",
              "attributes": {},
              "taxExemptAtSale": false,
              "refundedQuantity": 1,
              "backordered": false
             }
            ],
            "refunds": [
             {
              "id": 1,
              "type": "full",
              "method": "original",
              "amountCents": 1,
              "reason": "string",
              "createdOn": 1,
              "createdByUserId": 1
             }
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "status": "pending_payment",
            "fulfillmentType": "pos",
            "fulfilledBy": "string",
            "customer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "subtotalCents": 1,
            "discountCents": 1,
            "taxCents": 1,
            "shippingCents": 1,
            "totalCents": 1,
            "totalRefundedCents": 1,
            "notes": "string",
            "payer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "externalReference": "string",
            "shippingAddress": {},
            "placedByUserId": 1,
            "createdOn": 1,
            "updatedOn": 1,
            "itemCount": 1,
            "backorderedCount": 1,
            "items": [
             {
              "id": 1,
              "optionId": 1,
              "quantity": 1,
              "priceCents": 1,
              "productName": "string",
              "optionName": "string",
              "attributes": {},
              "taxExemptAtSale": false,
              "refundedQuantity": 1,
              "backordered": false
             }
            ],
            "refunds": [
             {
              "id": 1,
              "type": "full",
              "method": "original",
              "amountCents": 1,
              "reason": "string",
              "createdOn": 1,
              "createdByUserId": 1
             }
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "status": {
          "type": "string",
          "description": "Target fulfillment status. Must satisfy the allowed transitions.",
          "enum": [
           "pending_payment",
           "paid",
           "ready_for_pickup",
           "shipped",
           "completed",
           "cancelled",
           "refunded"
          ]
         },
         "notes": {
          "type": "string",
          "description": "Free-text staff notes. Always editable."
         },
         "shippingAddress": {
          "type": "object",
          "description": "Shipping address. Only editable while status is pre-shipped."
         }
        }
       },
       "example": {
        "status": "pending_payment",
        "notes": "string",
        "shippingAddress": {}
       }
      }
     }
    }
   }
  },
  "/v1/shop/orders/{id}/collect": {
   "post": {
    "operationId": "shop_collectOrder",
    "summary": "collectOrder",
    "description": "Collect payment on an 'Awaiting payment' (pay-later) order. Writes the sale transaction exactly as an immediate sale would and flips the order to 'paid' (synchronous methods) or leaves it pending until the gateway confirms (walk-in card, terminal, GoCardless). Double-collection is rejected; the student for store_credit/on-file charges comes from the order itself.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.Order"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "status": "pending_payment",
            "fulfillmentType": "pos",
            "fulfilledBy": "string",
            "customer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "subtotalCents": 1,
            "discountCents": 1,
            "taxCents": 1,
            "shippingCents": 1,
            "totalCents": 1,
            "totalRefundedCents": 1,
            "notes": "string",
            "payer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "externalReference": "string",
            "shippingAddress": {},
            "placedByUserId": 1,
            "createdOn": 1,
            "updatedOn": 1,
            "itemCount": 1,
            "backorderedCount": 1,
            "items": [
             {
              "id": 1,
              "optionId": 1,
              "quantity": 1,
              "priceCents": 1,
              "productName": "string",
              "optionName": "string",
              "attributes": {},
              "taxExemptAtSale": false,
              "refundedQuantity": 1,
              "backordered": false
             }
            ],
            "refunds": [
             {
              "id": 1,
              "type": "full",
              "method": "original",
              "amountCents": 1,
              "reason": "string",
              "createdOn": 1,
              "createdByUserId": 1
             }
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "status": "pending_payment",
            "fulfillmentType": "pos",
            "fulfilledBy": "string",
            "customer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "subtotalCents": 1,
            "discountCents": 1,
            "taxCents": 1,
            "shippingCents": 1,
            "totalCents": 1,
            "totalRefundedCents": 1,
            "notes": "string",
            "payer": {
             "id": 1,
             "firstName": "string",
             "lastName": "string",
             "email": "string"
            },
            "externalReference": "string",
            "shippingAddress": {},
            "placedByUserId": 1,
            "createdOn": 1,
            "updatedOn": 1,
            "itemCount": 1,
            "backorderedCount": 1,
            "items": [
             {
              "id": 1,
              "optionId": 1,
              "quantity": 1,
              "priceCents": 1,
              "productName": "string",
              "optionName": "string",
              "attributes": {},
              "taxExemptAtSale": false,
              "refundedQuantity": 1,
              "backordered": false
             }
            ],
            "refunds": [
             {
              "id": 1,
              "type": "full",
              "method": "original",
              "amountCents": 1,
              "reason": "string",
              "createdOn": 1,
              "createdByUserId": 1
             }
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "paymentMethod": {
          "type": "string",
          "description": "How the customer is paying now. Everything POS accepts except 'pending'.",
          "enum": [
           "cash",
           "manual_card",
           "store_credit",
           "stripe",
           "gocardless",
           "stripe_walkin",
           "stripe_terminal"
          ]
         }
        },
        "required": [
         "paymentMethod"
        ]
       },
       "example": {
        "paymentMethod": "cash"
       }
      }
     }
    }
   }
  },
  "/v1/shop/orders/{id}/refunds": {
   "post": {
    "operationId": "shop_createRefund",
    "summary": "createRefund",
    "description": "Issue a refund against a paid/fulfilled order. type='full' refunds all remaining qty per line; type='partial' refunds caller-specified lines and quantities. method='original' refunds the money AT THE PAYMENT GATEWAY when the sale carries a Stripe/GoCardless reference (a gateway decline answers 409 with the gateway's reason and nothing left recorded; if the gateway does not answer, the answer is a 409 whose message says the refund is not yet confirmed: the refund is on the order as pending, its lines held, and it settles by itself once the gateway confirms it or shows it was never made, so do not send another refund for it (sending the same refund again is safe: it is the same refund, never a second one) and tell the person it is not yet known; a 409 whose message says a refund of that amount was sent earlier and has since gone through means nothing was refunded now: tell the person, and only if they say another refund of the same amount is meant, send it again with newRefund: true); sales with no gateway reference record ledger-only and return gatewayRefund='no_reference' so the caller can tell the operator to reverse it in the gateway dashboard. method='store_credit' grants the linked student the same amount of Account Credit instead. Restock is opt-in per line on partial refunds and only affects finite-stock options. Writes a negative companion billing transaction linked to the original sale via parent_transaction_id (metadata carries the gateway refund id when pushed); flips order status to 'refunded' when cumulative refunds hit the order total. Response includes gatewayRefund: 'pushed' | 'no_reference' | 'not_applicable'.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.RefundCreateResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "refundId": 1,
            "amountCents": 1,
            "fullyRefunded": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "refundId": 1,
            "amountCents": 1,
            "fullyRefunded": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "type": {
          "type": "string",
          "description": "'full' = refund all remaining qty on every line; 'partial' = refund caller-specified items.",
          "enum": [
           "full",
           "partial"
          ]
         },
         "method": {
          "type": "string",
          "description": "How the refund is delivered. 'store_credit' requires the order to have a linked student.",
          "enum": [
           "original",
           "store_credit"
          ]
         },
         "reason": {
          "type": "string",
          "description": "Free-text reason logged on the refund header (max 1000 chars)."
         },
         "newRefund": {
          "type": "boolean",
          "description": "Only after a 409 saying a refund of the same amount was sent earlier and has since gone through, and only when the person has said another refund of that amount is meant: true sends it as a new refund. Leave it out otherwise."
         },
         "items": {
          "type": "array",
          "description": "Required for partial refunds; ignored when type='full'.",
          "items": {
           "type": "object",
           "properties": {
            "orderedProductId": {
             "type": "integer",
             "description": "Line item ID from the order"
            },
            "quantity": {
             "type": "integer",
             "description": "Units to refund (≤ remaining)",
             "minimum": 1
            },
            "restock": {
             "type": "boolean",
             "description": "Add the units back to inventory (finite-stock options only). Defaults to false."
            }
           },
           "required": [
            "orderedProductId",
            "quantity"
           ]
          }
         }
        },
        "required": [
         "type",
         "method"
        ]
       },
       "example": {
        "type": "full",
        "method": "original"
       }
      }
     }
    }
   }
  },
  "/v1/shop/students/{studentId}/store-credit": {
   "get": {
    "operationId": "shop_getStoreCredit",
    "summary": "getStoreCredit",
    "description": "Get a student's Account Credit balance and the 50 most recent ledger entries. The shop spends and refunds the same Account Credit the Billing profile shows and invoices use (one credit pot); entry source is refund for a shop refund paid into credit, consumption for a sale paid by credit.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/shop.StoreCreditView"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "balanceCents": 1,
          "entries": [
           {
            "id": 1,
            "amountCents": 1,
            "source": "manual",
            "reason": "string",
            "transactionId": 1,
            "createdByUserId": 1,
            "createdOn": 1
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "shop_adjustStoreCredit",
    "summary": "adjustStoreCredit",
    "description": "Manually grant or debit the student's Account Credit (admin path; not for refunds: refunds use POST /orders/:id/refunds). Positive amountCents grants credit, negative debits. Debits that would take the balance below zero are rejected with 409 INSUFFICIENT_BALANCE. An API key needs billing:write as well as shop:write.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/shop.StoreCreditAdjustResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "entryId": 1,
            "newBalanceCents": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "entryId": 1,
            "newBalanceCents": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "amountCents": {
          "type": "integer",
          "description": "Signed delta. Positive = grant; negative = debit. Must be non-zero."
         },
         "reason": {
          "type": "string",
          "description": "Required audit reason: shown on the student's ledger.",
          "minLength": 1,
          "maxLength": 300
         }
        },
        "required": [
         "amountCents",
         "reason"
        ]
       },
       "example": {
        "amountCents": 1,
        "reason": "string"
       }
      }
     }
    }
   }
  },
  "/v1/shop/orders/{id}/terminal/process": {
   "post": {
    "operationId": "shop_processOnTerminal",
    "summary": "processOnTerminal",
    "description": "Dispatch a pending order's payment to a Stripe Terminal card reader (in-person POS). The order completes when the reader payment succeeds (webhook-driven).",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/shop.Order"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "status": "pending_payment",
          "fulfillmentType": "pos",
          "fulfilledBy": "string",
          "customer": {
           "id": 1,
           "firstName": "string",
           "lastName": "string",
           "email": "string"
          },
          "subtotalCents": 1,
          "discountCents": 1,
          "taxCents": 1,
          "shippingCents": 1,
          "totalCents": 1,
          "totalRefundedCents": 1,
          "notes": "string",
          "payer": {
           "id": 1,
           "firstName": "string",
           "lastName": "string",
           "email": "string"
          },
          "externalReference": "string",
          "shippingAddress": {},
          "placedByUserId": 1,
          "createdOn": 1,
          "updatedOn": 1,
          "itemCount": 1,
          "backorderedCount": 1,
          "items": [
           {
            "id": 1,
            "optionId": 1,
            "quantity": 1,
            "priceCents": 1,
            "productName": "string",
            "optionName": "string",
            "attributes": {},
            "taxExemptAtSale": false,
            "refundedQuantity": 1,
            "backordered": false
           }
          ],
          "refunds": [
           {
            "id": 1,
            "type": "full",
            "method": "original",
            "amountCents": 1,
            "reason": "string",
            "createdOn": 1,
            "createdByUserId": 1
           }
          ]
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/shop/orders/{id}/terminal/cancel": {
   "post": {
    "operationId": "shop_cancelOnTerminal",
    "summary": "cancelOnTerminal",
    "description": "Cancel an in-flight Stripe Terminal reader action for the order.",
    "tags": [
     "shop"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/shop.Order"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "status": "pending_payment",
          "fulfillmentType": "pos",
          "fulfilledBy": "string",
          "customer": {
           "id": 1,
           "firstName": "string",
           "lastName": "string",
           "email": "string"
          },
          "subtotalCents": 1,
          "discountCents": 1,
          "taxCents": 1,
          "shippingCents": 1,
          "totalCents": 1,
          "totalRefundedCents": 1,
          "notes": "string",
          "payer": {
           "id": 1,
           "firstName": "string",
           "lastName": "string",
           "email": "string"
          },
          "externalReference": "string",
          "shippingAddress": {},
          "placedByUserId": 1,
          "createdOn": 1,
          "updatedOn": 1,
          "itemCount": 1,
          "backorderedCount": 1,
          "items": [
           {
            "id": 1,
            "optionId": 1,
            "quantity": 1,
            "priceCents": 1,
            "productName": "string",
            "optionName": "string",
            "attributes": {},
            "taxExemptAtSale": false,
            "refundedQuantity": 1,
            "backordered": false
           }
          ],
          "refunds": [
           {
            "id": 1,
            "type": "full",
            "method": "original",
            "amountCents": 1,
            "reason": "string",
            "createdOn": 1,
            "createdByUserId": 1
           }
          ]
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/leads/dormant": {
   "get": {
    "operationId": "leads_dormantList",
    "summary": "dormantList",
    "description": "Dormant leads: leads in a non-terminal stage with no stage change, activity, reminder or booking for the school's leads.dormant_days (Send messages do not count; default 180 days). They are off the board; this lists them, searchable by name / email / phone / source, sortable by last activity or created, paged (limit <= 100). stageId scopes to one column; null-stage leads belong to New.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "stageId",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Scope to one stage."
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Name, email, phone or source contains."
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "lastActivity",
        "created"
       ]
      },
      "description": "Default lastActivity (newest first)."
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "1-100, default 50."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/leads/dormant/restore": {
   "post": {
    "operationId": "leads_dormantRestore",
    "summary": "dormantRestore",
    "description": "Bulk move dormant leads back onto the board: clears the dormant date, sets the stage change time so they do not re-dormant, writes a 'dormant_restored' activity per lead with the actor. Omit toStageId for New; terminal stages are refused.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "leadIds": {
          "type": "array",
          "description": "1-100 lead ids.",
          "items": {}
         },
         "toStageId": {
          "type": "number",
          "description": "A live non-terminal stage; default New."
         }
        },
        "required": [
         "leadIds"
        ]
       },
       "example": {
        "leadIds": []
       }
      }
     }
    }
   }
  },
  "/v1/leads/dormant/lost": {
   "post": {
    "operationId": "leads_dormantLost",
    "summary": "dormantLost",
    "description": "Bulk mark dormant leads lost: the normal lost move per lead, so the usual activity and events fire.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "leadIds": {
          "type": "array",
          "description": "1-100 lead ids.",
          "items": {}
         }
        },
        "required": [
         "leadIds"
        ]
       },
       "example": {
        "leadIds": []
       }
      }
     }
    }
   }
  },
  "/v1/leads/dormant/archive": {
   "post": {
    "operationId": "leads_dormantArchive",
    "summary": "dormantArchive",
    "description": "Bulk archive dormant leads (soft delete via the normal lead delete, so lead.deleted fires and the rows are recoverable).",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "leadIds": {
          "type": "array",
          "description": "1-100 lead ids.",
          "items": {}
         }
        },
        "required": [
         "leadIds"
        ]
       },
       "example": {
        "leadIds": []
       }
      }
     }
    }
   }
  },
  "/v1/leads/dormant/export": {
   "get": {
    "operationId": "leads_dormantExport",
    "summary": "dormantExport",
    "description": "CSV of every dormant lead matching stageId / search: name, contact, source, stage, created, last activity, dormant since.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "stageId",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/leads/stage/{stageId}": {
   "get": {
    "operationId": "leads_stagePage",
    "summary": "stagePage",
    "description": "One more page of a board column. Takes the board's filters plus offset / limit (default 0 / 50); returns the slice and the column's totalCount.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "stageId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "offset",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "1-200."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/leads/stage/{stageId}/recipients": {
   "get": {
    "operationId": "leads_stageRecipients",
    "summary": "stageRecipients",
    "description": "Every live lead in a stage as { id, name }, for the column's Send button when the column is paged.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "stageId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/leads": {
   "get": {
    "operationId": "leads_board",
    "summary": "board",
    "description": "Get the full Kanban board: all stages with leads grouped inside. Includes computed temperature, days-in-stage, last contact, and reminder status. Returns referral sources for filter dropdowns.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/leads.LeadBoard"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "stages": [],
          "sources": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Search by name, email, or phone (LIKE match)"
     },
     {
      "name": "source",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by referral source (exact match)"
     },
     {
      "name": "temperature",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "hot",
        "warm",
        "cold"
       ]
      },
      "description": "Filter by computed temperature"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter leads referred on or after this Unix timestamp. Also accepted as dateFrom."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter leads referred on or before this Unix timestamp. Also accepted as dateTo."
     },
     {
      "name": "includeDormant",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Include dormant leads on the board. Off by default."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Cards per column (default 50); totalCount and dormantCount are unaffected."
     },
     {
      "name": "showArchived",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "true",
        "false"
       ]
      },
      "description": "Include archived lost leads (default: false). Lost leads are auto-archived after 30 days."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "leads_create",
    "summary": "create",
    "description": "Create a new lead. Names alone are refused: a lead needs one way to reach them, an emailAddress, mobileNumber or phoneNumber. Automatically placed in the \"New\" stage with a \"created\" activity logged.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/leads.LeadDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "string",
            "phoneNumber": "string",
            "mobileNumber": "string",
            "referralSource": "string",
            "referredOn": "2026-11-05",
            "stageId": 1,
            "temperature": "hot",
            "temperatureOverride": 1,
            "daysInStage": 1,
            "lastContactDate": 1793836800,
            "lastContactMethod": "string",
            "reminderDate": "2026-11-05",
            "reminderOverdue": false,
            "isTrial": false,
            "trialExpiresOn": "2026-11-05",
            "trialClassesUsed": 1,
            "trialClassesLimit": 1,
            "notes": "string",
            "createdOn": 1793836800,
            "lossReason": "string",
            "isLead": false,
            "isActive": false,
            "photoStorageKey": "string",
            "joinedOn": "2026-11-05",
            "convertedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "gender": "male",
            "address": "string",
            "suburb": "string",
            "postcode": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "string",
            "phoneNumber": "string",
            "mobileNumber": "string",
            "referralSource": "string",
            "referredOn": "2026-11-05",
            "stageId": 1,
            "temperature": "hot",
            "temperatureOverride": 1,
            "daysInStage": 1,
            "lastContactDate": 1793836800,
            "lastContactMethod": "string",
            "reminderDate": "2026-11-05",
            "reminderOverdue": false,
            "isTrial": false,
            "trialExpiresOn": "2026-11-05",
            "trialClassesUsed": 1,
            "trialClassesLimit": 1,
            "notes": "string",
            "createdOn": 1793836800,
            "lossReason": "string",
            "isLead": false,
            "isActive": false,
            "photoStorageKey": "string",
            "joinedOn": "2026-11-05",
            "convertedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "gender": "male",
            "address": "string",
            "suburb": "string",
            "postcode": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "firstName": {
          "type": "string",
          "description": "Lead's first name",
          "maxLength": 50
         },
         "lastName": {
          "type": "string",
          "description": "Lead's last name",
          "maxLength": 50
         },
         "emailAddress": {
          "type": "string",
          "description": "Email address (must be unique within the school). Optional when a mobile or phone number is given: a lead needs one way to reach them",
          "format": "email"
         },
         "phoneNumber": {
          "type": "string",
          "description": "Phone number",
          "maxLength": 20
         },
         "mobileNumber": {
          "type": "string",
          "description": "Mobile/cell number",
          "maxLength": 20
         },
         "referralSource": {
          "type": "string",
          "description": "How the lead found you (e.g., \"Facebook\", \"Google\", \"Walk-in\")",
          "maxLength": 120
         },
         "notes": {
          "type": "string",
          "description": "Free-text notes about the lead",
          "maxLength": 5000
         }
        },
        "required": [
         "firstName",
         "lastName"
        ]
       },
       "example": {
        "firstName": "string",
        "lastName": "string"
       }
      }
     }
    }
   }
  },
  "/v1/leads/export": {
   "get": {
    "operationId": "leads_export",
    "summary": "export",
    "description": "The board as a CSV file (text/csv attachment). Takes the same filters as the board and returns exactly what the board would show, converted leads on won stages included. Columns: First, Last, Email, Phone, Mobile, Address, Suburb, Postcode, Referral Source, Referral Date, Stage, Temperature, Last Contact, Next Reminder, Trial Expires, Conversion Date, Joined Date, Member#, Styles. Dates are YYYY-MM-DD in the school's timezone.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Search by name, email, or phone (LIKE match)"
     },
     {
      "name": "source",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Filter by referral source (exact match)"
     },
     {
      "name": "temperature",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "hot",
        "warm",
        "cold"
       ]
      },
      "description": "Filter by computed temperature"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter leads referred on or after this Unix timestamp. Also accepted as dateFrom."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter leads referred on or before this Unix timestamp. Also accepted as dateTo."
     },
     {
      "name": "showArchived",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "true",
        "false"
       ]
      },
      "description": "Include archived lost leads (default: false)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/leads/{id}": {
   "get": {
    "operationId": "leads_get",
    "summary": "get",
    "description": "Get full lead detail including profile, temperature, reminder, stage info, and extended fields (address, birthday, etc.)",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/leads.LeadDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "firstName": "string",
          "lastName": "string",
          "emailAddress": "string",
          "phoneNumber": "string",
          "mobileNumber": "string",
          "referralSource": "string",
          "referredOn": "2026-11-05",
          "stageId": 1,
          "temperature": "hot",
          "temperatureOverride": 1,
          "daysInStage": 1,
          "lastContactDate": 1793836800,
          "lastContactMethod": "string",
          "reminderDate": "2026-11-05",
          "reminderOverdue": false,
          "isTrial": false,
          "trialExpiresOn": "2026-11-05",
          "trialClassesUsed": 1,
          "trialClassesLimit": 1,
          "notes": "string",
          "createdOn": 1793836800,
          "lossReason": "string",
          "isLead": false,
          "isActive": false,
          "photoStorageKey": "string",
          "joinedOn": "2026-11-05",
          "convertedOn": "2026-11-05",
          "birthday": "2026-11-05",
          "gender": "male",
          "address": "string",
          "suburb": "string",
          "postcode": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "leads_update",
    "summary": "update",
    "description": "Update lead contact info and metadata. All fields optional.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/leads.LeadDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "string",
            "phoneNumber": "string",
            "mobileNumber": "string",
            "referralSource": "string",
            "referredOn": "2026-11-05",
            "stageId": 1,
            "temperature": "hot",
            "temperatureOverride": 1,
            "daysInStage": 1,
            "lastContactDate": 1793836800,
            "lastContactMethod": "string",
            "reminderDate": "2026-11-05",
            "reminderOverdue": false,
            "isTrial": false,
            "trialExpiresOn": "2026-11-05",
            "trialClassesUsed": 1,
            "trialClassesLimit": 1,
            "notes": "string",
            "createdOn": 1793836800,
            "lossReason": "string",
            "isLead": false,
            "isActive": false,
            "photoStorageKey": "string",
            "joinedOn": "2026-11-05",
            "convertedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "gender": "male",
            "address": "string",
            "suburb": "string",
            "postcode": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "string",
            "phoneNumber": "string",
            "mobileNumber": "string",
            "referralSource": "string",
            "referredOn": "2026-11-05",
            "stageId": 1,
            "temperature": "hot",
            "temperatureOverride": 1,
            "daysInStage": 1,
            "lastContactDate": 1793836800,
            "lastContactMethod": "string",
            "reminderDate": "2026-11-05",
            "reminderOverdue": false,
            "isTrial": false,
            "trialExpiresOn": "2026-11-05",
            "trialClassesUsed": 1,
            "trialClassesLimit": 1,
            "notes": "string",
            "createdOn": 1793836800,
            "lossReason": "string",
            "isLead": false,
            "isActive": false,
            "photoStorageKey": "string",
            "joinedOn": "2026-11-05",
            "convertedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "gender": "male",
            "address": "string",
            "suburb": "string",
            "postcode": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "firstName": {
          "type": "string",
          "description": "First name",
          "maxLength": 50
         },
         "lastName": {
          "type": "string",
          "description": "Last name",
          "maxLength": 50
         },
         "emailAddress": {
          "type": "string",
          "description": "Email (must remain unique within school)",
          "format": "email"
         },
         "phoneNumber": {
          "type": "string",
          "description": "Phone number (null to clear)",
          "maxLength": 20
         },
         "mobileNumber": {
          "type": "string",
          "description": "Mobile number (null to clear)",
          "maxLength": 20
         },
         "referralSource": {
          "type": "string",
          "description": "Referral source (null to clear)",
          "maxLength": 120
         },
         "notes": {
          "type": "string",
          "description": "Notes (null to clear)",
          "maxLength": 5000
         }
        }
       },
       "example": {
        "firstName": "string",
        "lastName": "string",
        "emailAddress": "jo@example.com",
        "phoneNumber": "string",
        "mobileNumber": "string",
        "referralSource": "string",
        "notes": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "leads_delete",
    "summary": "delete",
    "description": "Soft-delete a lead. The student record is marked as deleted.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/leads/{id}/stage": {
   "patch": {
    "operationId": "leads_moveStage",
    "summary": "moveStage",
    "description": "Move a lead to a different pipeline stage. Moving to \"Won\" converts the lead to an active student; the card stays in the Won column (and in the export) as the record of the conversion. Moving to \"Lost\" marks the lead as lost. Moving from \"Lost\" back to a regular stage reopens the lead. Moving a trial back to a regular stage makes them a lead again, which is refused with 409 STATUS_HELD_BY_LIVE_PLAN while they hold a live paid plan, their own or on a family plan (not set to cancel, and not paused unless a resume date is booked): cancel the plan first. A trial started again keeps the count: the days and classes used carry over, and a move into the Trial stage is refused with 409 TRIAL_USED_UP when nothing is left.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/leads.LeadDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "string",
            "phoneNumber": "string",
            "mobileNumber": "string",
            "referralSource": "string",
            "referredOn": "2026-11-05",
            "stageId": 1,
            "temperature": "hot",
            "temperatureOverride": 1,
            "daysInStage": 1,
            "lastContactDate": 1793836800,
            "lastContactMethod": "string",
            "reminderDate": "2026-11-05",
            "reminderOverdue": false,
            "isTrial": false,
            "trialExpiresOn": "2026-11-05",
            "trialClassesUsed": 1,
            "trialClassesLimit": 1,
            "notes": "string",
            "createdOn": 1793836800,
            "lossReason": "string",
            "isLead": false,
            "isActive": false,
            "photoStorageKey": "string",
            "joinedOn": "2026-11-05",
            "convertedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "gender": "male",
            "address": "string",
            "suburb": "string",
            "postcode": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "string",
            "phoneNumber": "string",
            "mobileNumber": "string",
            "referralSource": "string",
            "referredOn": "2026-11-05",
            "stageId": 1,
            "temperature": "hot",
            "temperatureOverride": 1,
            "daysInStage": 1,
            "lastContactDate": 1793836800,
            "lastContactMethod": "string",
            "reminderDate": "2026-11-05",
            "reminderOverdue": false,
            "isTrial": false,
            "trialExpiresOn": "2026-11-05",
            "trialClassesUsed": 1,
            "trialClassesLimit": 1,
            "notes": "string",
            "createdOn": 1793836800,
            "lossReason": "string",
            "isLead": false,
            "isActive": false,
            "photoStorageKey": "string",
            "joinedOn": "2026-11-05",
            "convertedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "gender": "male",
            "address": "string",
            "suburb": "string",
            "postcode": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS, STATUS_HELD_BY_LIVE_PLAN, TRIAL_USED_UP",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "STATUS_HELD_BY_LIVE_PLAN",
     "TRIAL_USED_UP",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "stageId": {
          "type": "integer",
          "description": "Target stage ID"
         },
         "notes": {
          "type": "string",
          "description": "Optional note for the stage change (used as loss reason when moving to \"Lost\")",
          "maxLength": 500
         }
        },
        "required": [
         "stageId"
        ]
       },
       "example": {
        "stageId": 1
       }
      }
     }
    }
   }
  },
  "/v1/leads/{id}/temperature": {
   "patch": {
    "operationId": "leads_setTemperature",
    "summary": "setTemperature",
    "description": "Set or clear the manual temperature override. When null, temperature is auto-calculated from days since last contact and stage position.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/leads.LeadDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "string",
            "phoneNumber": "string",
            "mobileNumber": "string",
            "referralSource": "string",
            "referredOn": "2026-11-05",
            "stageId": 1,
            "temperature": "hot",
            "temperatureOverride": 1,
            "daysInStage": 1,
            "lastContactDate": 1793836800,
            "lastContactMethod": "string",
            "reminderDate": "2026-11-05",
            "reminderOverdue": false,
            "isTrial": false,
            "trialExpiresOn": "2026-11-05",
            "trialClassesUsed": 1,
            "trialClassesLimit": 1,
            "notes": "string",
            "createdOn": 1793836800,
            "lossReason": "string",
            "isLead": false,
            "isActive": false,
            "photoStorageKey": "string",
            "joinedOn": "2026-11-05",
            "convertedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "gender": "male",
            "address": "string",
            "suburb": "string",
            "postcode": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "firstName": "string",
            "lastName": "string",
            "emailAddress": "string",
            "phoneNumber": "string",
            "mobileNumber": "string",
            "referralSource": "string",
            "referredOn": "2026-11-05",
            "stageId": 1,
            "temperature": "hot",
            "temperatureOverride": 1,
            "daysInStage": 1,
            "lastContactDate": 1793836800,
            "lastContactMethod": "string",
            "reminderDate": "2026-11-05",
            "reminderOverdue": false,
            "isTrial": false,
            "trialExpiresOn": "2026-11-05",
            "trialClassesUsed": 1,
            "trialClassesLimit": 1,
            "notes": "string",
            "createdOn": 1793836800,
            "lossReason": "string",
            "isLead": false,
            "isActive": false,
            "photoStorageKey": "string",
            "joinedOn": "2026-11-05",
            "convertedOn": "2026-11-05",
            "birthday": "2026-11-05",
            "gender": "male",
            "address": "string",
            "suburb": "string",
            "postcode": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "temperatureOverride": {
          "type": "integer",
          "description": "1=hot (green), 2=warm (amber), 3=cold (red), null=auto-calculate from recency and stage",
          "enum": [
           1,
           2,
           3
          ]
         }
        }
       },
       "example": {
        "temperatureOverride": 1
       }
      }
     }
    }
   }
  },
  "/v1/leads/{id}/activities": {
   "get": {
    "operationId": "leads_listActivities",
    "summary": "listActivities",
    "description": "Paginated activity timeline for a lead (newest first). Includes contact notes, stage changes, trial events, and system-generated entries.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/leads.LeadActivity"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "studentId": 1,
           "type": "note",
           "method": "phone",
           "contactDate": 1,
           "fromStageId": 1,
           "toStageId": 1,
           "fromStageName": "string",
           "toStageName": "string",
           "notes": "string",
           "createdBy": 1,
           "createdOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (default: 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 20, max: 100)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "leads_createActivity",
    "summary": "createActivity",
    "description": "Add a contact note to the activity timeline. Only type \"note\" can be manually created; other types are system-generated.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/leads.LeadActivity"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "type": "note",
            "method": "phone",
            "contactDate": 1,
            "fromStageId": 1,
            "toStageId": 1,
            "fromStageName": "string",
            "toStageName": "string",
            "notes": "string",
            "createdBy": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "type": "note",
            "method": "phone",
            "contactDate": 1,
            "fromStageId": 1,
            "toStageId": 1,
            "fromStageName": "string",
            "toStageName": "string",
            "notes": "string",
            "createdBy": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "type": {
          "type": "string",
          "description": "Activity type (only \"note\" for manual creation)",
          "enum": [
           "note"
          ]
         },
         "method": {
          "type": "string",
          "description": "Contact method used",
          "enum": [
           "phone",
           "email",
           "in_person",
           "sms",
           "other"
          ]
         },
         "contactDate": {
          "type": "integer",
          "description": "Unix timestamp of contact (defaults to now)"
         },
         "notes": {
          "type": "string",
          "description": "Note content",
          "maxLength": 5000
         }
        },
        "required": [
         "type",
         "notes"
        ]
       },
       "example": {
        "type": "note",
        "notes": "string"
       }
      }
     }
    }
   }
  },
  "/v1/leads/{id}/activities/{activityId}": {
   "patch": {
    "operationId": "leads_updateActivity",
    "summary": "updateActivity",
    "description": "Edit a note's text content",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/leads.LeadActivity"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "type": "note",
            "method": "phone",
            "contactDate": 1,
            "fromStageId": 1,
            "toStageId": 1,
            "fromStageName": "string",
            "toStageName": "string",
            "notes": "string",
            "createdBy": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "studentId": 1,
            "type": "note",
            "method": "phone",
            "contactDate": 1,
            "fromStageId": 1,
            "toStageId": 1,
            "fromStageName": "string",
            "toStageName": "string",
            "notes": "string",
            "createdBy": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "activityId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "notes": {
          "type": "string",
          "description": "Updated note content",
          "maxLength": 5000
         }
        },
        "required": [
         "notes"
        ]
       },
       "example": {
        "notes": "string"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "leads_deleteActivity",
    "summary": "deleteActivity",
    "description": "Soft-delete an activity from the timeline",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "activityId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/leads/follow-ups": {
   "get": {
    "operationId": "leads_listFollowUps",
    "summary": "listFollowUps",
    "description": "The follow-up task list: active reminders across live leads, ordered by due date, overdue always included. range scopes the horizon (today | week | month | all).",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "range",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "today",
        "week",
        "month",
        "all"
       ],
       "default": "today"
      },
      "description": "Due-date horizon (default today). Overdue items appear in every range."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/leads/{id}/reminder": {
   "get": {
    "operationId": "leads_getReminder",
    "summary": "getReminder",
    "description": "Get the active reminder for a lead. Returns null data if no reminder is set.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/leads.Reminder"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "date": "2026-11-05",
          "overdue": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "put": {
    "operationId": "leads_setReminder",
    "summary": "setReminder",
    "description": "Set or replace the active reminder. Clears any existing reminder first. Pass null to clear without setting a new one.",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/leads.Reminder"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "date": "2026-11-05",
            "overdue": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "date": "2026-11-05",
            "overdue": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "reminderDate": {
          "type": "string",
          "description": "Follow-up day (YYYY-MM-DD), or null to clear the reminder. Legacy unix-seconds numbers are also accepted.",
          "format": "date"
         }
        },
        "required": [
         "reminderDate"
        ]
       },
       "example": {
        "reminderDate": "2026-11-05"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "leads_deleteReminder",
    "summary": "deleteReminder",
    "description": "Clear the active reminder for a lead",
    "tags": [
     "leads"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/onetouch/forms/signups": {
   "get": {
    "operationId": "onetouch_listOtsuSignups",
    "summary": "listOtsuSignups",
    "description": "The students who signed up through OTSU forms, newest first: name, contact, sign-up date, current status and plan. Filter by formId and a from/to range (unix seconds). Paginated. An API key needs students:read or leads:read as well as settings:read: the answer carries people's details.",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "formId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "One form; omit for every form"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Signed up at or after (unix seconds)"
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Signed up at or before (unix seconds)"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "Page number, from 1"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 100
      },
      "description": "Rows per page, max 200"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/onetouch/forms/signups/export": {
   "get": {
    "operationId": "onetouch_exportOtsuSignups",
    "summary": "exportOtsuSignups",
    "description": "The same sign-ups as listOtsuSignups as one CSV: every row that matches the filters, not one page. Columns: date (school's zone), first name, last name, phone, email, status, plan, form. An API key needs students:read or leads:read as well as settings:read: the answer carries people's details.",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "formId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "One form; omit for every form"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Signed up at or after (unix seconds)"
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Signed up at or before (unix seconds)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/onetouch/checkouts/{id}/orders": {
   "get": {
    "operationId": "onetouch_listCheckoutOrders",
    "summary": "listCheckoutOrders",
    "description": "The orders behind one checkout, newest first: buyer, lines (product, option, quantity, unit price; the event ticket as its own line), total, status, and the shop order the product lines became. Every order except failed by default; a status narrows to that status alone. Paginated. An API key needs students:read or leads:read as well as settings:read: the answer carries people's details.",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "completed",
        "processing",
        "pending",
        "failed",
        "expired"
       ]
      },
      "description": "One status alone; omit for every order except failed"
     },
     {
      "name": "guest",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Only orders with no student: migrated guest orders still to attach"
     },
     {
      "name": "placedFrom",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Placed on or after this day (YYYY-MM-DD), the school's day"
     },
     {
      "name": "placedTo",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Placed on or before this day (YYYY-MM-DD), the school's day"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "Page number, from 1"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Rows per page, max 200"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/onetouch/checkouts/{id}/orders.csv": {
   "get": {
    "operationId": "onetouch_exportCheckoutOrders",
    "summary": "exportCheckoutOrders",
    "description": "The same orders as a CSV picking slip: order, date, name, email, phone, the lines as text, total, currency, status. An API key needs students:read or leads:read as well as settings:read: the answer carries people's details.",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "completed",
        "processing",
        "pending",
        "failed",
        "expired"
       ]
      },
      "description": "One status alone; omit for every order except failed"
     },
     {
      "name": "guest",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Only orders with no student"
     },
     {
      "name": "placedFrom",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Placed on or after this day (YYYY-MM-DD), the school's day"
     },
     {
      "name": "placedTo",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Placed on or before this day (YYYY-MM-DD), the school's day"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/onetouch/orders/{orderId}": {
   "get": {
    "operationId": "onetouch_getCheckoutOrder",
    "summary": "getCheckoutOrder",
    "description": "One checkout order in full: buyer, lines, total, status, its transaction, its event booking, the waiver signature it carries, whether a migrated guest order still holds an unrecorded signature, and emailMatches, the students already holding a guest buyer's email. An API key needs students:read or leads:read as well as settings:read: the answer carries people's details.",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/onetouch/orders/{orderId}/attach": {
   "post": {
    "operationId": "onetouch_attachCheckoutOrder",
    "summary": "attachCheckoutOrder",
    "description": "Attach a migrated guest order (no student) to an existing student: re-points the order, its ledger rows, its bookings and its shop order where no student is set, records the signature the order carries, and reports any row that already named someone else. 409 when the order already has a student. An API key needs billing:write as well as settings:write.",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "integer",
          "description": "The student to attach the order to"
         }
        },
        "required": [
         "studentId"
        ]
       },
       "example": {
        "studentId": 1
       }
      }
     }
    }
   }
  },
  "/v1/onetouch/orders/{orderId}/add-lead": {
   "post": {
    "operationId": "onetouch_addLeadFromCheckoutOrder",
    "summary": "addLeadFromCheckoutOrder",
    "description": "Add a migrated guest order's buyer as a lead from the name, email and phone the order carries, then attach the order to them. A student already holding that email is reused unless forceNew. 412 when the order carries no buyer email. An API key needs leads:write or students:write as well as settings:write.",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "orderId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "forceNew": {
          "type": "boolean",
          "description": "Create a new lead even when a student already holds the buyer's email (the detail's emailMatches)",
          "default": false
         }
        }
       },
       "example": {
        "forceNew": false
       }
      }
     }
    }
   }
  },
  "/v1/onetouch/attempts": {
   "get": {
    "operationId": "onetouch_listSignupAttempts",
    "summary": "listSignupAttempts",
    "description": "Recent reCAPTCHA challenges and rejections on this school's public signup form and lead widget: stage, decision, score, error codes, browser, the typed name and email, and the reference code the person was shown. Passes are not recorded. An API key needs students:read or leads:read as well as settings:read: the answer carries people's details.",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {}
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "days",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Look-back window in days (1-90). Default 30."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/onetouch/forms": {
   "get": {
    "operationId": "onetouch_listForms",
    "summary": "listForms",
    "description": "List all OTSU signup forms for the school",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/onetouch.OtsuForm"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "headline": "string",
           "intro": "string",
           "colour": "string",
           "fee": 1,
           "notifications": false,
           "studentType": "student",
           "hash": "string",
           "publicUrl": "string",
           "createdOn": 1,
           "styles": [],
           "venues": [],
           "plans": [],
           "waivers": [],
           "items": [],
           "registrationCount": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Search by form name"
     },
     {
      "name": "includeDeleted",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Include soft-deleted forms"
     },
     {
      "name": "studentType",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "student",
        "lead",
        "trial"
       ]
      },
      "description": "Filter by student type"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "onetouch_createForm",
    "summary": "createForm",
    "description": "Create a new OTSU signup form",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/onetouch.OtsuForm"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "headline": "string",
            "intro": "string",
            "colour": "string",
            "fee": 1,
            "notifications": false,
            "studentType": "student",
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "styles": [],
            "venues": [],
            "plans": [],
            "waivers": [],
            "items": [],
            "registrationCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "headline": "string",
            "intro": "string",
            "colour": "string",
            "fee": 1,
            "notifications": false,
            "studentType": "student",
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "styles": [],
            "venues": [],
            "plans": [],
            "waivers": [],
            "items": [],
            "registrationCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Form name (must be unique)",
          "maxLength": 500
         },
         "headline": {
          "type": "string",
          "description": "Form headline text",
          "maxLength": 1000
         },
         "intro": {
          "type": "string",
          "description": "Introduction/description text",
          "maxLength": 2500
         },
         "colour": {
          "type": "string",
          "description": "Brand colour as hex code (e.g. #1F7F5C)",
          "pattern": "^#[0-9A-Fa-f]{6}$"
         },
         "fee": {
          "type": "integer",
          "description": "Registration fee in cents (0 = free)",
          "minimum": 0
         },
         "notifications": {
          "type": "boolean",
          "description": "Send email notifications on signup",
          "default": false
         },
         "studentType": {
          "type": "string",
          "description": "Type of student record to create",
          "enum": [
           "student",
           "lead",
           "trial"
          ],
          "default": "student"
         },
         "styleIds": {
          "type": "array",
          "description": "Style IDs to link to this form",
          "items": {
           "type": "integer"
          }
         },
         "venueIds": {
          "type": "array",
          "description": "Venue IDs to link to this form",
          "items": {
           "type": "integer"
          }
         },
         "planIds": {
          "type": "array",
          "description": "Billing plan IDs to offer on this form",
          "items": {
           "type": "integer"
          }
         },
         "waiverIds": {
          "type": "array",
          "description": "Waiver IDs to require on this form",
          "items": {
           "type": "integer"
          }
         },
         "items": {
          "type": "array",
          "description": "Shop items offered with sign-up (uniforms, starter packs), one entry per product. Each: {productId, optionIds (the sizes to offer, options of that product; see listShopProducts), included (true = free with sign-up; false = the option's shop price is added to the first payment with the fee), required (true = a size must be picked to finish)}. An out-of-stock size can still be picked: stock goes below zero and the order is marked back-ordered.",
          "items": {
           "type": "object",
           "properties": {
            "productId": {
             "type": "integer"
            },
            "optionIds": {
             "type": "array",
             "items": {
              "type": "integer"
             }
            },
            "included": {
             "type": "boolean"
            },
            "required": {
             "type": "boolean"
            }
           },
           "required": [
            "productId",
            "optionIds",
            "included",
            "required"
           ]
          }
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/onetouch/forms/{id}": {
   "get": {
    "operationId": "onetouch_getForm",
    "summary": "getForm",
    "description": "Get a single OTSU form with related styles, venues, plans, and waivers",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/onetouch.OtsuForm"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "headline": "string",
          "intro": "string",
          "colour": "string",
          "fee": 1,
          "notifications": false,
          "studentType": "student",
          "hash": "string",
          "publicUrl": "string",
          "createdOn": 1,
          "styles": [],
          "venues": [],
          "plans": [],
          "waivers": [],
          "items": [],
          "registrationCount": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "onetouch_updateForm",
    "summary": "updateForm",
    "description": "Update an existing OTSU form. Junction arrays (styleIds, venueIds, etc.) replace all existing links when provided.",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/onetouch.OtsuForm"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "headline": "string",
            "intro": "string",
            "colour": "string",
            "fee": 1,
            "notifications": false,
            "studentType": "student",
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "styles": [],
            "venues": [],
            "plans": [],
            "waivers": [],
            "items": [],
            "registrationCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "headline": "string",
            "intro": "string",
            "colour": "string",
            "fee": 1,
            "notifications": false,
            "studentType": "student",
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "styles": [],
            "venues": [],
            "plans": [],
            "waivers": [],
            "items": [],
            "registrationCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Form name (must be unique)",
          "maxLength": 500
         },
         "headline": {
          "type": "string",
          "description": "Form headline text",
          "maxLength": 1000
         },
         "intro": {
          "type": "string",
          "description": "Introduction/description text",
          "maxLength": 2500
         },
         "colour": {
          "type": "string",
          "description": "Brand colour as hex code",
          "pattern": "^#[0-9A-Fa-f]{6}$"
         },
         "fee": {
          "type": "integer",
          "description": "Registration fee in cents",
          "minimum": 0
         },
         "notifications": {
          "type": "boolean",
          "description": "Send email notifications on signup"
         },
         "studentType": {
          "type": "string",
          "description": "Type of student record to create",
          "enum": [
           "student",
           "lead",
           "trial"
          ]
         },
         "styleIds": {
          "type": "array",
          "description": "Replace linked styles",
          "items": {
           "type": "integer"
          }
         },
         "venueIds": {
          "type": "array",
          "description": "Replace linked venues",
          "items": {
           "type": "integer"
          }
         },
         "planIds": {
          "type": "array",
          "description": "Replace linked plans",
          "items": {
           "type": "integer"
          }
         },
         "waiverIds": {
          "type": "array",
          "description": "Replace linked waivers",
          "items": {
           "type": "integer"
          }
         },
         "items": {
          "type": "array",
          "description": "Shop items offered with sign-up (uniforms, starter packs), one entry per product. Each: {productId, optionIds (the sizes to offer, options of that product; see listShopProducts), included (true = free with sign-up; false = the option's shop price is added to the first payment with the fee), required (true = a size must be picked to finish)}. An out-of-stock size can still be picked: stock goes below zero and the order is marked back-ordered. Replaces every item when provided.",
          "items": {
           "type": "object",
           "properties": {
            "productId": {
             "type": "integer"
            },
            "optionIds": {
             "type": "array",
             "items": {
              "type": "integer"
             }
            },
            "included": {
             "type": "boolean"
            },
            "required": {
             "type": "boolean"
            }
           },
           "required": [
            "productId",
            "optionIds",
            "included",
            "required"
           ]
          }
         }
        }
       },
       "example": {
        "name": "string",
        "headline": "string",
        "intro": "string",
        "colour": "#1F7F5C",
        "fee": 1,
        "notifications": false,
        "studentType": "student",
        "styleIds": [
         1
        ],
        "venueIds": [
         1
        ],
        "planIds": [
         1
        ],
        "waiverIds": [
         1
        ],
        "items": [
         {
          "productId": 1,
          "optionIds": [
           1
          ],
          "included": false,
          "required": false
         }
        ]
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "onetouch_deleteForm",
    "summary": "deleteForm",
    "description": "Soft-delete an OTSU form. Returns cascade effects (e.g. registration count).",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/onetouch/forms/{id}/duplicate": {
   "post": {
    "operationId": "onetouch_duplicateForm",
    "summary": "duplicateForm",
    "description": "Duplicate an OTSU form with all its linked styles, venues, plans, and waivers",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/onetouch.OtsuForm"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "headline": "string",
            "intro": "string",
            "colour": "string",
            "fee": 1,
            "notifications": false,
            "studentType": "student",
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "styles": [],
            "venues": [],
            "plans": [],
            "waivers": [],
            "items": [],
            "registrationCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "headline": "string",
            "intro": "string",
            "colour": "string",
            "fee": 1,
            "notifications": false,
            "studentType": "student",
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "styles": [],
            "venues": [],
            "plans": [],
            "waivers": [],
            "items": [],
            "registrationCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Name for the duplicate (defaults to 'Copy of <original>')"
         }
        }
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/onetouch/forms/report": {
   "get": {
    "operationId": "onetouch_getFormReport",
    "summary": "getFormReport",
    "description": "Get OTSU signup report data grouped by weekly or monthly time periods",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/onetouch.OtsuReport"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "periods": [],
          "total": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Start date as Unix timestamp (defaults to 12 weeks ago). Also accepted as startDate."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "End date as Unix timestamp (defaults to now). Also accepted as endDate."
     },
     {
      "name": "aggregation",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "weekly",
        "monthly"
       ],
       "default": "weekly"
      },
      "description": "Time period grouping"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/onetouch/checkouts": {
   "get": {
    "operationId": "onetouch_listCheckouts",
    "summary": "listCheckouts",
    "description": "List all OTCO checkout pages for the school",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/onetouch.OtcoCheckout"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "copy": "string",
           "hero": "string",
           "studentType": "student",
           "notifications": false,
           "hash": "string",
           "publicUrl": "string",
           "createdOn": 1,
           "event": {},
           "products": [],
           "orderCount": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Search by checkout name"
     },
     {
      "name": "includeDeleted",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Include soft-deleted checkouts"
     },
     {
      "name": "eventId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by linked event ID"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "onetouch_createCheckout",
    "summary": "createCheckout",
    "description": "Create a new OTCO checkout page",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/onetouch.OtcoCheckout"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "copy": "string",
            "hero": "string",
            "studentType": "student",
            "notifications": false,
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "event": {},
            "products": [],
            "orderCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "copy": "string",
            "hero": "string",
            "studentType": "student",
            "notifications": false,
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "event": {},
            "products": [],
            "orderCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Checkout name (must be unique)",
          "maxLength": 500
         },
         "copy": {
          "type": "string",
          "description": "Description/copy text",
          "maxLength": 1000
         },
         "hero": {
          "type": "string",
          "description": "Hero image URL",
          "maxLength": 500,
          "format": "uri"
         },
         "eventId": {
          "type": "integer",
          "description": "Link to an event"
         },
         "studentType": {
          "type": "string",
          "description": "What a NEW buyer becomes. Defaults to lead (a checkout buyer is a prospect); existing students are matched by email and reused untouched",
          "enum": [
           "student",
           "lead",
           "trial"
          ],
          "default": "lead"
         },
         "notifications": {
          "type": "boolean",
          "description": "Send email notifications on purchase",
          "default": false
         },
         "collectCardWhenFree": {
          "type": "boolean",
          "description": "Still collect card details (saved, not charged) when the order is free, e.g. a free event ticket",
          "default": false
         },
         "productOptionIds": {
          "type": "array",
          "description": "Product option IDs to include on this checkout",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/onetouch/checkouts/{id}": {
   "get": {
    "operationId": "onetouch_getCheckout",
    "summary": "getCheckout",
    "description": "Get a single OTCO checkout with linked event and product options",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/onetouch.OtcoCheckout"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "copy": "string",
          "hero": "string",
          "studentType": "student",
          "notifications": false,
          "hash": "string",
          "publicUrl": "string",
          "createdOn": 1,
          "event": {},
          "products": [],
          "orderCount": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "onetouch_updateCheckout",
    "summary": "updateCheckout",
    "description": "Update an existing OTCO checkout. productOptionIds replaces all existing links when provided.",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/onetouch.OtcoCheckout"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "copy": "string",
            "hero": "string",
            "studentType": "student",
            "notifications": false,
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "event": {},
            "products": [],
            "orderCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "copy": "string",
            "hero": "string",
            "studentType": "student",
            "notifications": false,
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "event": {},
            "products": [],
            "orderCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Checkout name (must be unique)",
          "maxLength": 500
         },
         "copy": {
          "type": "string",
          "description": "Description/copy text",
          "maxLength": 1000
         },
         "hero": {
          "type": "string",
          "description": "Hero image URL",
          "maxLength": 500,
          "format": "uri"
         },
         "eventId": {
          "type": "integer",
          "description": "Link to an event"
         },
         "studentType": {
          "type": "string",
          "description": "What a NEW buyer becomes; existing students are matched by email and reused untouched",
          "enum": [
           "student",
           "lead",
           "trial"
          ]
         },
         "notifications": {
          "type": "boolean",
          "description": "Send email notifications on purchase"
         },
         "collectCardWhenFree": {
          "type": "boolean",
          "description": "Still collect card details when the order is free"
         },
         "productOptionIds": {
          "type": "array",
          "description": "Replace linked product options",
          "items": {
           "type": "integer"
          }
         }
        }
       },
       "example": {
        "name": "string",
        "copy": "string",
        "hero": "https://example.com",
        "eventId": 1,
        "studentType": "student",
        "notifications": false,
        "collectCardWhenFree": false,
        "productOptionIds": [
         1
        ]
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "onetouch_deleteCheckout",
    "summary": "deleteCheckout",
    "description": "Soft-delete an OTCO checkout. Returns cascade effects (e.g. order count).",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/onetouch/checkouts/{id}/duplicate": {
   "post": {
    "operationId": "onetouch_duplicateCheckout",
    "summary": "duplicateCheckout",
    "description": "Duplicate an OTCO checkout with all its linked product options",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/onetouch.OtcoCheckout"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "copy": "string",
            "hero": "string",
            "studentType": "student",
            "notifications": false,
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "event": {},
            "products": [],
            "orderCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "copy": "string",
            "hero": "string",
            "studentType": "student",
            "notifications": false,
            "hash": "string",
            "publicUrl": "string",
            "createdOn": 1,
            "event": {},
            "products": [],
            "orderCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Name for the duplicate (defaults to 'Copy of <original>')"
         }
        }
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/onetouch/checkouts/report": {
   "get": {
    "operationId": "onetouch_getCheckoutReport",
    "summary": "getCheckoutReport",
    "description": "Get OTCO checkout report data grouped by weekly or monthly time periods",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/onetouch.OtcoReport"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "periods": [],
          "total": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Start date as Unix timestamp (defaults to 12 weeks ago). Also accepted as startDate."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "End date as Unix timestamp (defaults to now). Also accepted as endDate."
     },
     {
      "name": "aggregation",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "weekly",
        "monthly"
       ],
       "default": "weekly"
      },
      "description": "Time period grouping"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/onetouch/shop-products": {
   "get": {
    "operationId": "onetouch_listShopProducts",
    "summary": "listShopProducts",
    "description": "List shop products grouped by category (for OTCO product option selection UI)",
    "tags": [
     "onetouch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/onetouch.ShopProductCategory"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "categoryId": 1,
           "categoryName": "string",
           "products": []
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/widgets": {
   "get": {
    "operationId": "widgets_get",
    "summary": "get",
    "description": "Get widget settings and embed-code payloads (URL + iframe) for both widgets in a single call. Includes legacy MD5 URLs for support reference.",
    "tags": [
     "widgets"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/widgets.WidgetsPayload"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "settings": {
           "leadRecipientEmail": "jo@example.com",
           "bookingRecipientEmail": "jo@example.com",
           "leadRedirectUrl": "https://example.com",
           "accentColor": "1F7F5C",
           "darkThemeDefault": false,
           "allowedOrigins": [
            "string"
           ],
           "shopEnabled": false,
           "shopMemberDirectDebit": false,
           "shopFulfillment": "pickup_only",
           "shopShippingFeeCents": 1,
           "shopLowStockThreshold": 1
          },
          "embeds": {
           "leads": {},
           "bookings": {},
           "shop": {}
          }
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "widgets_update",
    "summary": "update",
    "description": "Update one or more widget settings. Only fields included in the body are written. Allowed-origins changes take effect within seconds.",
    "tags": [
     "widgets"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/widgets.WidgetSettings"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "leadRecipientEmail": "jo@example.com",
            "bookingRecipientEmail": "jo@example.com",
            "leadRedirectUrl": "https://example.com",
            "accentColor": "1F7F5C",
            "darkThemeDefault": false,
            "allowedOrigins": [
             "string"
            ],
            "shopEnabled": false,
            "shopMemberDirectDebit": false,
            "shopFulfillment": "pickup_only",
            "shopShippingFeeCents": 1,
            "shopLowStockThreshold": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "leadRecipientEmail": "jo@example.com",
            "bookingRecipientEmail": "jo@example.com",
            "leadRedirectUrl": "https://example.com",
            "accentColor": "1F7F5C",
            "darkThemeDefault": false,
            "allowedOrigins": [
             "string"
            ],
            "shopEnabled": false,
            "shopMemberDirectDebit": false,
            "shopFulfillment": "pickup_only",
            "shopShippingFeeCents": 1,
            "shopLowStockThreshold": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "leadRecipientEmail": {
          "type": "string",
          "description": "Email address that receives new lead notifications. Pass null to disable.",
          "format": "email"
         },
         "bookingRecipientEmail": {
          "type": "string",
          "description": "Email address that receives the school's booking emails (new booking, waitlist, capacity enquiry). Pass null to use the primary account's email.",
          "format": "email"
         },
         "leadRedirectUrl": {
          "type": "string",
          "description": "URL to redirect to after a successful lead submission. Pass null to show the built-in thank-you screen.",
          "format": "url"
         },
         "accentColor": {
          "type": "string",
          "description": "Widget-specific accent (overrides school primary). Hex with leading #, e.g. '#1F7F5C'. Pass null to fall back to school branding.",
          "pattern": "^#[0-9a-fA-F]{6}$",
          "format": "hex-color"
         },
         "darkThemeDefault": {
          "type": "boolean",
          "description": "Default the widget to dark theme on first load."
         },
         "allowedOrigins": {
          "type": "array",
          "description": "Origins (scheme + host, no path) that may embed the widget via iframe. Drives Content-Security-Policy frame-ancestors. Max 20.",
          "items": {
           "type": "string",
           "format": "url"
          }
         },
         "shopEnabled": {
          "type": "boolean",
          "description": "Master switch for the public Shop widget. False hides the storefront and rejects /v1/public/widgets/shop traffic."
         },
         "shopFulfillment": {
          "type": "string",
          "description": "How shop orders are fulfilled. 'pickup_only' (default) limits checkout to in-store pickup at a venue; 'shipping_pickup' adds a flat-shipping option.",
          "enum": [
           "pickup_only",
           "shipping_pickup"
          ]
         },
         "shopShippingFeeCents": {
          "type": "number",
          "description": "Flat shipping fee in cents applied at checkout when fulfillment is 'shipping_pickup'. Ignored otherwise."
         },
         "shopLowStockThreshold": {
          "type": "number",
          "description": "Show 'Only N left' on product cards when stock is at or below this number. 0 disables the badge entirely. Default 5."
         }
        }
       },
       "example": {
        "leadRecipientEmail": "jo@example.com",
        "bookingRecipientEmail": "jo@example.com",
        "leadRedirectUrl": "https://example.com",
        "accentColor": "#1F7F5C",
        "darkThemeDefault": false,
        "allowedOrigins": [
         "https://example.com"
        ],
        "shopEnabled": false,
        "shopFulfillment": "pickup_only",
        "shopShippingFeeCents": 1,
        "shopLowStockThreshold": 1
       }
      }
     }
    }
   }
  },
  "/v1/widgets/send-instructions": {
   "post": {
    "operationId": "widgets_sendInstructions",
    "summary": "sendInstructions",
    "description": "Email the iframe embed code (and optional message) to a webmaster contact. Used when a school owner wants to hand off install to a developer.",
    "tags": [
     "widgets"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "email": {
          "type": "string",
          "description": "Recipient email (the webmaster).",
          "format": "email"
         },
         "widget": {
          "type": "string",
          "description": "Which widget's embed code to send.",
          "enum": [
           "leads",
           "bookings",
           "shop"
          ]
         },
         "message": {
          "type": "string",
          "description": "Optional personal note prepended to the email body.",
          "maxLength": 2000
         }
        },
        "required": [
         "email",
         "widget"
        ]
       },
       "example": {
        "email": "jo@example.com",
        "widget": "leads"
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/nudges": {
   "get": {
    "operationId": "dashboard_getNudges",
    "summary": "getNudges",
    "description": "Get aggregated nudge items across all 5 categories (payments, retention, leads, milestones, admin). Results are filtered by the current user's snooze/dismiss preferences. An API key needs students:read as well as reports:read: the list names students.",
    "tags": [
     "dashboard"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/dashboard.NudgesResponse"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "categories": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/dashboard/nudges/{nudgeId}/snooze": {
   "post": {
    "operationId": "dashboard_snoozeNudge",
    "summary": "snoozeNudge",
    "description": "Snooze a nudge for a given duration. The nudge will reappear after the snooze period expires.",
    "tags": [
     "dashboard"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/dashboard.SnoozeResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "nudgeId": "string",
            "snoozed": false,
            "duration": "1d"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "nudgeId": "string",
            "snoozed": false,
            "duration": "1d"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "nudgeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "duration": {
          "type": "string",
          "description": "Snooze duration (1 day, 7 days, or 30 days)",
          "enum": [
           "1d",
           "7d",
           "30d"
          ]
         }
        },
        "required": [
         "duration"
        ]
       },
       "example": {
        "duration": "1d"
       }
      }
     }
    }
   }
  },
  "/v1/dashboard/nudges/{nudgeId}/dismiss": {
   "post": {
    "operationId": "dashboard_dismissNudge",
    "summary": "dismissNudge",
    "description": "Permanently dismiss a nudge. It will not reappear for this user.",
    "tags": [
     "dashboard"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/dashboard.DismissResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "nudgeId": "string",
            "dismissed": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "nudgeId": "string",
            "dismissed": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "nudgeId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/dashboard/stats": {
   "get": {
    "operationId": "dashboard_getStats",
    "summary": "getStats",
    "description": "Rolling 30-day student lifecycle KPIs (active students, current trials, new students, churned students, net change) with prior-period comparison for trend arrows.",
    "tags": [
     "dashboard"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/dashboard.StudentStats"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "activeStudents": {},
          "currentTrials": {},
          "newStudents": {},
          "churnedStudents": {},
          "netChange": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/dashboard/stats/{category}/students": {
   "get": {
    "operationId": "dashboard_getStatCardStudents",
    "summary": "getStatCardStudents",
    "description": "The students behind a stats card. Categories: trials (every current trial), new (joined in the rolling 30 days), churned (deactivated in the rolling 30 days), net (new + churned combined, each row tagged with its side). Lists match the card counts exactly; active students has no drill-down. An API key needs students:read as well as reports:read.",
    "tags": [
     "dashboard"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/dashboard.StatCardStudents"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "category": "trials",
          "students": [],
          "total": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "category",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/dashboard/upcoming-classes/calendar": {
   "get": {
    "operationId": "dashboard_getUpcomingClassesCalendar",
    "summary": "getUpcomingClassesCalendar",
    "description": "Calendar heat map data for a month. Returns total expected attendees per day. Supports filtering by venue, style, and notable-only.",
    "tags": [
     "dashboard"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/dashboard.CalendarHeatMap"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "days": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "month",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Month in YYYY-MM format (defaults to current month)"
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by venue ID"
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by style ID"
     },
     {
      "name": "notableOnly",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "true",
        "false"
       ]
      },
      "description": "Only include days with trial/lead students"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/dashboard/upcoming-classes/day": {
   "get": {
    "operationId": "dashboard_getUpcomingClassesDay",
    "summary": "getUpcomingClassesDay",
    "description": "Day detail with individual class occurrences and notable students (trials, leads). Supports filtering by venue, style, and notable-only.",
    "tags": [
     "dashboard"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/dashboard.DayDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "occurrences": [
           {
            "eventId": 1,
            "eventName": "string",
            "eventType": "single",
            "startTime": 1,
            "endTime": 1,
            "venueId": 1,
            "venueName": "string",
            "capacity": 1,
            "enrolledCount": 1,
            "bookedCount": 1,
            "nearFull": false,
            "ranks": [],
            "notableStudents": []
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "date",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Day (YYYY-MM-DD). Defaults to today."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by venue ID"
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by style ID"
     },
     {
      "name": "notableOnly",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "true",
        "false"
       ]
      },
      "description": "Only include occurrences with trial/lead students"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/overview": {
   "get": {
    "operationId": "reports_overview",
    "summary": "overview",
    "description": "Read the cached overview payload for the current school. Returns `{ status: 'ready', payload, computedAt, snapshotVersion }` when a snapshot exists, or `{ status: 'pending', reason }` when the worker hasn't generated one yet.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.OverviewResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "ready",
          "payload": {},
          "computedAt": 1,
          "snapshotVersion": "string",
          "reason": "no_snapshot_yet"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/ai/first-look": {
   "post": {
    "operationId": "reports_postAiFirstLook",
    "summary": "postAiFirstLook",
    "description": "Fire-and-poll: enqueue an on-demand AI insight run when the cached snapshot has no AI block or has only a transient login-gate skip (no_recent_login / login_too_old). Server decides eligibility; client polls /overview for the result. No request body. schoolId comes from auth.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.FirstLookEnqueueResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "enqueued",
          "jobId": "string",
          "reason": "no_snapshot"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/reports/growth/detail": {
   "get": {
    "operationId": "reports_growthDetail",
    "summary": "growthDetail",
    "description": "Growth lens detail (funnel, cohort grid, per-venue splits). Ships in Phase 1.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.PendingDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "pending",
          "availableInPhase": "string",
          "message": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Start of date range (YYYY-MM-DD, school timezone)."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "End of date range (YYYY-MM-DD, school timezone)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/growth/trend": {
   "get": {
    "operationId": "reports_growthTrend",
    "summary": "growthTrend",
    "description": "Growth cohorts by period, live, for when ribbon filters are set (unfiltered charts read the snapshot's growth_monthly_cohorts block). Per bucket: new active/trials/leads, churned, leadsLost, and point-in-time totalActive. Uses the snapshot's cohort logic, so the two agree. A venue narrows to students enrolled at that venue.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.GrowthCohortsResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "cohorts": [],
          "totalActiveMomPct": 1,
          "from": 1,
          "to": 1,
          "granularity": "month"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Ribbon range start (YYYY-MM-DD, school tz). Omit for the default trailing window (12mo / 13wk / 30d)."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Ribbon range end (YYYY-MM-DD). Becomes the end-of-day-in-tz anchor; omit to anchor at now."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow."
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional styles.id narrow (ribbon Style filter). Plans restricted to the style count; unrestricted plans follow the student's enrolled styles."
     },
     {
      "name": "granularity",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "month",
        "week",
        "day"
       ],
       "default": "month"
      },
      "description": "Bucket cadence."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/growth/cohort": {
   "get": {
    "operationId": "reports_growthCohort",
    "summary": "growthCohort",
    "description": "Drill-down behind a clicked Growth bar: the students whose lifecycle event lands in the bucket [from, to), each tagged with its segment (active/trials/leads/churned/leadsLost), plus per-segment counts that reconcile with the bar. A student can appear under multiple segments for one period.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Bucket start in unix seconds (inclusive). The frontend resolves the period key + granularity to tz-anchored bounds matching how the bar was bucketed."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Bucket end in unix seconds (exclusive)."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow (mirrors the ribbon venue scope so the drill-down matches a venue-filtered bar)."
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional styles.id narrow (ribbon Style filter). Plans restricted to the style count; unrestricted plans follow the student's enrolled styles."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/growth/trials": {
   "get": {
    "operationId": "reports_growthTrials",
    "summary": "growthTrials",
    "description": "Growth (GTM lens) trial performance: the activation cliff (completed trials bucketed by classes attended during the trial, with conversion rate per bucket), lifecycle counts (in-flight / expiring-soon / recently converted / recently expired), and an expiring-trial worklist. School-scoped. Returns hasData=false when the school has no trial history.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/growth/conversion": {
   "get": {
    "operationId": "reports_growthConversion",
    "summary": "growthConversion",
    "description": "Growth (GTM lens) conversion trends: cohort-based lead->trial, trial->member, and lead->member rates per month over the trailing 12 months. Each prospect belongs to the month it entered the funnel (COALESCE(referred_on, created_on)) and is followed to outcome; immature recent cohorts are flagged (mature=false) and excluded from the headline rates. hasTrialData=false when no entrant started a trial (the lead->member series still renders).",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "tz",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "IANA timezone for month bucketing (defaults to Australia/Sydney)."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Narrow entrants to one venue (student_venue_enrollment)."
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Narrow entrants to one style (by the student's rank)."
     },
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds; the trailing 12-month window ends here (defaults to now)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/growth/channels": {
   "get": {
    "operationId": "reports_growthChannels",
    "summary": "growthChannels",
    "description": "Growth (GTM lens) acquisition channels + unit economics: each referral_source with prospects / members / conversion %, classified word-of-mouth vs paid vs digital, plus ARPU, LTV (ARPU / monthly churn) and, when the school's average monthly ad spend is set (Growth card cog), paid CAC (spend / paid-channel new members), blended CAC (spend / all new members), LTV:CAC, and CAC payback. Money is cents; hasSpend=false hides CAC.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/retention/survival": {
   "get": {
    "operationId": "reports_retentionSurvival",
    "summary": "retentionSurvival",
    "description": "Retention critical windows: a discrete-time (Kaplan-Meier-style) member survival curve from join/leave dates, with the worst tenure window detected by hazard (conditional drop-rate). Right-censored: a student only counts toward an interval once old enough to be observed through its end. mode=own (this school) or mode=peer (its benchmark cohort). Returns status 'insufficient' when there are too few departures to be meaningful.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "mode",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "own",
        "peer"
       ]
      },
      "description": "own = this school's members; peer = the benchmark cohort (country [+ style]) aggregated. Defaults to own."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/retention/cohorts": {
   "get": {
    "operationId": "reports_retentionCohorts",
    "summary": "retentionCohorts",
    "description": "Cohort retention grid: for each join-month cohort over the trailing year, the % of members still active at each subsequent month offset (M0..M6). Triangular (a cohort only reports offsets it is old enough to have reached).",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "tz",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "IANA timezone for join-month bucketing (defaults to Australia/Sydney)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/retention/detail": {
   "get": {
    "operationId": "reports_retentionDetail",
    "summary": "retentionDetail",
    "description": "Retention lens detail: engagement hero, risk-band summary (Critical/Warning/Watch/Healthy counts), top-50 risk register with top-3 contributing factors per student, and last-90-day lost-students post-mortem. Scores come from the active churn model.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/retention/overrides": {
   "get": {
    "operationId": "reports_churnOverrides",
    "summary": "churnOverrides",
    "description": "Live churn overrides: students staff have dismissed from the churn register, with the expiry (null = permanent). An overridden student is opted out of the nightly churn scoring entirely, so they carry no score, sit in no band and match no churn segment until the override lapses or is removed.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/reports.ChurnOverride"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "studentId": 1,
           "studentName": "string",
           "expiresOn": 1,
           "createdOn": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/retention/overrides/{studentId}": {
   "put": {
    "operationId": "reports_setChurnOverride",
    "summary": "setChurnOverride",
    "description": "Dismiss a student from the churn register: 'this student is fine, stop flagging them'. Body { expiresInDays: 30 | 90 | null }; null is permanent. Replaces any existing override for the student and deletes their current score row so the register, the Retention band histogram and the churn segments drop them immediately.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/reports.ChurnOverride"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "studentId": 1,
            "studentName": "string",
            "expiresOn": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "studentId": 1,
            "studentName": "string",
            "expiresOn": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "expiresInDays": {
          "type": "integer",
          "description": "Days until the override lapses; send null for permanent.",
          "enum": [
           30,
           90
          ]
         }
        }
       },
       "example": {
        "expiresInDays": 30
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "reports_clearChurnOverride",
    "summary": "clearChurnOverride",
    "description": "Undo a dismissal. The student is scored again on the next nightly run.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/reports/retention/register": {
   "get": {
    "operationId": "reports_riskRegister",
    "summary": "riskRegister",
    "description": "Risk-band drill-down: active students in a single risk band (or all bands when `band` is omitted), paginated and sorted, with the true total count. Same per-student shape as the detail register (score, band, top-3 factors, days since last seen).",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "band",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "healthy",
        "watch",
        "warning",
        "critical"
       ]
      },
      "description": "Optional band filter. Omit to return every scored active student. Bands map to score ranges: healthy 0-30, watch 31-50, warning 51-70, critical 71-100."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page size, 1-100. Default 50."
     },
     {
      "name": "offset",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Row offset for pagination. Default 0."
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "-score",
        "score",
        "-computed_at"
       ]
      },
      "description": "Order. `-score` (default) lists the most at-risk first; `score` flips it; `-computed_at` orders by most recently scored."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/retention/band-cohort": {
   "get": {
    "operationId": "reports_retentionBandCohort",
    "summary": "retentionBandCohort",
    "description": "Every active student in a risk band, for sending or CSV export: lean rows (student id + name + email + score + days since last seen) ordered worst-first, plus the true total and a `truncated` flag (set only if the band exceeds the 10,000-row safety cap).",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "band",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "healthy",
        "watch",
        "warning",
        "critical"
       ]
      },
      "required": true,
      "description": "Required. The risk band to pull. Score ranges: healthy 0-30, watch 31-50, warning 51-70, critical 71-100."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/churn/detail": {
   "get": {
    "operationId": "reports_churnDetail",
    "summary": "churnDetail",
    "description": "Churn lens detail from the student_churn_events ledger (written on deactivation via the leaving-survey capture): 30-day count + MoM trend, the reasons breakdown over the trailing 90 days, the recent churned students with reason, tenure-at-churn, and note, `monthly` (departures per calendar month in the school's zone, the 12 ending this month, oldest first) and `tenure` (how long the people who left in those 12 months had stayed: under3m, m3to12, y1to3, y3plus, unknown). A school moved from v1 has its past departures backfilled at cutover with reason 'unknown', dated from v1's last edit of the student.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/churn/cost": {
   "get": {
    "operationId": "reports_churnCost",
    "summary": "churnCost",
    "description": "Churn framed in dollars from student_churn_events.last_mrr_cents: lost MRR in the last 30 days + MoM, the trailing-12-month total, a 12-month trend (departures + lost MRR per month), and lost MRR broken down by reason and by plan (last 30 days). Money is cents.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "tz",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "IANA timezone for the monthly trend buckets (defaults to Australia/Sydney)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/churn/verbatims": {
   "get": {
    "operationId": "reports_churnVerbatims",
    "summary": "churnVerbatims",
    "description": "Anonymous free-text comments from the leaving survey (churn_survey_responses.note), tagged with the reason. The survey table carries no student link, so notes are anonymous by design. Most recent 50.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/income/detail": {
   "get": {
    "operationId": "reports_incomeDetail",
    "summary": "incomeDetail",
    "description": "Income tab detail. Returns the actuals series (length depends on ribbon `from`/`to`; defaults to 12 months / 13 weeks / 30 days), total + per-source breakdown across subscription / payg / shop / events / one_off / other, the default inputs for the projection model (active subscriptions, MRR, monthly churn rate, new-paying-customers rate, ARPU), and a 4-month forward projection at monthly grain produced by the two-tower model (deterministic subscription roll-forward + per-source smoothed extrapolation). YoY context for the hero chart compares the last N COMPLETE months to the same-length window one year earlier: when the anchor (`asOf`, or end of `to`, default now) sits mid-month the current month stays on the chart but is excluded from the pair (`yoyExcludesCurrentMonth: true`), so a partial month is never set against a full one. `asOf` (unix seconds) pins the anchor directly and wins over `to`. Projection lookback always reads the most recent `horizonMonths` of history, regardless of how far back the display window extends.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.IncomeDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "ready",
          "actualMonths": [],
          "actualMonthsBySource": {},
          "projectionMonths": [],
          "projectionMonthsBySource": {},
          "totalActualCents": 1,
          "totalProjectionCents": 1,
          "priorYearActualCents": 1,
          "yoyDeltaPct": 1,
          "projectionInputs": {},
          "generatedAt": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Optional ribbon-filter lower bound (YYYY-MM-DD, school timezone). Sizes the actuals window: at granularity=month the count is `ceil(months between from..to)` clamped to a defensive ceiling of [1, 600]; at granularity=week clamped to [1, 2080]; at granularity=day clamped to [1, 3650]. The prior-year YoY window is shifted back one year and uses the same length when the monthly window is <= 12 months; longer monthly windows return null YoY (the year-shifted slice would overlap actuals). Omit to fall back to the default trailing window (12 months / 13 weeks / 30 days)."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Optional ribbon-filter anchor (YYYY-MM-DD). Converted to end-of-day in the school's timezone and used as the 'as of' moment. The actuals window, YoY comparison, and forward forecast all pivot off this date. Omit to anchor on 'now'."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional venue scope. When set, restricts transactions + active subscriptions to students enrolled at the given venue (via student_venue_enrollment). Transactions without a student are excluded."
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional styles.id narrow (ribbon Style filter). Plans restricted to the style count; unrestricted plans follow the student's enrolled styles."
     },
     {
      "name": "granularity",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "month",
        "week",
        "day"
       ]
      },
      "description": "Bucket grain for the actual series. `month` (default) = monthly actuals + 4-month projection + YoY (window length driven by `from`/`to`, default 12). `week` = weekly actuals, no projection, no YoY (`projectionMonths: []`, `totalProjectionCents: 0`, `yoyDeltaPct: null`, `priorYearActualCents: 0`); default 13 weeks. `day` = daily actuals, same no-projection/no-YoY semantics; default 30 days. `projectionInputs` is returned as a zero-valued placeholder for response-shape stability."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/income/scenario": {
   "post": {
    "operationId": "reports_incomeScenario",
    "summary": "incomeScenario",
    "description": "Run a what-if income projection scenario. Body carries optional lever multipliers (churn, new-paying-rate, ARPU, price level, per-source revenue) and an optional horizon. Returns the lever-adjusted projection plus the baseline (no levers) projection for side-by-side comparison. No persistence: scenarios live entirely in the request/response cycle.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.IncomeScenario"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "scenarioProjectionMonths": [],
          "scenarioProjectionMonthsBySource": {},
          "scenarioTotalCents": 1,
          "baselineProjectionMonths": [],
          "baselineTotalCents": 1,
          "projectionInputs": {},
          "appliedLevers": {},
          "generatedAt": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "churnMultiplier": {
          "type": "number",
          "description": "Multiplier on the derived monthly churn rate. 1.0 = unchanged; 0.5 = halve churn; 2.0 = double it. Bounded [0, 5]."
         },
         "newPayingMultiplier": {
          "type": "number",
          "description": "Multiplier on the derived monthly new-paying-customers rate. Bounded [0, 10]."
         },
         "arpuMultiplier": {
          "type": "number",
          "description": "Multiplier on the derived avg revenue per new customer (ARPU). Bounded [0, 10]."
         },
         "priceMultiplier": {
          "type": "number",
          "description": "Multiplier applied once to the starting MRR. Models a flat price increase across the existing book. Bounded [0, 10]."
         },
         "sourceMultipliers": {
          "type": "object",
          "description": "Per-source multiplier map. Keys: subscription / payg / shop / events / one_off / other. Values bounded [0, 10]. Missing keys default to 1.0. `subscription` is ignored (subscription revenue comes from the deterministic tower)."
         },
         "horizonMonths": {
          "type": "integer",
          "description": "Projection horizon in months. Default 4. Bounded [1, 24]."
         }
        }
       },
       "example": {
        "churnMultiplier": 1,
        "newPayingMultiplier": 1,
        "arpuMultiplier": 1,
        "priceMultiplier": 1,
        "sourceMultipliers": {},
        "horizonMonths": 1
       }
      }
     }
    }
   }
  },
  "/v1/reports/engagement/heatmap": {
   "get": {
    "operationId": "reports_engagementHeatmap",
    "summary": "engagementHeatmap",
    "description": "Class-time hour×day attendance heatmap. Ships in Phase 3.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.PendingDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "pending",
          "availableInPhase": "string",
          "message": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/curriculum/belt-pyramid": {
   "get": {
    "operationId": "reports_curriculumBeltPyramid",
    "summary": "curriculumBeltPyramid",
    "description": "Belt pyramid + time-at-rank distribution. Ships in Phase 4. Reads rank_history; no new aggregates required.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.PendingDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "pending",
          "availableInPhase": "string",
          "message": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/curriculum/detail": {
   "get": {
    "operationId": "reports_curriculumDetail",
    "summary": "curriculumDetail",
    "description": "Curriculum detail for one style (active students): the rank breakdown (every rank in the style with the count of active students currently at it, shown as the donut) and per-skill pass rates (passed/total from student_rank_skills.pass across the style's ranks, worst-first). Style ownership is validated against the school.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "The style to report on (styles.id, must belong to the school)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/curriculum/lesson-planning": {
   "get": {
    "operationId": "reports_curriculumLesson",
    "summary": "curriculumLesson",
    "description": "Curriculum lesson-planning view for one style (active students): skills students struggle with (pass rate per skill with the rank it's assessed at, worst-first), rank difficulty (pass rate per rank vs the style average), and progression cadence (avg time at each rank before promotion, from grading dates), plus hardest-skill / hardest-rank / slowest-rank callouts. Pass rates from student_rank_skills. Style ownership validated.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "The style to report on (styles.id, must belong to the school)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/curriculum/rank-distribution": {
   "get": {
    "operationId": "reports_curriculumRankDistribution",
    "summary": "curriculumRankDistribution",
    "description": "Program-wide rank distribution: for each of the school's styles, the count of active students at each current rank (their most-recent grading in that style). Compares belt distribution shape across styles. Not style-filtered.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/grading/detail": {
   "get": {
    "operationId": "reports_gradingDetail",
    "summary": "gradingDetail",
    "description": "Grading lens hero + pipeline: distinct students ready to grade (eligibility green, reusing the grading feature's calculateGradingEligibility), nearly ready (yellow), overdue for promotion (past 1.5x the typical time-in-rank, median from promotion history with catalog num_days fallback), the next upcoming grading event (events.is_grading=1, with booked count and price) and projected fees (ready x price). Pipeline rows per (style, rank) with ready/nearly/total counts. Top-rank holders are excluded (nothing to grade to).",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Scope to one venue via student_venue_enrollment."
     },
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor for trailing windows (ribbon date range end)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/grading/overdue": {
   "get": {
    "operationId": "reports_gradingOverdue",
    "summary": "gradingOverdue",
    "description": "Paginated overdue-for-promotion register, worst overdue ratio first: students past 1.5x typical time-in-rank for their current rank, with days-in-rank vs typical, eligibility score/category, check-ins still short, last check-in, and churn-risk band (student_risk_scores). The Grading lens worklist.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Scope to one venue."
     },
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "1-based page (default 1)."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page size (default 10, max 100)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/income/mix": {
   "get": {
    "operationId": "reports_incomeMix",
    "summary": "incomeMix",
    "description": "Revenue mix: monthly totals for the trailing 13 months split by source category (recurring subscriptions, pass packs, PAYG, grading fees from bookings on grading events, other events, shop orders, and other one-offs), over successful, non-refunded transactions. Includes the current month's mix percentages and the share change vs the same month last year. Income lens.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/growth/referrers": {
   "get": {
    "operationId": "reports_growthReferrers",
    "summary": "growthReferrers",
    "description": "Referrer leaderboard over the trailing 24 months: referral_source values normalized and grouped, matched against member full names (a source matching exactly one member becomes a linked referrer with their family name; ambiguous/unmatched stays a string group). Per referrer: referred count, status mix (active / trial-or-lead / lapsed), and the referred students' lifetime successful payments. Also reports the unmatched share.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/growth/household-opportunities": {
   "get": {
    "operationId": "reports_growthHouseholdOpportunities",
    "summary": "growthHouseholdOpportunities",
    "description": "Family cross-sell list: households with >= 1 active member plus >= 1 dormant member (lead / lapsed trial / former student) or a guardian contact whose email isn't enrolled. Per household: active members, opportunity members with kind + last-active + estimated monthly value (their old plan price or the school median), current household MRR. Sorted by estimated value, top 25.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/growth/speed-to-lead": {
   "get": {
    "operationId": "reports_growthSpeedToLead",
    "summary": "growthSpeedToLead",
    "description": "Speed-to-lead: trailing-90d median and p90 time from lead creation (COALESCE(referred_on, created_on)) to first contact (MIN(contact_date) of lead_activities type='note', as the leads board defines it), conversion rate bucketed by response time over 12 months (<1h / 1-4h / 4-24h / 1-3d / >3d), never-contacted count + conversion, walk-in count (contacted within 5 minutes of creation, excluded from buckets), and the median-by-month trend. Soft-deleted lost leads included as inflow (growth-lens convention).",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Scope to one venue."
     },
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/income/leakage": {
   "get": {
    "operationId": "reports_incomeLeakage",
    "summary": "incomeLeakage",
    "description": "Pricing leakage, three sections: (1) upgrade candidates: active students without a recurring sub whose trailing-90d PAYG/pass spend exceeds the cheapest recurring plan they're style-eligible for, framed as the student's monthly saving; (2) legacy pricing: active recurring subs on a grandfathered price below current list (effective price replayed from billing_plan_price_versions; explicit-discount subs excluded as intentional), grouped by plan with the monthly concession; (3) pass breakage: packs expired in the trailing 12 months with unused classes, valued at the pack's per-class price. Income lens.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/attendance/slot-economics": {
   "get": {
    "operationId": "reports_attendanceSlotEconomics",
    "summary": "attendanceSlotEconomics",
    "description": "Schedule economics over the trailing 13 weeks, per recurring class slot: scheduled occurrences (expanded from the days bitmask, same as attendance/classes), check-ins, average attendance, utilization vs capacity, allocated revenue per class and per mat-hour (each student's successful payments in the window divided across their check-ins, summed per slot), and an attendance trend (second half vs first half). Includes expand candidates (>= 90% utilization) and review candidates (<= 25% utilization, at-or-below-median revenue per mat-hour) with merge targets when >= 50% of a slot's regulars already attend another slot.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Scope to one venue (events.venue_id)."
     },
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/retention/transitions": {
   "get": {
    "operationId": "reports_retentionTransitions",
    "summary": "retentionTransitions",
    "description": "Program transitions (ageing-out): active students whose majority recurring class is age-bounded (events.max_age) and who cross the ceiling within 90 days (suppressed when already attending an age-eligible program), with a suggested destination; the historical handoff funnel per program (ceilings crossed 6-24 months ago: reached -> moved within 90d -> still active 6 months on); a count of students in age-bounded programs missing birthdays; and a setup prompt (setupNeeded + recurring class list) when no class carries an age range yet.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Scope to one venue."
     },
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/retention/onboarding": {
   "get": {
    "operationId": "reports_retentionOnboarding",
    "summary": "retentionOnboarding",
    "description": "First-90-days milestone funnel for new members: attainment of M1 (2nd class within 7d) / M2 (8th class within 30d) / M3 (20th class within 90d) / M4 (first promotion within 120d, skipping the signup rank assignment), 12-month survival split per milestone (hit vs missed, computed on mature 12-24-month-old cohorts only, hidden below n=25), M2 attainment by join month, and the salvageable list (missed M2, joined 30-90d ago, still active). Joined = COALESCE(joined_on, converted_on, created_on); members only.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Scope to one venue."
     },
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/payments/recovery": {
   "get": {
    "operationId": "reports_paymentsRecovery",
    "summary": "paymentsRecovery",
    "description": "Revenue recovery: current overdue position (count, owed cents, aging tiers; the same overdue rule as the billing page and payment nudges), 13-month failed-payment trend with per-month recovery rate, trailing-90d outcome split (recovered / still open / written off), and the count of overdue students who checked in within the last 7 days. Income lens (financial data). trainingWithFailedPayment is a worklist: count plus up to 50 students (owed desc) who checked in in the last 7 days with an overdue payment, each with last check-in, overdue-since, owed, the most recent failed transaction on their largest overdue subscription (amount, when, gateway), and a retryable flag that mirrors the retry endpoint's refusals (already_retried / refunded / no_payment_customer / no_failed_transaction).",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/grading/overdue/recipients": {
   "get": {
    "operationId": "reports_gradingOverdueRecipients",
    "summary": "gradingOverdueRecipients",
    "description": "Every overdue-for-promotion student as a lean send-roster ({studentId, firstName, lastName}), deduped across styles, for messaging them all without paging through the register.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Scope to one venue."
     },
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/grading/retention-effect": {
   "get": {
    "operationId": "reports_gradingRetentionEffect",
    "summary": "gradingRetentionEffect",
    "description": "Pooled 12-month survival curves comparing members on track at their rank (`onTrack`) with members overdue for promotion (`overdue`: held their rank longer than 1.5x its usual time, the overdue register's rule applied at each cohort month), pooled over the trailing 18 cohort months. Members in their first 3 months, top ranks and ranks with no usual time are left out. Includes per-group n, the month-12 delta (onTrack minus overdue), and a sampleOk flag (n >= 30 in both groups) the band uses to hide itself on thin data.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Scope to one venue."
     },
     {
      "name": "asOf",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix-seconds anchor."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/demographics/map": {
   "get": {
    "operationId": "reports_demographicsMap",
    "summary": "demographicsMap",
    "description": "Student-map data: geocoded venues (pins) + geocoded students (dots) with the attributes the map filters need (type active/trial/lead, age, gender, styleIds, venueId), plus the count of active students with no mappable point. Filters run client-side, so the response carries the full mapped set in one payload.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/demographics/insights": {
   "get": {
    "operationId": "reports_demographicsInsights",
    "summary": "demographicsInsights",
    "description": "Non-map Demographics bands in one payload (active students): hero stats (total, median age, gender split, median travel distance), catchment (distance-to-venue distribution from student_geocodes.distance_to_primary_venue_km, median + % within 5km), top suburbs by student count, age pyramid split male/female/other (explicitly recorded genders only; students missing gender or birthday are excluded and counted in unknownGender/unknownAge; gender split % is of recorded genders), and family composition (share in families, families with 2+ active members, average members). Each block degrades gracefully when its source data is sparse.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/demographics/detail": {
   "get": {
    "operationId": "reports_demographicsDetail",
    "summary": "demographicsDetail",
    "description": "Demographics ribbon for the active roster: a flow from age band -> program (the styles a student holds a rank in; students with no rank flow into a 'No style' node). Each age band carries a male/female/other split of students with a stated gender; unstatedGender counts those with none (blank or prefer_not_to_say), who are left out of the split. Also returns headline stat callouts. Degrades gracefully when birthday, gender, or rank data is sparse.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/benchmarks": {
   "get": {
    "operationId": "reports_benchmarks",
    "summary": "benchmarks",
    "description": "The Benchmarks tab: this school against the schools most like it, anonymously. Peers are the closest schools on style, size and kids/adults mix (at least 10, at most 30), widening country to region to the world when the school's country has too few; a school split across styles is matched on its style family. Revenue per student is compared in its own same-currency group. Figures are computed once a month and a school's peers are fixed for a calendar quarter. `status` is `ready` (a headline, the split of standings, nine lanes and the peer panel), `trial` (benchmarks open once the school is paying), `opted_out` (the school switched taking part off), `preparing` (no figures computed yet), `no_roster` (no active students) or `not_enough_peers` (fewer than 10 schools like this one, even worldwide). Only the peers' median and middle half are returned, rounded; no peer is identified and no peer's own value is returned. Each lane's `result.status` is `ready`, `no_data` (the school has no figure for that metric) or `too_few_peers` (fewer than 10 peers have one).",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.BenchmarksView"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "ready",
          "headline": {},
          "split": {},
          "lanes": [],
          "peers": {},
          "moneyPeers": {},
          "school": {},
          "settling": false,
          "figuresMonth": "2026-11-05",
          "peersSetOn": "2026-11-05",
          "peersReviewedOn": "2026-11-05",
          "styleLabel": "string",
          "found": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/benchmarks/settings": {
   "get": {
    "operationId": "reports_benchmarksSettings",
    "summary": "benchmarksSettings",
    "description": "Whether the school takes part in benchmarks. Taking part is on by default: the school's figures are included anonymously in other schools' comparisons and it sees its own.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.BenchmarksSettings"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "takePart": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "put": {
    "operationId": "reports_setBenchmarksSettings",
    "summary": "setBenchmarksSettings",
    "description": "Take part in benchmarks, or stop. Owner only. Stopping removes the school's figures from every other school's comparison at once and hides its own benchmarks; switching back on restores both.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/reports.BenchmarksSettings"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "takePart": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "takePart": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "takePart": {
          "type": "boolean",
          "description": "true to take part, false to stop."
         }
        },
        "required": [
         "takePart"
        ]
       },
       "example": {
        "takePart": false
       }
      }
     }
    }
   }
  },
  "/v1/reports/benchmarks/{metric}": {
   "get": {
    "operationId": "reports_benchmark",
    "summary": "benchmark",
    "description": "Anonymous network benchmark percentiles for a metric. Bands display only when N ≥ 30 contributing schools (the privacy guardrail). Ships in Phase 5.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.PendingDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "pending",
          "availableInPhase": "string",
          "message": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "metric",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "sizeBand",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "small",
        "medium",
        "large",
        "very_large"
       ]
      },
      "description": "Optional school size band filter."
     },
     {
      "name": "regionTier",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Optional region tier filter (e.g. 'en-AU')."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/library": {
   "get": {
    "operationId": "reports_library",
    "summary": "library",
    "description": "Index of legacy parity reports. Each entry maps to a destination: a lens modal in the 2.0 app, an export (CSV/PDF), or an external admin route. Static catalog.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/reports.LibraryEntry"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": "string",
           "title": "string",
           "description": "string",
           "destination": {},
           "availableInPhase": "string"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/transactions": {
   "get": {
    "operationId": "reports_transactions",
    "summary": "transactions",
    "description": "Paginated school-wide payments ledger with the paying student's name on each row (unlike /v1/billing/transactions).",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/reports.PaymentsLedgerRow"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "createdOn": 1,
           "amount": 1,
           "status": "successful",
           "paymentMethod": "string",
           "gateway": "stripe",
           "description": "string",
           "studentId": 1,
           "studentName": "string",
           "familyId": 1,
           "shopOrderId": 1,
           "familyName": "string",
           "refundedOn": 1,
           "failedOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Inclusive lower bound on created_on (unix seconds). Omit for unbounded. Also accepted as dateFrom."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Inclusive upper bound on created_on (unix seconds). Omit for unbounded. Also accepted as dateTo."
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "successful",
        "failed",
        "retrying",
        "pending",
        "submitted",
        "cancelled"
       ]
      },
      "description": "Semantic status filter. Maps to the underlying integer status codes via the canonical translation in billing/utils/status.ts."
     },
     {
      "name": "paymentMethod",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Exact match on payment_method (e.g. 'Stripe', 'Cash')."
     },
     {
      "name": "minAmount",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Cents. Inclusive lower bound on amount."
     },
     {
      "name": "excludeAutoRecorded",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "true",
        "false"
       ]
      },
      "description": "'true' leaves out rows Automatic Transaction Recording wrote (each row also carries autoRecorded)."
     },
     {
      "name": "source",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "subscription",
        "payg",
        "shop",
        "events",
        "one_off",
        "other"
       ]
      },
      "description": "Revenue-source narrow. Uses the Income card's source buckets, so totals match it."
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "-date",
        "date",
        "-amount",
        "amount",
        "student",
        "-student"
       ],
       "default": "-date"
      },
      "description": "Sort order. Default is newest first. `student` sort triggers filesort (paginated, acceptable)."
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "1-indexed page number."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 50
      },
      "description": "Page size (max 10000). UI table uses 50; CSV export pulls up to 10000 in one round-trip."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/subscriptions": {
   "get": {
    "operationId": "reports_subscriptions",
    "summary": "subscriptions",
    "description": "Revenue Movement drill-down: the subscriber roster for a plan wedge, waterfall step or period anchor, read from the snapshot, so its counts always match the chart.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.SubscribersResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "ready",
          "periodStartSec": 1,
          "periodEndSec": 1,
          "rows": [],
          "page": 1,
          "limit": 1,
          "total": 1,
          "totalPages": 1,
          "reason": "no_snapshot"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "context",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "plan",
        "step",
        "anchor"
       ]
      },
      "description": "Drill-down kind. `plan` = donut wedge click (also requires planId). `step` = waterfall step bar (also requires step). `anchor` = period boundary on the donut (also requires anchor)."
     },
     {
      "name": "planId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "(context=plan only) Billing plan id whose wedge was clicked."
     },
     {
      "name": "step",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "new",
        "reactivation",
        "expansion",
        "contraction",
        "churn"
       ]
      },
      "description": "(context=step only) Waterfall step the bar represents."
     },
     {
      "name": "anchor",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "start",
        "end"
       ]
      },
      "description": "(context=anchor only) Which period boundary the click landed on."
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "-mrr",
        "mrr",
        "name",
        "-name"
       ],
       "default": "-mrr"
      },
      "description": "Sort order. `mrr` sorts by absolute cents for step views so biggest movers surface first; plan and anchor views sort by signed cents."
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "1-indexed page number."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 100
      },
      "description": "Page size (max 1000)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/attendances": {
   "get": {
    "operationId": "reports_attendances",
    "summary": "attendances",
    "description": "Live attendance roster drill-down. Range-aware (from/to in unix seconds, optional venueId/styleId narrow). Returns paginated `AttendanceRosterRow[]` with each check-in's student (and photo, and emergency number where permitted), style and venue.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/reports.AttendanceRosterRow"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "checkInSec": 1,
           "studentId": 1,
           "studentName": "string",
           "styleId": 1,
           "styleName": "string",
           "venueId": 1,
           "venueName": "string",
           "photoUrl": "string",
           "emergencyNumber": "string"
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Inclusive lower bound on student_attendance.created_on (unix seconds)."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Inclusive upper bound on student_attendance.created_on (unix seconds)."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow. Use when the modal is launched from a venue-scoped chart layer."
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional styles.id narrow. Style is attributed via the rank held at check-in time (matches the snapshot worker's bucketing)."
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "-date",
        "date",
        "student",
        "-student",
        "style",
        "-style"
       ],
       "default": "-date"
      },
      "description": "Sort order. Default is most recent first."
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "1-indexed page number."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 200
      },
      "description": "Page size (max 10000). Modal table uses 200; CSV export pulls the full filtered set in one round-trip."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/attendance/leaderboard": {
   "get": {
    "operationId": "reports_attendanceLeaderboard",
    "summary": "attendanceLeaderboard",
    "description": "Top-N students ranked by check-in count within a window. Same filters as /attendances. Ties broken by most-recent activity DESC then student id ASC.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.LeaderboardResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "rows": [],
          "from": 1,
          "to": 1,
          "totalStudents": 1,
          "totalCheckIns": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Inclusive lower bound on student_attendance.created_on (unix seconds)."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Inclusive upper bound on student_attendance.created_on (unix seconds)."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow."
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional styles.id narrow. Style attributed via rank-at-checkin."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 25
      },
      "description": "Top-N row cap (max 200)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/attendance/frequency": {
   "get": {
    "operationId": "reports_attendanceFrequency",
    "summary": "attendanceFrequency",
    "description": "Classes per active student, by calendar week in the school's time zone (weeks start Sunday). Each week: check-ins by the week's population, the population (today's Active Students who had joined by the end of the week, zero-class students included), their ratio to two decimals, and whether the week is still running. Always weekly: the ribbon's date range and venue apply, its granularity does not. Default window is the trailing 13 weeks. A venue narrows the population to students enrolled there and the check-ins to that venue.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.FrequencyResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "weeks": [],
          "from": 1,
          "to": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "First day of the window, YYYY-MM-DD in the school's time zone."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Last day of the window (inclusive), YYYY-MM-DD. Defaults to today."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/attendance/frequency/week": {
   "get": {
    "operationId": "reports_attendanceFrequencyWeek",
    "summary": "attendanceFrequencyWeek",
    "description": "Every active student's classes in one week (the population and venue rules of /attendance/frequency), with a trailing four-week average (check-ins over the four weeks ending with this one, divided by four). Sorted by classes DESC, then four-week check-ins DESC, then name. Unpaginated: a school's roster.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.FrequencyWeekResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "weekStart": "string",
          "startSec": 1,
          "endSec": 1,
          "rows": [],
          "students": 1,
          "checkIns": 1,
          "average": 1,
          "partial": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "weekStart",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "A day in the week, YYYY-MM-DD; snaps to that week's Sunday."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/attendance/frequency/week.csv": {
   "get": {
    "operationId": "reports_attendanceFrequencyWeekCsv",
    "summary": "attendanceFrequencyWeekCsv",
    "description": "The /attendance/frequency/week list as a CSV download. Columns: Student ID, First Name, Last Name, Classes this week, 4-week average. text/csv.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "weekStart",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "A day in the week, YYYY-MM-DD."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/attendance/leaderboard.csv": {
   "get": {
    "operationId": "reports_attendanceLeaderboardCsv",
    "summary": "attendanceLeaderboardCsv",
    "description": "The attendance leaderboard as a CSV download, every student with a check-in in the window (no top-N), ranked as /attendance/leaderboard ranks them. Columns: Position, Student ID, First Name, Last Name, Check-ins, Last check-in (YYYY-MM-DD HH:MM in the school's time zone). text/csv.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Inclusive lower bound on student_attendance.created_on (unix seconds)."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Inclusive upper bound on student_attendance.created_on (unix seconds)."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow."
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional styles.id narrow. Style attributed via rank-at-checkin."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/attendance/classes": {
   "get": {
    "operationId": "reports_attendanceClasses",
    "summary": "attendanceClasses",
    "description": "Per-class activity in a window: check-ins, bookings, no-shows, occurrences. Only classes with any activity (at least one check-in, booking or no-show) appear. `styleId` is not supported: classes are not linked to a style.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.ClassActivityResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "rows": [],
          "from": 1,
          "to": 1,
          "totalClasses": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Inclusive unix-seconds lower bound."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Inclusive unix-seconds upper bound."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow."
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 25
      },
      "description": "Top-N row cap (max 200)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/attendance/heatmap": {
   "get": {
    "operationId": "reports_attendanceHeatmap",
    "summary": "attendanceHeatmap",
    "description": "7×24 day-of-week × hour-of-day grid of check-ins in the window, computed in the school's local wall clock. Returns the matrix plus 4 quantile-bin boundaries for a per-school colour scale. Auto-trims dead edge hours via hourStart/hourEnd. Same filters as the leaderboard.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.HeatmapResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "matrix": [],
          "total": 1,
          "maxCell": 1,
          "hourStart": 1,
          "hourEnd": 1,
          "bins": [],
          "from": 1,
          "to": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Inclusive unix-seconds lower bound on `created_on`."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "required": true,
      "description": "Inclusive unix-seconds upper bound on `created_on`."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow."
     },
     {
      "name": "styleId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional style narrow via rank-at-checkin."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/reports/attendance/trend": {
   "get": {
    "operationId": "reports_attendanceTrend",
    "summary": "attendanceTrend",
    "description": "Check-ins by period (month/week/day on the school's clock) and by style (from the check-in's rank), live, for when ribbon filters are set; unfiltered charts read the snapshot's engagement.visualization, and the two agree. A venue narrows to check-ins at that venue's classes, so walk-ins drop out.",
    "tags": [
     "reports"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/reports.AttendanceTrendResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "periods": [],
          "from": 1,
          "to": 1,
          "granularity": "month"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Ribbon range start (YYYY-MM-DD, school tz). Sizes the window; omit for the default trailing window (12mo / 13wk / 30d)."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Ribbon range end (YYYY-MM-DD). Becomes the end-of-day-in-tz anchor; omit to anchor at now."
     },
     {
      "name": "venueId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Optional school_venues.id narrow (drops walk-ins, which have no event)."
     },
     {
      "name": "granularity",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "month",
        "week",
        "day"
       ],
       "default": "month"
      },
      "description": "Bucket cadence."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/news": {
   "get": {
    "operationId": "news_list",
    "summary": "list",
    "description": "List news articles for the school. Includes drafts unless filtered. Soft-deleted articles are excluded by default.",
    "tags": [
     "news"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/news.NewsArticle"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "title": "string",
           "article": "string",
           "excerpt": "string",
           "author": "string",
           "isVisible": false,
           "showOnWebsite": false,
           "publishStart": 1,
           "publishEnd": 1,
           "views": 1,
           "heroStorageKey": "string",
           "heroUrl": "string",
           "pushSentAt": 1,
           "createdOn": 1,
           "deletedOn": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "isVisible",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Filter by visibility flag. true = published, false = draft. Omit to return both."
     },
     {
      "name": "showOnWebsite",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Filter by whether the article is on the school's public website (its Blog). Omit to return both."
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Case-insensitive substring match on article title."
     },
     {
      "name": "includeDeleted",
      "in": "query",
      "schema": {
       "type": "boolean",
       "default": false
      },
      "description": "Include soft-deleted articles. Useful for recovery tooling."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "news_create",
    "summary": "create",
    "description": "Create a new article. Defaults to draft (isVisible=false). Pair publishStart + publishEnd to schedule visibility within a window; either side alone is unbounded.",
    "tags": [
     "news"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/news.NewsArticle"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "title": "string",
            "article": "string",
            "excerpt": "string",
            "author": "string",
            "isVisible": false,
            "showOnWebsite": false,
            "publishStart": 1,
            "publishEnd": 1,
            "views": 1,
            "heroStorageKey": "string",
            "heroUrl": "string",
            "pushSentAt": 1,
            "createdOn": 1,
            "deletedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "title": "string",
            "article": "string",
            "excerpt": "string",
            "author": "string",
            "isVisible": false,
            "showOnWebsite": false,
            "publishStart": 1,
            "publishEnd": 1,
            "views": 1,
            "heroStorageKey": "string",
            "heroUrl": "string",
            "pushSentAt": 1,
            "createdOn": 1,
            "deletedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "title": {
          "type": "string",
          "description": "Article headline",
          "minLength": 1,
          "maxLength": 500
         },
         "article": {
          "type": "string",
          "description": "HTML body content. Up to 5 MB. Inline images can be embedded as absolute URLs."
         },
         "excerpt": {
          "type": "string",
          "description": "Short summary. Used in list views, push notification bodies, and digests.",
          "maxLength": 500
         },
         "author": {
          "type": "string",
          "description": "Author display name. Free-text; not a user FK.",
          "maxLength": 250
         },
         "isVisible": {
          "type": "boolean",
          "description": "Publish immediately if true; otherwise save as draft.",
          "default": false
         },
         "showOnWebsite": {
          "type": "boolean",
          "description": "Also show it on the school's public website, where anyone can read it. Off unless set; a published article without it reaches members only.",
          "default": false
         },
         "publishStart": {
          "type": "integer",
          "description": "Unix seconds. Article is hidden from students before this time. Null = no lower bound."
         },
         "publishEnd": {
          "type": "integer",
          "description": "Unix seconds. Article is hidden from students after this time. Null = no upper bound. Must be greater than publishStart if both are set."
         }
        },
        "required": [
         "title",
         "article"
        ]
       },
       "example": {
        "title": "string",
        "article": "string"
       }
      }
     }
    }
   }
  },
  "/v1/news/{id}": {
   "get": {
    "operationId": "news_get",
    "summary": "get",
    "description": "Get a single article by ID. Soft-deleted articles return 404.",
    "tags": [
     "news"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/news.NewsArticle"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "title": "string",
          "article": "string",
          "excerpt": "string",
          "author": "string",
          "isVisible": false,
          "showOnWebsite": false,
          "publishStart": 1,
          "publishEnd": 1,
          "views": 1,
          "heroStorageKey": "string",
          "heroUrl": "string",
          "pushSentAt": 1,
          "createdOn": 1,
          "deletedOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "news_update",
    "summary": "update",
    "description": "Update an existing article. All fields optional.",
    "tags": [
     "news"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/news.NewsArticle"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "title": "string",
            "article": "string",
            "excerpt": "string",
            "author": "string",
            "isVisible": false,
            "showOnWebsite": false,
            "publishStart": 1,
            "publishEnd": 1,
            "views": 1,
            "heroStorageKey": "string",
            "heroUrl": "string",
            "pushSentAt": 1,
            "createdOn": 1,
            "deletedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "title": "string",
            "article": "string",
            "excerpt": "string",
            "author": "string",
            "isVisible": false,
            "showOnWebsite": false,
            "publishStart": 1,
            "publishEnd": 1,
            "views": 1,
            "heroStorageKey": "string",
            "heroUrl": "string",
            "pushSentAt": 1,
            "createdOn": 1,
            "deletedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "title": {
          "type": "string",
          "minLength": 1,
          "maxLength": 500
         },
         "article": {
          "type": "string",
          "description": "HTML body content"
         },
         "excerpt": {
          "type": "string",
          "maxLength": 500
         },
         "author": {
          "type": "string",
          "maxLength": 250
         },
         "isVisible": {
          "type": "boolean"
         },
         "showOnWebsite": {
          "type": "boolean",
          "description": "On the school's public website (its Blog), where anyone can read it."
         },
         "publishStart": {
          "type": "integer",
          "description": "Unix seconds"
         },
         "publishEnd": {
          "type": "integer",
          "description": "Unix seconds"
         }
        }
       },
       "example": {
        "title": "string",
        "article": "string",
        "excerpt": "string",
        "author": "string",
        "isVisible": false,
        "showOnWebsite": false,
        "publishStart": 1,
        "publishEnd": 1
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "news_delete",
    "summary": "delete",
    "description": "Soft-delete an article. Sets `deletedOn` and hides it from read paths. The row is recoverable by clearing the column directly in the database (no admin restore UI yet), but all images under the article's storage prefix (hero + inline) are HARD-deleted to keep the bucket lean. Restoring a deleted article will leave broken image references in the body.",
    "tags": [
     "news"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/news/{id}/hero": {
   "post": {
    "operationId": "news_uploadHero",
    "summary": "uploadHero",
    "description": "Upload (or replace) the article's hero image. Multipart form field name is `image`. Accepts jpeg/png/webp/gif up to 10 MB. Server normalizes to WebP at 1920x1080 max and stores at `{schoolId}/news/{articleId}/hero_{uuid}.webp`. Replaces any prior hero. Returns a short-lived presigned URL for immediate preview; subsequent list/get responses also include a fresh `heroUrl`.",
    "tags": [
     "news"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/news.HeroUploadResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "storageKey": "string",
          "heroUrl": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   },
   "delete": {
    "operationId": "news_deleteHero",
    "summary": "deleteHero",
    "description": "Remove the article's hero image. Clears `heroStorageKey` and deletes the file from storage (best-effort). Returns success even when there was no hero to delete.",
    "tags": [
     "news"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/news/{id}/images": {
   "post": {
    "operationId": "news_uploadInlineImage",
    "summary": "uploadInlineImage",
    "description": "Upload an image to embed inline in the article body. Multipart form field name is `image`. Accepts jpeg/png/webp/gif up to 5 MB. Server normalizes to WebP at 1600px max and stores at `{schoolId}/news/{articleId}/inline_{uuid}.webp`. Not tracked in the database: the returned URL should be placed into the article HTML by the editor.",
    "tags": [
     "news"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/news.InlineUploadResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "storageKey": "string",
          "url": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/send/email": {
   "post": {
    "operationId": "send_sendEmail",
    "summary": "sendEmail",
    "description": "Send email to a list of students. Body fields: see EmailPayload model. Broadcast stream requires ?confirm=true and supports ?preview=true. Transactional stream sends immediately (no confirm/preview). Preview response includes a `deliverability` field (see DeliverabilityPreview model) that runs the same student/preference/suppression checks the real send would, so the caller can see actual reach (deliverable vs skipped: not_found / no_address / opted_out / suppressed) before confirming. Anti-fatigue is intentionally NOT counted in preview because it is point-in-time and would change between preview and send.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.DeliverResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "sent": [],
            "skipped": [],
            "summary": {},
            "held": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "sent": [],
            "skipped": [],
            "summary": {},
            "held": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Confirmation required (condition: broadcast_only). Pass confirm=true to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "recipientIds": {
          "type": "array",
          "description": "Student IDs to send to (1 to 500)",
          "items": {
           "type": "integer"
          }
         },
         "subject": {
          "type": "string",
          "description": "Email subject line. Supports {{merge_tags}}.",
          "maxLength": 998
         },
         "htmlBody": {
          "type": "string",
          "description": "HTML email body. Supports {{merge_tags}}."
         },
         "textBody": {
          "type": "string",
          "description": "Plain text fallback body"
         },
         "fromName": {
          "type": "string",
          "description": "Sender display name (defaults to school name)",
          "maxLength": 255
         },
         "replyTo": {
          "type": "string",
          "description": "Reply-to email address",
          "format": "email"
         },
         "stream": {
          "type": "string",
          "description": "Transactional bypasses anti-fatigue rules and sends immediately (no confirm/preview). Default: broadcast.",
          "enum": [
           "transactional",
           "broadcast"
          ]
         },
         "trackOpens": {
          "type": "boolean",
          "description": "Track email opens. Default: true."
         },
         "trackClicks": {
          "type": "boolean",
          "description": "Track link clicks. Default: true."
         },
         "templateId": {
          "type": "integer",
          "description": "Template ID for delivery log tracking"
         },
         "metadata": {
          "type": "object",
          "description": "Custom key-value metadata"
         },
         "attachment": {
          "type": "object",
          "description": "One file sent with the email: the storageKey returned by POST /v1/send/assets with kind=attachment, plus the filename the recipient sees. PDF, JPG, PNG, DOC, DOCX; 5 MB."
         },
         "overrideSendLimits": {
          "type": "boolean",
          "description": "Send past the per-person send limits for this call (cooldown, daily caps, the weekly marketing cap, quiet hours). Only when the person has seen who the limits would hold (POST /v1/send/audience-check, `held`) and chosen to send anyway. Recorded as send_limits_override in the delivery log."
         },
         "holdLimited": {
          "type": "boolean",
          "description": "Anyone the per-person send limits hold is queued as a scheduled send at the time the limit clears, instead of being skipped. The response's `held` lists each queued row (scheduledSendId, rule, until, recipientIds)."
         }
        },
        "required": [
         "recipientIds",
         "subject",
         "htmlBody"
        ]
       },
       "example": {
        "recipientIds": [
         1
        ],
        "subject": "string",
        "htmlBody": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/sms": {
   "post": {
    "operationId": "send_sendSms",
    "summary": "sendSms",
    "description": "Send SMS to a list of students. Body fields: see SmsPayload model. Broadcast stream requires ?confirm=true and supports ?preview=true. Transactional stream sends immediately (no confirm/preview). Preview response includes both credit math (creditsRequired, currentBalance, sufficientCredits) AND a `deliverability` field (see DeliverabilityPreview model) so the caller can see both cost and actual reach. Credit math is based on requested count, not deliverable count. Spend happens up-front per legacy parity, with per-recipient refunds on skip.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.DeliverResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "sent": [],
            "skipped": [],
            "summary": {},
            "held": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "sent": [],
            "skipped": [],
            "summary": {},
            "held": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Confirmation required (condition: broadcast_only). Pass confirm=true to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "recipientIds": {
          "type": "array",
          "description": "Student IDs to send to (1 to 500)",
          "items": {
           "type": "integer"
          }
         },
         "message": {
          "type": "string",
          "description": "SMS message body. Supports {{merge_tags}}.",
          "maxLength": 1600
         },
         "mediaUrl": {
          "type": "string",
          "description": "MMS media URL",
          "format": "url"
         },
         "stream": {
          "type": "string",
          "description": "Transactional bypasses anti-fatigue rules and sends immediately (no confirm/preview). Default: broadcast.",
          "enum": [
           "transactional",
           "broadcast"
          ]
         },
         "templateId": {
          "type": "integer",
          "description": "Template ID for delivery log tracking"
         },
         "metadata": {
          "type": "object",
          "description": "Custom key-value metadata"
         },
         "overrideQuietHours": {
          "type": "boolean",
          "description": "Send inside the school's quiet hours (the person chose Send anyway on the quiet-hours check). Other limits still apply."
         },
         "overrideSendLimits": {
          "type": "boolean",
          "description": "Send past the per-person send limits for this call (cooldown, daily caps, the weekly marketing cap, quiet hours). Only when the person has seen who the limits would hold (POST /v1/send/audience-check, `held`) and chosen to send anyway. Recorded as send_limits_override in the delivery log."
         },
         "holdLimited": {
          "type": "boolean",
          "description": "Anyone the per-person send limits hold is queued as a scheduled send at the time the limit clears, instead of being skipped. The response's `held` lists each queued row (scheduledSendId, rule, until, recipientIds)."
         }
        },
        "required": [
         "recipientIds",
         "message"
        ]
       },
       "example": {
        "recipientIds": [
         1
        ],
        "message": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/push": {
   "post": {
    "operationId": "send_sendPush",
    "summary": "sendPush",
    "description": "Send a Web Push notification to a list of admin/staff users (NOT students; this is the admin push channel). Body fields: see PushPayload model. Recipients must have an active VAPID subscription registered via the admin app; users without one are surfaced in `skipped` on the response. Broadcast stream requires ?confirm=true and supports ?preview=true. Default stream is transactional. Preview response includes a `deliverability` field (see DeliverabilityPreview model). Push uses a collapsed skipped breakdown: only `no_subscription` is counted at preview time (per-token failures like expired endpoints only surface mid-send).",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.DeliverResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "sent": [],
            "skipped": [],
            "summary": {},
            "held": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "sent": [],
            "skipped": [],
            "summary": {},
            "held": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Confirmation required (condition: broadcast_only). Pass confirm=true to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "userIds": {
          "type": "array",
          "description": "Admin/staff user IDs to send to (1 to 500). NOTE: not students. These are the school's staff account IDs (an internal surface; there is no public endpoint to enumerate them).",
          "items": {
           "type": "integer"
          }
         },
         "title": {
          "type": "string",
          "description": "Push notification title",
          "maxLength": 120
         },
         "body": {
          "type": "string",
          "description": "Push notification body text",
          "maxLength": 500
         },
         "actionUrl": {
          "type": "string",
          "description": "URL opened when the user clicks the push",
          "format": "url"
         },
         "icon": {
          "type": "string",
          "description": "URL of the icon shown in the push card",
          "format": "url"
         },
         "stream": {
          "type": "string",
          "description": "Transactional bypasses confirm/preview. Default: transactional.",
          "enum": [
           "transactional",
           "broadcast"
          ]
         },
         "metadata": {
          "type": "object",
          "description": "Custom key-value metadata"
         }
        },
        "required": [
         "userIds",
         "title",
         "body"
        ]
       },
       "example": {
        "userIds": [
         1
        ],
        "title": "string",
        "body": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/schedule/queue": {
   "post": {
    "operationId": "send_scheduleSend",
    "summary": "scheduleSend",
    "description": "Schedule an email or SMS send for future delivery. Stores the full request payload; a background worker executes it at the scheduled time. Broadcast streams require ?confirm=true at schedule-time (the worker fires unattended). ?preview=true returns a dry-run summary without enqueuing.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.ScheduledSend"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "channel": "email",
            "status": "string",
            "scheduledFor": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "channel": "email",
            "status": "string",
            "scheduledFor": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Confirmation required (condition: broadcast_only). Pass confirm=true to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "channel": {
          "type": "string",
          "description": "Channel to schedule",
          "enum": [
           "email",
           "sms"
          ]
         },
         "scheduledFor": {
          "type": "integer",
          "description": "Unix timestamp for when to send (must be in the future)"
         },
         "email": {
          "$ref": "#/components/schemas/send.EmailPayload",
          "description": "Full email payload (required when channel=email). Identical shape to POST /v1/send/email body."
         },
         "sms": {
          "$ref": "#/components/schemas/send.SmsPayload",
          "description": "Full SMS payload (required when channel=sms). Identical shape to POST /v1/send/sms body."
         }
        },
        "required": [
         "channel",
         "scheduledFor"
        ]
       },
       "example": {
        "channel": "email",
        "scheduledFor": 1
       }
      }
     }
    }
   },
   "get": {
    "operationId": "send_listScheduledSends",
    "summary": "listScheduledSends",
    "description": "List the school's schedule queue (paginated): pending rows (status 'scheduled'), plus rows the worker refused at fire time in the last seven days (status 'failed' with a `failure` reason, until dismissed with DELETE). Cancelled and successfully fired rows are excluded. Sorted by createdOn ascending so list order matches worker fire order. Use this to confirm a POST /schedule/queue landed before its scheduledFor moment, and to see why a scheduled send did not go out.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.ScheduledSendItem"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "channel": "email",
           "status": "scheduled",
           "failure": {},
           "held": {},
           "scheduledFor": 1793836800,
           "recipientCount": 1,
           "subject": "string",
           "messagePreview": "string",
           "senderId": 1,
           "createdOn": 1793836800
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "channel",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "email",
        "sms"
       ]
      },
      "description": "Filter by channel"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "createdOn lower bound (unix seconds). Also accepted as after."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "createdOn upper bound (unix seconds). Also accepted as before."
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (default: 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 50)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/schedule/queue/{id}": {
   "delete": {
    "operationId": "send_cancelScheduledSend",
    "summary": "cancelScheduledSend",
    "description": "Cancel a scheduled send. Two-phase: requires ?confirm=true (cancellation is one-way; the row cannot be re-scheduled). Use ?preview=true to inspect what's about to be cancelled (returns the same ScheduledSendItem shape as GET /schedule/queue/:id wrapped under `schedule`). Cancelled or already-fired rows return 404 from preview/confirm/execute alike. There's no way to distinguish those states from the cancel endpoint by design (history lives in /v1/send/delivery and /v1/send/history). Returns 409 only if the row is mid-fire when the cancel lands. On a row with status 'failed' (the worker refused it at fire time) DELETE dismisses it from the queue listing immediately, no confirm needed: nothing was sent and it cannot be re-fired.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   },
   "get": {
    "operationId": "send_getScheduledSend",
    "summary": "getScheduledSend",
    "description": "Get a single pending scheduled send by ID. Returns 404 once the row has been cancelled or fired (status moves off 'scheduled' at that point); historical data lives in /v1/send/delivery and /v1/send/history. Response includes recipientCount, scheduledFor, and a content snippet (subject for email; messagePreview for SMS) so an agent can identify the send before deciding to cancel.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.ScheduledSendItem"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "channel": "email",
          "status": "scheduled",
          "failure": {},
          "held": {},
          "scheduledFor": 1793836800,
          "recipientCount": 1,
          "subject": "string",
          "messagePreview": "string",
          "senderId": 1,
          "createdOn": 1793836800
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/schedule/queue/{id}/send-now": {
   "post": {
    "operationId": "send_pushThroughScheduledSend",
    "summary": "pushThroughScheduledSend",
    "description": "Send a held scheduled send now. Only rows with `held` set qualify: people the per-person send limits held back from an earlier send, queued to go when the limit clears. This sends them now, past those limits for this one call (recorded as send_limits_override in the delivery log); preferences, suppression and the school's brakes still apply. Two-phase: ?preview=true returns the row under `schedule` without sending; ?confirm=true sends. 404 when the row is not pending; 409 when it is not a held row, is already going out, or was refused (the reason is in the message); 429 when the school's send rate brake is on (the row stays held).",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/delivery/{id}/recipients": {
   "get": {
    "operationId": "send_listDeliveryRecipients",
    "summary": "listDeliveryRecipients",
    "description": "List per-recipient delivery status for a batch send. Groups recipients by contentHash or templateId.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.DeliveryRecipient"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "recipientId": 1,
           "recipientAddress": "string",
           "status": "queued",
           "externalId": "string",
           "createdOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "queued",
        "sending",
        "delivered",
        "opened",
        "clicked",
        "bounced",
        "failed"
       ]
      },
      "description": "Filter by delivery status"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (default: 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 50)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/batches/{id}": {
   "get": {
    "operationId": "send_getBatch",
    "summary": "getBatch",
    "description": "A single send's identity and outcomes: subject, content snapshot, source, and the per-recipient rows with delivered/opened/clicked timestamps. Batch ids come from sendHistory entries (batchId); rows from before the batch model have none and cannot be opened.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/skip-log": {
   "get": {
    "operationId": "send_skipLog",
    "summary": "skipLog",
    "description": "Recent messages that were NOT sent, with why: anti-fatigue caps, quiet hours, opt-outs, missing addresses, insufficient SMS credits. One row per skipped recipient, newest first. retryAt is present on anti-fatigue skips and is when a deferred automation retries.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "description": "SkipLogItem"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (default: 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 50)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/quiet-hours": {
   "get": {
    "operationId": "send_getQuietHours",
    "summary": "getQuietHours",
    "description": "The school's quiet-hours window. When enabled, broadcast and automation sends inside the window defer to its end; transactional sends are exempt. Times are wall-clock HH:MM in the school's timezone and the window may wrap midnight.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "send_updateQuietHours",
    "summary": "updateQuietHours",
    "description": "Update the quiet-hours window (enabled, start, end).",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "enabled": {
          "type": "boolean",
          "description": "Turn quiet hours on or off"
         },
         "start": {
          "type": "string",
          "description": "Window start, HH:MM"
         },
         "end": {
          "type": "string",
          "description": "Window end, HH:MM"
         }
        }
       },
       "example": {
        "enabled": false,
        "start": "string",
        "end": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/history": {
   "get": {
    "operationId": "send_sendHistory",
    "summary": "sendHistory",
    "description": "Cross-channel send history. One entry per send batch (with batchId + subject, openable via GET /v1/send/batches/:id); rows from before the batch model group by content/template with a null batchId. Aggregate stats per entry (delivered, opened, clicked, bounced, failed); skipped recipients are excluded from totals.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.SendHistoryEntry"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "channel": "string",
           "contentHash": "string",
           "templateId": 1,
           "stats": {},
           "firstSentOn": 1,
           "lastSentOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "channel",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "email",
        "sms",
        "chat",
        "push",
        "social",
        "webhook"
       ]
      },
      "description": "Filter by channel"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix timestamp lower bound. Also accepted as after."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix timestamp upper bound. Also accepted as before."
     },
     {
      "name": "includeV1",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "true",
        "false"
       ]
      },
      "description": "Also list sends made in v1 before the school moved to 2.0 (source 'v1': subject, channel, recipient count, date). Their stats carry outcomesKnown: false; delivered/opened/clicked were not kept. They follow every 2.0 send."
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (default: 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 50)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/merge-tags": {
   "get": {
    "operationId": "send_listMergeTags",
    "summary": "listMergeTags",
    "description": "List available merge tags with descriptions and audience scope",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.MergeTag"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "name": "string",
           "category": "string",
           "description": "string",
           "audience": "student"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "audience",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "student",
        "admin",
        "instructor"
       ]
      },
      "description": "Filter tags by audience. Omit for all."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/merge-tags/resolve": {
   "post": {
    "operationId": "send_resolveMergeTags",
    "summary": "resolveMergeTags",
    "description": "Resolve merge tags in a template string for a specific student. Returns the rendered template plus an inspection report (foundTags, unknownTags, audienceMismatches). Unknown tags are LEFT AS-IS in the rendered output (not removed) so partial templates remain debuggable.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "template": "string",
          "resolved": "string",
          "studentId": 1,
          "audience": "student",
          "foundTags": [
           {}
          ],
          "unknownTags": [
           {}
          ],
          "audienceMismatches": [
           {}
          ],
          "totalOccurrences": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "template": {
          "type": "string",
          "description": "Template string with {{tag}} placeholders"
         },
         "studentId": {
          "type": "integer",
          "description": "Student ID to resolve tags for"
         },
         "audience": {
          "type": "string",
          "description": "Per-student endpoint: only 'student' is accepted. Admin and instructor tags are aggregate (per-school / per-instructor) and have no per-studentId answer; the schema rejects them with a 400 instead of silently producing partial results. Default: student.",
          "enum": [
           "student"
          ]
         }
        },
        "required": [
         "template",
         "studentId"
        ]
       },
       "example": {
        "template": "string",
        "studentId": 1
       }
      }
     }
    }
   }
  },
  "/v1/send/merge-tags/resolve-batch": {
   "post": {
    "operationId": "send_resolveMergeTagsBatch",
    "summary": "resolveMergeTagsBatch",
    "description": "Resolve a single template against many students in one round trip. Cap: 100 students per call. Missing students are echoed back with `found: false`.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "template": "string",
          "audience": "student",
          "requested": 1,
          "resolvedCount": 1,
          "missingCount": 1,
          "foundTags": [
           {}
          ],
          "unknownTags": [
           {}
          ],
          "audienceMismatches": [
           {}
          ],
          "totalOccurrences": 1,
          "results": [
           {
            "studentId": 1,
            "found": false,
            "resolved": "string"
           }
          ]
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "template": {
          "type": "string",
          "description": "Template string with {{tag}} placeholders"
         },
         "studentIds": {
          "type": "array",
          "description": "Array of student IDs (1-100)",
          "items": {}
         },
         "audience": {
          "type": "string",
          "description": "Per-student endpoint: only 'student' is accepted. See /resolve for the rationale. Default: student.",
          "enum": [
           "student"
          ]
         }
        },
        "required": [
         "template",
         "studentIds"
        ]
       },
       "example": {
        "template": "string",
        "studentIds": []
       }
      }
     }
    }
   }
  },
  "/v1/send/merge-tags/validate": {
   "post": {
    "operationId": "send_validateMergeTags",
    "summary": "validateMergeTags",
    "description": "Inspect a template without resolving it (no student needed). Always returns 200; check the `valid` field. Use this for draft-template iteration before committing to a real send.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "template": "string",
          "audience": "student",
          "valid": false,
          "foundTags": [
           {}
          ],
          "unknownTags": [
           {}
          ],
          "audienceMismatches": [
           {}
          ],
          "totalOccurrences": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "template": {
          "type": "string",
          "description": "Template string with {{tag}} placeholders"
         },
         "audience": {
          "type": "string",
          "description": "Optional audience scope. Tags from other audiences are flagged as mismatches.",
          "enum": [
           "student",
           "admin",
           "instructor"
          ]
         }
        },
        "required": [
         "template"
        ]
       },
       "example": {
        "template": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/delivery": {
   "get": {
    "operationId": "send_listDeliveryLogs",
    "summary": "listDeliveryLogs",
    "description": "List delivery log entries with filters and pagination",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.DeliveryLogEntry"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "channel": "email",
           "recipientId": 1,
           "recipientAddress": "string",
           "status": "queued",
           "externalId": "string",
           "templateId": 1,
           "createdOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "channel",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "email",
        "sms",
        "chat",
        "push",
        "social",
        "webhook"
       ]
      },
      "description": "Filter by channel"
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "queued",
        "sending",
        "delivered",
        "opened",
        "clicked",
        "bounced",
        "failed"
       ]
      },
      "description": "Filter by delivery status"
     },
     {
      "name": "recipientId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by student ID"
     },
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix timestamp lower bound. Also accepted as after."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Unix timestamp upper bound. Also accepted as before."
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Sort field. Prefix with - for descending. Default: -createdOn."
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (default: 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 50, max: 10000)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/delivery/{id}": {
   "get": {
    "operationId": "send_getDeliveryLog",
    "summary": "getDeliveryLog",
    "description": "Get a single delivery log entry by ID",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.DeliveryLogEntry"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "channel": "email",
          "recipientId": 1,
          "recipientAddress": "string",
          "status": "queued",
          "externalId": "string",
          "templateId": 1,
          "createdOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/preferences/{studentId}": {
   "get": {
    "operationId": "send_getPreferences",
    "summary": "getPreferences",
    "description": "Get a student's communication preferences across all channels (email, sms, chat, push). Merges explicit settings with legacy fallback.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.StudentPreferences"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "studentId": 1,
          "email": {},
          "sms": {},
          "chat": {},
          "push": {},
          "etag": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "send_updatePreferences",
    "summary": "updatePreferences",
    "description": "Update a student's communication preferences. Creates explicit rows on first write (lazy migration from legacy). Use ?preview=true to see the current and proposed values. Supports optimistic concurrency: send the etag from a previous GET back as the If-Match header (`If-Match: \"v<timestamp>\"`) to detect concurrent admin edits. Returns 412 PRECONDITION_FAILED with a recovery hint on mismatch. If-Match is opt-in; omitting it preserves last-write-wins behavior for legacy clients.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.StudentPreferences"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "studentId": 1,
            "email": {},
            "sms": {},
            "chat": {},
            "push": {},
            "etag": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "studentId": 1,
            "email": {},
            "sms": {},
            "chat": {},
            "push": {},
            "etag": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "email": {
          "type": "string",
          "description": "Email preference",
          "enum": [
           "opted_in",
           "opted_out"
          ]
         },
         "sms": {
          "type": "string",
          "description": "SMS preference",
          "enum": [
           "opted_in",
           "opted_out"
          ]
         },
         "chat": {
          "type": "string",
          "description": "Chat preference",
          "enum": [
           "opted_in",
           "opted_out"
          ]
         },
         "push": {
          "type": "string",
          "description": "Push preference",
          "enum": [
           "opted_in",
           "opted_out"
          ]
         },
         "reason": {
          "type": "string",
          "description": "Reason for change. Default: admin_override.",
          "enum": [
           "user_request",
           "admin_override",
           "system"
          ]
         }
        }
       },
       "example": {
        "email": "opted_in",
        "sms": "opted_in",
        "chat": "opted_in",
        "push": "opted_in",
        "reason": "user_request"
       }
      }
     }
    }
   }
  },
  "/v1/send/audience-check": {
   "post": {
    "operationId": "send_audienceCheck",
    "summary": "audienceCheck",
    "description": "Preflight a handpicked audience for email or SMS: runs the same eligibility rules a send applies (not found, no address, opted out, suppressed) without sending. Returns requested, deliverable, per-reason skipped counts and the excluded recipients with names and reasons, so the composer can warn before the send. Also returns `held`: who the per-person send limits (cooldown, daily caps, weekly marketing cap, quiet hours) would hold right now, with the rule and the unix time each clears. Nothing is written.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.DeliverabilityPreview"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "requested": 1,
          "deliverable": 1,
          "skipped": {},
          "held": []
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "channel": {
          "type": "string",
          "enum": [
           "email",
           "sms"
          ]
         },
         "recipientIds": {
          "type": "array",
          "description": "Student ids, up to 5000. Send this or segmentId.",
          "items": {
           "description": "integer"
          }
         },
         "segmentId": {
          "type": "integer",
          "description": "A segment, resolved on the server. Send this or recipientIds."
         },
         "category": {
          "type": "string",
          "description": "The send's metadata.category; 'marketing' adds the weekly marketing cap to `held`."
         }
        },
        "required": [
         "channel"
        ]
       },
       "example": {
        "channel": "email"
       }
      }
     }
    }
   }
  },
  "/v1/send/preview": {
   "post": {
    "operationId": "send_previewEmail",
    "summary": "previewEmail",
    "description": "Render a block-based email document to HTML + plain text. Optionally resolves merge tags for a specific student. Does not send anything.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.PreviewResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "html": "string",
          "text": "string",
          "subject": "string",
          "blockCount": 1,
          "footerAutoAppended": false,
          "mergeTagsResolved": false,
          "mergeTagsFound": [
           "string"
          ],
          "warnings": [
           "string"
          ]
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "document": {
          "$ref": "#/components/schemas/send.EmailDocument",
          "description": "Block-based email document. See EmailDocument model."
         },
         "subject": {
          "type": "string",
          "description": "Email subject line. Supports {{merge_tags}}.",
          "maxLength": 998
         },
         "recipientId": {
          "type": "integer",
          "description": "Student ID to resolve merge tags for. If omitted, {{tags}} are left as-is in the output."
         },
         "audience": {
          "type": "string",
          "description": "The step's recipient being composed for (default: student): routing is per step; the automation's audience is a classification tag. \"admin\" additionally resolves school-aggregate admin tags (with or without a recipientId) and unknown-tag warnings accept both tag audiences, matching delivery-time resolution for admin-recipient emails.",
          "enum": [
           "student",
           "admin"
          ]
         }
        },
        "required": [
         "document"
        ]
       },
       "example": {
        "document": {
         "version": 1,
         "settings": {
          "backgroundColor": "1F7F5C",
          "contentWidth": 1,
          "fontFamily": "string"
         },
         "blocks": [
          {
           "type": "heading",
           "id": "string",
           "_shapes": {}
          }
         ]
        }
       }
      }
     }
    }
   }
  },
  "/v1/send/drafts": {
   "get": {
    "operationId": "send_listDrafts",
    "summary": "listDrafts",
    "description": "List the current user's compose drafts (most recent first). Per-user scoping: only your own drafts are visible.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.Draft"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "channel": "email",
           "subject": "string",
           "content": "string",
           "recipients": {},
           "scheduleOn": 1793836800,
           "createdOn": 1793836800,
           "updatedOn": 1793836800
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (default: 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 50)"
     },
     {
      "name": "channel",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "email",
        "sms",
        "social"
       ]
      },
      "description": "Only this channel's drafts, so an SMS draft is never offered to the email composer."
     },
     {
      "name": "summary",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "true swaps each draft's stored document for the two lines a list shows (title, preview) plus purgesOn, the day the 30 day purge takes it. Drafts do not store recipients, so there is no recipient line."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send_createDraft",
    "summary": "createDraft",
    "description": "Save a new compose draft. Auto-saves from the email/SMS composer.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.Draft"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "channel": "email",
            "subject": "string",
            "content": "string",
            "recipients": {},
            "scheduleOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "channel": "email",
            "subject": "string",
            "content": "string",
            "recipients": {},
            "scheduleOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "channel": {
          "type": "string",
          "description": "Draft channel",
          "enum": [
           "email",
           "sms",
           "social"
          ]
         },
         "subject": {
          "type": "string",
          "description": "Email subject",
          "maxLength": 500
         },
         "content": {
          "type": "string",
          "description": "Draft content (block JSON or text)"
         },
         "recipients": {
          "type": "object",
          "description": "Recipient config: { studentIds?: number[], segmentId?: number }"
         },
         "scheduleOn": {
          "type": "integer",
          "description": "Scheduled send time (unix timestamp). Null = not scheduled."
         }
        },
        "required": [
         "channel"
        ]
       },
       "example": {
        "channel": "email"
       }
      }
     }
    }
   }
  },
  "/v1/send/drafts/{id}": {
   "get": {
    "operationId": "send_getDraft",
    "summary": "getDraft",
    "description": "Get a single draft by ID (must belong to the requesting user)",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.Draft"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "channel": "email",
          "subject": "string",
          "content": "string",
          "recipients": {},
          "scheduleOn": 1793836800,
          "createdOn": 1793836800,
          "updatedOn": 1793836800
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "send_updateDraft",
    "summary": "updateDraft",
    "description": "Update a draft. All fields optional; partial updates supported.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.Draft"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "channel": "email",
            "subject": "string",
            "content": "string",
            "recipients": {},
            "scheduleOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "channel": "email",
            "subject": "string",
            "content": "string",
            "recipients": {},
            "scheduleOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "subject": {
          "type": "string",
          "description": "Email subject"
         },
         "content": {
          "type": "string",
          "description": "Draft content"
         },
         "recipients": {
          "type": "object",
          "description": "Recipient config"
         },
         "scheduleOn": {
          "type": "integer",
          "description": "Scheduled send time (null to clear)"
         }
        }
       },
       "example": {
        "subject": "string",
        "content": "string",
        "recipients": {},
        "scheduleOn": 1
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "send_deleteDraft",
    "summary": "deleteDraft",
    "description": "Permanently delete a draft. Hard delete; not recoverable. Requires ?confirm=true.",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/assets": {
   "post": {
    "operationId": "send_uploadAsset",
    "summary": "uploadAsset",
    "description": "Upload an image for use in the email composer (returns a permanent public URL to embed, served from /v1/public/send-assets; PNG, JPG, GIF or WEBP, max 10 MB; 503 SERVICE_UNAVAILABLE when storage is down), or with kind=attachment a file to send with a manual email (PDF, JPG, PNG, DOC, DOCX; max 5 MB; returns a storageKey for sendEmail.attachment).",
    "tags": [
     "send"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.UploadedAsset"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "storageKey": "string",
          "url": "string",
          "mimeType": "string",
          "sizeBytes": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "multipart/form-data": {
       "schema": {
        "type": "object",
        "properties": {
         "file": {
          "type": "string",
          "description": "The file (multipart/form-data). Images: png, jpeg, gif, webp, max 10 MB. Attachments: pdf, jpg, png, doc, docx, max 5 MB.",
          "format": "binary"
         },
         "kind": {
          "type": "string",
          "description": "Omit for an inline composer image. 'attachment' stores a file to send with an email.",
          "enum": [
           "attachment"
          ]
         }
        },
        "required": [
         "file"
        ]
       },
       "example": {
        "file": "(file contents)"
       }
      }
     }
    }
   }
  },
  "/v1/send/automations": {
   "get": {
    "operationId": "send_automations_list",
    "summary": "list",
    "description": "List automations for the school (paginated). Returns metadata with trigger/step counts; use get-by-id for full tree. Filterable by status, category, audience, and name search.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.automations.AutomationListItem"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "description": "string",
           "status": "draft",
           "category": "string",
           "audience": "student",
           "source": "custom",
           "triggerCount": 1,
           "stepCount": 1,
           "statsActiveEnrollments": 1,
           "statsCompleted": 1,
           "statsTotalEnrollments": 1,
           "createdOn": 1793836800,
           "updatedOn": 1793836800,
           "hasUnpublishedChanges": false
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "draft",
        "active",
        "paused",
        "archived"
       ]
      },
      "description": "Filter by automation status"
     },
     {
      "name": "category",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "onboarding",
        "retention",
        "milestones",
        "billing",
        "marketing",
        "operational",
        "system_admin",
        "system_instructor"
       ]
      },
      "description": "Filter by category"
     },
     {
      "name": "audience",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "student",
        "admin",
        "instructor"
       ]
      },
      "description": "Filter by target audience"
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Search by automation name (substring match)"
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Sort field. Prefix with - for descending. Default: name. Allowed fields: name, status, category, createdOn, updatedOn"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (default: 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 50, max: 10000)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send_automations_create",
    "summary": "create",
    "description": "Create a new automation with triggers and steps. Always starts as draft. Name must be unique per school.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.automations.AutomationDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Automation name (unique per school)",
          "minLength": 1,
          "maxLength": 200
         },
         "description": {
          "type": "string",
          "description": "Optional description",
          "maxLength": 5000
         },
         "category": {
          "type": "string",
          "description": "Automation category",
          "enum": [
           "onboarding",
           "retention",
           "milestones",
           "billing",
           "marketing",
           "operational",
           "system_admin",
           "system_instructor"
          ]
         },
         "audience": {
          "type": "string",
          "description": "Target audience (default: student)",
          "enum": [
           "student",
           "admin",
           "instructor"
          ]
         },
         "triggers": {
          "type": "array",
          "description": "At least one trigger is required",
          "items": {
           "$ref": "#/components/schemas/send.automations.TriggerInput"
          }
         },
         "steps": {
          "type": "array",
          "description": "At least one step is required",
          "items": {
           "$ref": "#/components/schemas/send.automations.StepInput"
          }
         }
        },
        "required": [
         "name",
         "category",
         "triggers",
         "steps"
        ]
       },
       "example": {
        "name": "string",
        "category": "onboarding",
        "triggers": [
         {
          "type": "event",
          "eventName": "string",
          "schedule": "string",
          "segmentId": 1,
          "conditions": {},
          "reEnrollmentPolicy": "once",
          "reEnrollmentPeriodDays": 1
         }
        ],
        "steps": [
         {
          "parentStepId": 1,
          "branchPath": "yes",
          "order": 1,
          "type": "string",
          "config": {},
          "urgency": "buffered",
          "exitConditions": [
           {}
          ]
         }
        ]
       }
      }
     }
    }
   }
  },
  "/v1/send/automations/{id}": {
   "get": {
    "operationId": "send_automations_get",
    "summary": "get",
    "description": "Get a single automation by ID with full trigger and step tree. The response includes an ETag header (format: \"v<timestamp>\") that callers should send back as If-Match on the next update for optimistic concurrency. Without If-Match, two concurrent PATCHes silently clobber each other's triggers/steps.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.automations.AutomationDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "description": "string",
          "status": "draft",
          "category": "string",
          "audience": "student",
          "reviewPoints": [],
          "source": "custom",
          "recipientUserIds": [
           1
          ],
          "recipientInstructorIds": [
           1
          ],
          "statsActiveEnrollments": 1,
          "statsCompleted": 1,
          "statsCancelled": 1,
          "statsTotalEnrollments": 1,
          "statsTotalSends": 1,
          "statsTotalOpens": 1,
          "statsTotalClicks": 1,
          "triggers": [
           {
            "id": 1,
            "type": "event",
            "eventName": "string",
            "schedule": "string",
            "segmentId": 1,
            "conditions": {},
            "reEnrollmentPolicy": "once",
            "reEnrollmentPeriodDays": 1
           }
          ],
          "steps": [
           {
            "id": 1,
            "stepKey": "string",
            "parentStepId": 1,
            "branchPath": "yes",
            "order": 1,
            "type": "send_email",
            "config": {},
            "urgency": "buffered",
            "exitConditions": [
             {}
            ]
           }
          ],
          "createdBy": 1,
          "createdOn": 1793836800,
          "updatedOn": 1793836800,
          "draft": {},
          "hasUnpublishedChanges": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "send_automations_update",
    "summary": "update",
    "description": "Update an automation. IMPORTANT: for ACTIVE or PAUSED automations this saves a DRAFT, not the live rows; what students receive is unchanged until you call POST /:id/publish. Draft-status automations update directly. If triggers or steps are provided, they replace all existing ones in the target (draft or live rows). Steps carry a stable stepKey: echo each step's stepKey from your last GET verbatim and mint a fresh UUID for added steps; publish matches steps by key so in-flight enrollments survive edits, and refuses keyless payloads. System automations cannot be modified (403). Optimistic concurrency: if you send an If-Match header (the ETag from your last GET, format \"v<timestamp>\" or \"*\" for any), a 412 PRECONDITION_FAILED is returned when another writer has modified the row; for live automations the ETag tracks the draft's version. Without If-Match the update proceeds unconditionally (last writer wins).",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.automations.AutomationDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "New automation name",
          "minLength": 1,
          "maxLength": 200
         },
         "description": {
          "type": "string",
          "description": "New description"
         },
         "category": {
          "type": "string",
          "description": "New category",
          "enum": [
           "onboarding",
           "retention",
           "milestones",
           "billing",
           "marketing",
           "operational",
           "system_admin",
           "system_instructor"
          ]
         },
         "audience": {
          "type": "string",
          "description": "New audience",
          "enum": [
           "student",
           "admin",
           "instructor"
          ]
         },
         "triggers": {
          "type": "array",
          "description": "Replace all triggers",
          "items": {
           "$ref": "#/components/schemas/send.automations.TriggerInput"
          }
         },
         "steps": {
          "type": "array",
          "description": "Replace all steps",
          "items": {
           "$ref": "#/components/schemas/send.automations.StepInput"
          }
         }
        }
       },
       "example": {
        "name": "string",
        "description": "string",
        "category": "onboarding",
        "audience": "student",
        "triggers": [
         {
          "type": "event",
          "eventName": "string",
          "schedule": "string",
          "segmentId": 1,
          "conditions": {},
          "reEnrollmentPolicy": "once",
          "reEnrollmentPeriodDays": 1
         }
        ],
        "steps": [
         {
          "parentStepId": 1,
          "branchPath": "yes",
          "order": 1,
          "type": "string",
          "config": {},
          "urgency": "buffered",
          "exitConditions": [
           {}
          ]
         }
        ]
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "send_automations_delete",
    "summary": "delete",
    "description": "Soft-delete an automation. System automations cannot be deleted (403). Triggers and steps are hard-deleted; active+waiting enrollments are cancelled. Preview (`?preview=true`) returns `wouldDelete` plus `cascadeEffects` with concrete counts of `triggers`, `steps`, and `activeEnrollments` so an agent can see what it affects before confirming. Confirm gate (`?confirm=true`) is required to actually delete; the prompt also names the active-enrollment count. Supports optimistic concurrency via the If-Match header (use the ETag from a prior GET; mismatch returns 412) so an agent can't accidentally delete an automation another writer just edited.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/publish": {
   "post": {
    "operationId": "send_automations_publish",
    "summary": "publish",
    "description": "Apply the stored draft to the live automation. Steps are matched by stepKey and updated in place, so in-flight enrollments keep their position on any step you kept; enrollments waiting on a REMOVED step are cancelled with reason step_removed. Preview (`?preview=true`) returns stepsUpdated/stepsInserted/stepsRemoved and wouldCancelEnrollments so you can see what it affects first. Returns 412 if a newer draft save landed mid-publish (re-read and retry), and a validation error for keyless step payloads. 400 when there is no draft to publish.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.automations.AutomationDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/draft": {
   "delete": {
    "operationId": "send_automations_discardDraft",
    "summary": "discardDraft",
    "description": "Discard the stored draft. The live automation keeps running its published version; the next GET returns the live rows with no draft.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.automations.AutomationDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/activate": {
   "post": {
    "operationId": "send_automations_activate",
    "summary": "activate",
    "description": "Set automation status to active. Valid from: draft, paused. Once active, triggers start firing immediately and downstream messaging steps (send_email, send_sms, etc.) are sent to enrolled students. Requires ?confirm=true. The 400 confirmation prompt describes the trigger types and messaging steps so callers know what they're authorizing.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.automations.AutomationDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/pause": {
   "post": {
    "operationId": "send_automations_pause",
    "summary": "pause",
    "description": "Set automation status to paused. Valid from: active. Stops new enrollments; existing enrollments continue.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.automations.AutomationDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/mark-reviewed": {
   "post": {
    "operationId": "send_automations_markReviewed",
    "summary": "markReviewed",
    "description": "Clear the pre-launch review checklist (reviewPoints) on a library-installed automation. Checklists are seeded at import for templates that need school-specific attention (waiver reminder timing, billing retry windows, etc.) and are also cleared automatically on activation.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.automations.AutomationDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/duplicate": {
   "post": {
    "operationId": "send_automations_duplicate",
    "summary": "duplicate",
    "description": "Deep copy an automation including all triggers and steps. New automation starts as draft with ' (Copy)' appended to name.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.automations.AutomationDetail"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "description": "string",
            "status": "draft",
            "category": "string",
            "audience": "student",
            "reviewPoints": [],
            "source": "custom",
            "recipientUserIds": [
             1
            ],
            "recipientInstructorIds": [
             1
            ],
            "statsActiveEnrollments": 1,
            "statsCompleted": 1,
            "statsCancelled": 1,
            "statsTotalEnrollments": 1,
            "statsTotalSends": 1,
            "statsTotalOpens": 1,
            "statsTotalClicks": 1,
            "triggers": [
             {
              "id": 1,
              "type": "event",
              "eventName": "string",
              "schedule": "string",
              "segmentId": 1,
              "conditions": {},
              "reEnrollmentPolicy": "once",
              "reEnrollmentPeriodDays": 1
             }
            ],
            "steps": [
             {
              "id": 1,
              "stepKey": "string",
              "parentStepId": 1,
              "branchPath": "yes",
              "order": 1,
              "type": "send_email",
              "config": {},
              "urgency": "buffered",
              "exitConditions": [
               {}
              ]
             }
            ],
            "createdBy": 1,
            "createdOn": 1793836800,
            "updatedOn": 1793836800,
            "draft": {},
            "hasUnpublishedChanges": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/explain": {
   "get": {
    "operationId": "send_automations_explain",
    "summary": "explain",
    "description": "Get a plain-English explanation of what this automation does, including trigger description, step list, and enrollment stats.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.automations.AutomationExplanation"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "summary": "string",
          "triggerDescriptions": [
           "string"
          ],
          "stepDescriptions": [
           "string"
          ],
          "exitConditionCount": 1,
          "stats": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/automations/triggers": {
   "get": {
    "operationId": "send_automations_triggersCatalog",
    "summary": "triggersCatalog",
    "description": "Get the catalog of available trigger types and event names. Use this to populate trigger configuration UIs.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.automations.TriggerCatalog"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "triggerTypes": [],
          "eventNames": [
           "string"
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/automations/step-types": {
   "get": {
    "operationId": "send_automations_stepTypesCatalog",
    "summary": "stepTypesCatalog",
    "description": "Get the catalog of available step types with descriptions and categories. Use this to populate step configuration UIs.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.automations.StepTypeCatalogItem"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "type": "string",
           "description": "string",
           "category": "messaging"
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/enrollments": {
   "get": {
    "operationId": "send_automations_listEnrollments",
    "summary": "listEnrollments",
    "description": "List enrollments for an automation (paginated). Includes student names, step pointers, and a per-row `etag` (format \"v<timestamp>\") suitable for sending back as If-Match on cancelEnrollment for optimistic concurrency.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.automations.Enrollment"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "automationId": 1,
           "studentId": 1,
           "studentName": "string",
           "status": "active",
           "enrolledOn": 1793836800,
           "lastStepOn": 1793836800,
           "nextStepOn": 1793836800,
           "completedOn": 1793836800,
           "cancelledOn": 1793836800,
           "cancelReason": "string",
           "currentStepId": 1,
           "nextStepId": 1,
           "triggerEventId": 1,
           "etag": "string"
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "active",
        "waiting",
        "completed",
        "cancelled",
        "errored"
       ]
      },
      "description": "Filter by enrollment status"
     },
     {
      "name": "studentId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter by student ID"
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Sort field. Prefix with - for descending. Default: -enrolledOn. Allowed fields: enrolledOn, status, nextStepOn, completedOn"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (default: 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 50)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send_automations_manualEnroll",
    "summary": "manualEnroll",
    "description": "Manually enroll students in an automation. Automation must be active. Re-enrollment policy + opt-out + duplicate-active checks apply; ineligible students are returned in `details` with a reason. Max 100 student IDs per request.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.automations.ManualEnrollResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "enrolled": 1,
            "skipped": 1,
            "details": [
             {}
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "enrolled": 1,
            "skipped": 1,
            "details": [
             {}
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "Student IDs to enroll (1 to 100)",
          "minLength": 1,
          "maxLength": 100,
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "studentIds"
        ]
       },
       "example": {
        "studentIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/send/automations/{id}/enrollments/{enrollmentId}": {
   "delete": {
    "operationId": "send_automations_cancelEnrollment",
    "summary": "cancelEnrollment",
    "description": "Cancel a single active or waiting enrollment. Stops the automation for that student only. Already terminal (completed/cancelled/errored) returns 409 CONFLICT (state-machine, won't change). Optimistic concurrency: send `If-Match` (the row's `etag` from listEnrollments, format \"v<timestamp>\" or \"*\" for any) and a 412 PRECONDITION_FAILED is returned when the worker has advanced the row since you read it. Without `If-Match` the cancel proceeds unconditionally (last writer wins, but the underlying SQL gate still prevents cancelling an already-terminal row).",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "enrollmentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/stats": {
   "get": {
    "operationId": "send_automations_getEnrollmentStats",
    "summary": "getEnrollmentStats",
    "description": "Get enrollment statistics for an automation: total + breakdown by status, completion rate, and aggregate send/open/click counters.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.automations.EnrollmentStats"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "totalEnrollments": 1,
          "byStatus": {},
          "completionRate": 1,
          "totalSends": 1,
          "totalOpens": 1,
          "totalClicks": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/logs": {
   "get": {
    "operationId": "send_automations_listStepLogs",
    "summary": "listStepLogs",
    "description": "List per-step execution logs for the automation (cursor paginated). Filterable by enrollment, action, and result. Use for debugging branch/exit decisions and delivery outcomes.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.automations.StepLog"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/CursorMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "enrollmentId": 1,
           "stepId": 1,
           "action": "executed",
           "result": "success",
           "deliveryId": 1,
           "executedOn": 1793836800,
           "durationMs": 1,
           "detail": {}
          }
         ],
         "meta": {
          "count": 1,
          "total": 1,
          "nextCursor": null
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "enrollmentId",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Filter to one enrollment"
     },
     {
      "name": "action",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "executed",
        "skipped",
        "branched_yes",
        "branched_no",
        "cancelled_by_exit"
       ]
      },
      "description": "Filter by step action taken"
     },
     {
      "name": "result",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "success",
        "failed",
        "opted_out",
        "rate_limited",
        "anti_fatigue_suppressed",
        "combined_in_digest"
       ]
      },
      "description": "Filter by step outcome"
     },
     {
      "name": "cursor",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Cursor (last seen log ID for next page)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 50, max: 100)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/automations/{id}/share": {
   "get": {
    "operationId": "send_automations_getShare",
    "summary": "getShare",
    "description": "Get the public share-link state for this automation. Returns the share URL (if enabled), title/description, OG image, and publisher attribution settings. Used by the marketplace viral loop. See docs/MARKETPLACE-VIRAL-LOOP-PLAN.md.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.automations.ShareLinkState"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "automationId": 1,
          "enabled": false,
          "shareSlug": "string",
          "shareUrl": "https://example.com",
          "shareTitle": "string",
          "shareDescription": "string",
          "ogImagePath": "string",
          "ogImageUrl": "https://example.com",
          "publisherRefSlug": "string",
          "publisherSchoolName": "string",
          "publisherAttributionEnabled": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send_automations_toggleShare",
    "summary": "toggleShare",
    "description": "Enable or disable the public share link for this automation. When enabling, optionally set a custom title/description and toggle publisher attribution. Generates a stable shareSlug on first enable.",
    "tags": [
     "send/automations"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.automations.ShareLinkState"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "automationId": 1,
            "enabled": false,
            "shareSlug": "string",
            "shareUrl": "https://example.com",
            "shareTitle": "string",
            "shareDescription": "string",
            "ogImagePath": "string",
            "ogImageUrl": "https://example.com",
            "publisherRefSlug": "string",
            "publisherSchoolName": "string",
            "publisherAttributionEnabled": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "automationId": 1,
            "enabled": false,
            "shareSlug": "string",
            "shareUrl": "https://example.com",
            "shareTitle": "string",
            "shareDescription": "string",
            "ogImagePath": "string",
            "ogImageUrl": "https://example.com",
            "publisherRefSlug": "string",
            "publisherSchoolName": "string",
            "publisherAttributionEnabled": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "enabled": {
          "type": "boolean",
          "description": "Whether the share link should be live"
         },
         "shareTitle": {
          "type": "string",
          "description": "Public title shown on share page + OG card. Required when enabled=true.",
          "maxLength": 200
         },
         "shareDescription": {
          "type": "string",
          "description": "Public description for share page + OG card",
          "maxLength": 1000
         },
         "publisherAttributionEnabled": {
          "type": "boolean",
          "description": "Whether to show 'Shared by {school}' on the public page. Default: true (opt-out)."
         }
        },
        "required": [
         "enabled"
        ]
       },
       "example": {
        "enabled": false
       }
      }
     }
    }
   }
  },
  "/v1/send/chat/unread-count": {
   "get": {
    "operationId": "send-chat_unreadCount",
    "summary": "unreadCount",
    "description": "Total unread student-sent messages across all non-deleted conversations for the admin's school. Used for the inbox badge.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-chat.UnreadCount"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "count": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/chat/conversations": {
   "get": {
    "operationId": "send-chat_listConversations",
    "summary": "listConversations",
    "description": "Paginated inbox list, newest-first. Returns conversations with student display info + last-message preview + unread count per conversation.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-chat.ConversationWithStudent"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "status": "string",
           "isPriority": false,
           "student": {},
           "unreadCount": 1,
           "lastMessagePreview": "string",
           "lastMessageAt": 1,
           "updatedOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "active",
        "closed",
        "snoozed"
       ]
      },
      "description": "Filter by status"
     },
     {
      "name": "priorityOnly",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Show only priority-flagged conversations"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Default 1"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "1-100 (default 50)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/chat/conversations/{id}": {
   "get": {
    "operationId": "send-chat_getConversation",
    "summary": "getConversation",
    "description": "Conversation metadata (status, priority, snooze, typing).",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-chat.Conversation"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "studentId": 1,
          "status": "active",
          "isPriority": false,
          "snoozeUntil": 1,
          "studentTypingUntil": 1,
          "adminTypingUntil": 1,
          "pinnedMessageId": 1,
          "createdOn": 1,
          "updatedOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/chat/conversations/{id}/messages": {
   "get": {
    "operationId": "send-chat_getMessages",
    "summary": "getMessages",
    "description": "Paginated message history, newest first. Cursor via `beforeId`: pass the oldest message id from the previous page to get older messages.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-chat.MessagesPage"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "messages": [
           {
            "id": 1,
            "conversationId": 1,
            "senderType": "admin",
            "senderUserId": 1,
            "studentId": 1,
            "kind": "message",
            "message": "string",
            "readOn": 1,
            "createdOn": 1,
            "attachments": []
           }
          ],
          "olderCursor": 1,
          "hasMore": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "beforeId",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Oldest message id from previous page"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "1-100 (default 30)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send-chat_sendMessageToConversation",
    "summary": "sendMessageToConversation",
    "description": "Send into an existing conversation. Reopens the conversation if it was closed. `attachmentIds` links previously-uploaded orphan attachments.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-chat.SendMessageResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "conversationId": 1,
            "messageId": 1,
            "conversationCreated": false,
            "attachmentsLinked": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "conversationId": 1,
            "messageId": 1,
            "conversationCreated": false,
            "attachmentsLinked": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "message": {
          "type": "string",
          "description": "Text body; may be empty if attachmentIds is non-empty",
          "maxLength": 5000
         },
         "kind": {
          "type": "string",
          "enum": [
           "message",
           "note"
          ]
         },
         "attachmentIds": {
          "type": "array",
          "description": "Up to 5 orphan attachment IDs",
          "items": {}
         }
        }
       },
       "example": {
        "message": "string",
        "kind": "message",
        "attachmentIds": []
       }
      }
     }
    }
   }
  },
  "/v1/send/chat/broadcast": {
   "post": {
    "operationId": "send-chat_broadcast",
    "summary": "broadcast",
    "description": "Post one message into each selected student's conversation, as the school, with merge tags resolved per student. Students whose chat consent is off are skipped and named. A student who has never signed in to the student app also gets the words by email with the link to read and reply, when they have an address. The message lives in the conversations only; nothing is recorded in the Send history. The run is queued as an operation: the answer is { operationId, label }, followed through GET /v1/operations/:id.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentIds": {
          "type": "array",
          "description": "The selection (1 to 10,000)",
          "items": {
           "type": "integer"
          }
         },
         "text": {
          "type": "string",
          "description": "The message; merge tags such as {{firstname}} resolve per student",
          "maxLength": 5000
         }
        },
        "required": [
         "studentIds",
         "text"
        ]
       },
       "example": {
        "studentIds": [
         1
        ],
        "text": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/chat/messages": {
   "post": {
    "operationId": "send-chat_sendMessageToStudent",
    "summary": "sendMessageToStudent",
    "description": "Send a message to a student by studentId. Creates the conversation if none exists. Kind='message' delivers a push; kind='note' is admin-internal and suppresses push. `attachmentIds` links previously-uploaded orphan attachments.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-chat.SendMessageResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "conversationId": 1,
            "messageId": 1,
            "conversationCreated": false,
            "attachmentsLinked": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "conversationId": 1,
            "messageId": 1,
            "conversationCreated": false,
            "attachmentsLinked": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "studentId": {
          "type": "number"
         },
         "message": {
          "type": "string",
          "description": "Text body; may be empty if attachmentIds is non-empty",
          "maxLength": 5000
         },
         "kind": {
          "type": "string",
          "description": "Default 'message'",
          "enum": [
           "message",
           "note"
          ]
         },
         "attachmentIds": {
          "type": "array",
          "description": "Up to 5 orphan attachment IDs returned from POST /attachments",
          "items": {}
         }
        },
        "required": [
         "studentId"
        ]
       },
       "example": {
        "studentId": 1
       }
      }
     }
    }
   }
  },
  "/v1/send/chat/conversations/{id}/read": {
   "post": {
    "operationId": "send-chat_markRead",
    "summary": "markRead",
    "description": "Mark all student-sent messages in this conversation as read. Note: admin-sent messages don't have student-side read tracking (legacy asymmetric model).",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-chat.MarkReadResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "markedCount": 1,
          "message": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/send/chat/conversations/{id}/close": {
   "post": {
    "operationId": "send-chat_closeConversation",
    "summary": "closeConversation",
    "description": "Atomic: set status to 'closed'. Idempotent. The conversation auto-reopens on next message send.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-chat.Conversation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "studentId": 1,
            "status": "active",
            "isPriority": false,
            "snoozeUntil": 1,
            "studentTypingUntil": 1,
            "adminTypingUntil": 1,
            "pinnedMessageId": 1,
            "createdOn": 1,
            "updatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "studentId": 1,
            "status": "active",
            "isPriority": false,
            "snoozeUntil": 1,
            "studentTypingUntil": 1,
            "adminTypingUntil": 1,
            "pinnedMessageId": 1,
            "createdOn": 1,
            "updatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "seenUpdatedOn": {
          "type": "integer",
          "description": "The conversation's updatedOn as the caller last saw it. If a message arrived since, the close is refused (409) and nothing is written."
         }
        }
       },
       "example": {
        "seenUpdatedOn": 1
       }
      }
     }
    }
   }
  },
  "/v1/send/chat/conversations/{id}/reopen": {
   "post": {
    "operationId": "send-chat_reopenConversation",
    "summary": "reopenConversation",
    "description": "Atomic: set status back to 'active' and clear any active snooze. Idempotent.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-chat.Conversation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "studentId": 1,
            "status": "active",
            "isPriority": false,
            "snoozeUntil": 1,
            "studentTypingUntil": 1,
            "adminTypingUntil": 1,
            "pinnedMessageId": 1,
            "createdOn": 1,
            "updatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "studentId": 1,
            "status": "active",
            "isPriority": false,
            "snoozeUntil": 1,
            "studentTypingUntil": 1,
            "adminTypingUntil": 1,
            "pinnedMessageId": 1,
            "createdOn": 1,
            "updatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/chat/conversations/{id}/snooze": {
   "post": {
    "operationId": "send-chat_snoozeConversation",
    "summary": "snoozeConversation",
    "description": "Atomic: snooze the conversation until `until` (unix seconds). Sets status='snoozed'. Pass until=null to clear the snooze (equivalent to reopen).",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-chat.Conversation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "studentId": 1,
            "status": "active",
            "isPriority": false,
            "snoozeUntil": 1,
            "studentTypingUntil": 1,
            "adminTypingUntil": 1,
            "pinnedMessageId": 1,
            "createdOn": 1,
            "updatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "studentId": 1,
            "status": "active",
            "isPriority": false,
            "snoozeUntil": 1,
            "studentTypingUntil": 1,
            "adminTypingUntil": 1,
            "pinnedMessageId": 1,
            "createdOn": 1,
            "updatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "until": {
          "type": "number",
          "description": "Unix seconds when snooze expires; pass null to clear"
         },
         "seenUpdatedOn": {
          "type": "integer",
          "description": "The conversation's updatedOn as the caller last saw it. If a message arrived since, the snooze is refused (409) and nothing is written."
         }
        }
       },
       "example": {
        "until": 1,
        "seenUpdatedOn": 1
       }
      }
     }
    }
   }
  },
  "/v1/send/chat/conversations/{id}/priority": {
   "post": {
    "operationId": "send-chat_setPriority",
    "summary": "setPriority",
    "description": "Atomic: set the priority flag. Priority conversations surface on the inbox 'Priority' filter.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-chat.Conversation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "studentId": 1,
            "status": "active",
            "isPriority": false,
            "snoozeUntil": 1,
            "studentTypingUntil": 1,
            "adminTypingUntil": 1,
            "pinnedMessageId": 1,
            "createdOn": 1,
            "updatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "studentId": 1,
            "status": "active",
            "isPriority": false,
            "snoozeUntil": 1,
            "studentTypingUntil": 1,
            "adminTypingUntil": 1,
            "pinnedMessageId": 1,
            "createdOn": 1,
            "updatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "value": {
          "type": "boolean",
          "description": "true = priority, false = normal"
         }
        },
        "required": [
         "value"
        ]
       },
       "example": {
        "value": false
       }
      }
     }
    }
   }
  },
  "/v1/send/chat/conversations/{id}/pin": {
   "post": {
    "operationId": "send-chat_pinMessage",
    "summary": "pinMessage",
    "description": "Atomic: pin a message inside the conversation, or clear the pin. Single-slot per conversation; pinning a new message replaces the previous pin. Server validates the message belongs to this conversation.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-chat.Conversation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "studentId": 1,
            "status": "active",
            "isPriority": false,
            "snoozeUntil": 1,
            "studentTypingUntil": 1,
            "adminTypingUntil": 1,
            "pinnedMessageId": 1,
            "createdOn": 1,
            "updatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "studentId": 1,
            "status": "active",
            "isPriority": false,
            "snoozeUntil": 1,
            "studentTypingUntil": 1,
            "adminTypingUntil": 1,
            "pinnedMessageId": 1,
            "createdOn": 1,
            "updatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "messageId": {
          "type": "number",
          "description": "ID of a message in this conversation. Pass null to clear the pin."
         }
        },
        "required": [
         "messageId"
        ]
       },
       "example": {
        "messageId": 1
       }
      }
     }
    }
   }
  },
  "/v1/send/chat/conversations/{id}/messages/{messageId}": {
   "delete": {
    "operationId": "send-chat_deleteMessage",
    "summary": "deleteMessage",
    "description": "Soft-delete a message (sets deleted_on). Requires ?confirm=true.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "messageId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/chat/conversations/{id}/typing": {
   "post": {
    "operationId": "send-chat_setTyping",
    "summary": "setTyping",
    "description": "Heartbeat: records that the admin is typing, expiring after `durationSec` (default 10s). Clients call every 2-3s while user types; no explicit stop needed.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-chat.TypingResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "expiresAt": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "durationSec": {
          "type": "number",
          "description": "1-60 (default 10)"
         }
        }
       },
       "example": {
        "durationSec": 1
       }
      }
     }
    }
   }
  },
  "/v1/send/chat/push/key": {
   "get": {
    "operationId": "send-chat_getPushKey",
    "summary": "getPushKey",
    "description": "Returns the VAPID public key the admin browser needs to call pushManager.subscribe().",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-chat.PushKey"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "publicKey": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/chat/push/subscribe": {
   "post": {
    "operationId": "send-chat_subscribePush",
    "summary": "subscribePush",
    "description": "Register (or refresh) this browser's push subscription. Body exactly matches PushSubscription.toJSON() from the Web Push API.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-chat.SubscribeResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "subscriptionId": 1,
          "activeSubscriptions": 1,
          "message": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "endpoint": {
          "type": "string",
          "maxLength": 512
         },
         "keys": {
          "type": "object",
          "description": "{ p256dh, auth }; required by VAPID"
         }
        },
        "required": [
         "endpoint",
         "keys"
        ]
       },
       "example": {
        "endpoint": "string",
        "keys": {}
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "send-chat_unsubscribePush",
    "summary": "unsubscribePush",
    "description": "Disable this browser's push subscription. A signed-in admin's browser only: an API key is refused 401, since a key has no browser to subscribe.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-chat.SubscribeResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "subscriptionId": 1,
          "activeSubscriptions": 1,
          "message": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "RATE_LIMITED"
    ],
    "x-risk": "reversible",
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "endpoint": {
          "type": "string",
          "maxLength": 512
         }
        },
        "required": [
         "endpoint"
        ]
       },
       "example": {
        "endpoint": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/chat/attachments": {
   "post": {
    "operationId": "send-chat_uploadAttachment",
    "summary": "uploadAttachment",
    "description": "Upload an attachment (multipart/form-data, field \"file\"). Images get a 400x400 jpeg thumbnail auto-generated. Returns the attachment id; pass it in attachmentIds on the send-message call to link it. Attachments unreferenced after 24h are purged. Allowed types: image/jpeg, image/png, image/webp, image/gif, application/pdf. Max 10485760 bytes.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-chat.Attachment"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "filename": "string",
          "mimeType": "string",
          "sizeBytes": 1,
          "width": 1,
          "height": 1,
          "hasThumbnail": false,
          "purgedOn": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/send/chat/attachments/{id}": {
   "get": {
    "operationId": "send-chat_serveAttachment",
    "summary": "serveAttachment",
    "description": "302-redirect to a 10-minute signed bucket URL. `?variant=thumb` serves the thumbnail for images; default serves the original. Returns 404 if the attachment has been purged (chat attachments are the first category auto-reclaimed when a school is over its storage quota).",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "variant",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "thumb",
        "original"
       ]
      },
      "description": "Default 'original'"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/chat/attachments/reclaim": {
   "post": {
    "operationId": "send-chat_reclaimAttachments",
    "summary": "reclaimAttachments",
    "description": "Manually reclaim chat-attachment storage: purges oldest chat attachments for this school until `bytes` are freed (or no attachments remain). Paired with the 413 response on quota-exceeded uploads so admins can immediately free space instead of waiting for the daily auto-trim. Emits chat.attachments.purged domain event so dashboard nudges can surface the activity to the school owner. Use ?preview=true to dry-run; ?confirm=true is required for live purges.",
    "tags": [
     "send-chat"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-chat.ReclaimResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "purgedCount": 1,
            "freedBytes": 1,
            "purgedIds": [],
            "usageBefore": {},
            "usageAfter": {},
            "message": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "purgedCount": 1,
            "freedBytes": 1,
            "purgedIds": [],
            "usageBefore": {},
            "usageAfter": {},
            "message": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "bytes",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "required": true,
      "description": "Target bytes to free"
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/social/oauth/start": {
   "post": {
    "operationId": "send-social_oauthStart",
    "summary": "oauthStart",
    "description": "Returns the Meta authorize URL for the admin browser to redirect to. Meta will redirect back to apps/services which calls the public complete endpoint.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "returnTo": {
          "type": "string",
          "description": "URL to return the admin to after successful connection"
         }
        }
       },
       "example": {
        "returnTo": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/social/oauth/discovery": {
   "get": {
    "operationId": "send-social_oauthDiscovery",
    "summary": "oauthDiscovery",
    "description": "Read back the cached discovery result by token. Used by the admin picker UI after the public callback redirects with ?discoveryToken=xxx. Returns 404 if the cache has expired (10 min TTL).",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "token",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "The discoveryToken returned from POST /v1/public/send/social/oauth-complete"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/social/connections": {
   "get": {
    "operationId": "send-social_listConnections",
    "summary": "listConnections",
    "description": "List connected social accounts for this school. Filterable by platform.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-social.Connection"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "platform": "facebook",
           "platformAccountId": "string",
           "accountName": "string",
           "accountAvatarUrl": "string",
           "status": "active",
           "connectedOn": 1,
           "tokenExpiresOn": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "platform",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "facebook",
        "instagram"
       ]
      },
      "description": "Filter by platform"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send-social_createConnections",
    "summary": "createConnections",
    "description": "Save the admin's chosen accounts from an OAuth discovery session. Body includes the discoveryToken returned by the public callback endpoint.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-social.Connection"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "platform": "facebook",
           "platformAccountId": "string",
           "accountName": "string",
           "accountAvatarUrl": "string",
           "status": "active",
           "connectedOn": 1,
           "tokenExpiresOn": 1
          }
         ]
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "accounts": {
          "type": "array",
          "description": "[{ platform, platformAccountId }]: subset of discovery result",
          "items": {}
         },
         "discoveryToken": {
          "type": "string",
          "description": "Token returned by POST /v1/public/send/social/oauth-complete"
         }
        },
        "required": [
         "accounts",
         "discoveryToken"
        ]
       },
       "example": {
        "accounts": [],
        "discoveryToken": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/social/connections/{id}": {
   "get": {
    "operationId": "send-social_getConnection",
    "summary": "getConnection",
    "description": "Single connection metadata.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-social.Connection"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "platform": "facebook",
          "platformAccountId": "string",
          "accountName": "string",
          "accountAvatarUrl": "string",
          "status": "active",
          "connectedOn": 1,
          "tokenExpiresOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "delete": {
    "operationId": "send-social_deleteConnection",
    "summary": "deleteConnection",
    "description": "Disconnect an account. Best-effort platform-side OAuth revoke; local row hard-deleted (no soft-delete trail, since OAuth credentials must be purged). Use ?preview=true to see scheduled-post fallout first; ?confirm=true required to execute.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/social/connections/{id}/refresh": {
   "post": {
    "operationId": "send-social_refreshConnection",
    "summary": "refreshConnection",
    "description": "Force a token refresh now. Normally unnecessary; the nightly worker handles pre-expiry refresh.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/send/social/posts": {
   "get": {
    "operationId": "send-social_listPosts",
    "summary": "listPosts",
    "description": "Paginated post list, newest first.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-social.Post"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "content": "string",
           "mediaIds": [],
           "targets": [],
           "status": "draft",
           "scheduledOn": 1,
           "publishedOn": 1,
           "createdOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "draft",
        "scheduled",
        "publishing",
        "published",
        "partial",
        "failed"
       ]
      }
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "1-100 (default 25)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send-social_createPost",
    "summary": "createPost",
    "description": "Create a post. Omit scheduledOn to publish immediately (PUBLIC, IRREVERSIBLE; requires ?confirm=true). Provide scheduledOn to queue for later (no confirm needed; cancel via DELETE before due time). Text max 2200 chars (IG limit; FB accepts more). Up to 10 media attachments (IG carousel cap). Partial success is permitted; per-target errors surface on the Post response. Use ?preview=true for a dry-run report (targets, media, schedule).",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-social.Post"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "content": "string",
            "mediaIds": [],
            "targets": [],
            "status": "draft",
            "scheduledOn": 1,
            "publishedOn": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "content": "string",
            "mediaIds": [],
            "targets": [],
            "status": "draft",
            "scheduledOn": 1,
            "publishedOn": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Confirmation required (condition: immediate_only). Pass confirm=true to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "content": {
          "type": "string",
          "description": "Body text / caption",
          "maxLength": 2200
         },
         "mediaIds": {
          "type": "array",
          "description": "Media IDs in desired display order",
          "items": {}
         },
         "targets": {
          "type": "array",
          "description": "[{ connectionId, options? }]: which connected accounts to publish to",
          "items": {}
         },
         "scheduledOn": {
          "type": "number",
          "description": "Unix seconds; absent = publish now (requires ?confirm=true)"
         }
        },
        "required": [
         "targets"
        ]
       },
       "example": {
        "targets": []
       }
      }
     }
    }
   }
  },
  "/v1/send/social/posts/{id}": {
   "get": {
    "operationId": "send-social_getPost",
    "summary": "getPost",
    "description": "Full post detail with per-target results.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-social.Post"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "content": "string",
          "mediaIds": [],
          "targets": [],
          "status": "draft",
          "scheduledOn": 1,
          "publishedOn": 1,
          "createdOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "send-social_updatePost",
    "summary": "updatePost",
    "description": "Update a draft or scheduled post. Published/partial/failed posts are immutable.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-social.Post"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "content": "string",
            "mediaIds": [],
            "targets": [],
            "status": "draft",
            "scheduledOn": 1,
            "publishedOn": 1,
            "createdOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "content": "string",
            "mediaIds": [],
            "targets": [],
            "status": "draft",
            "scheduledOn": 1,
            "publishedOn": 1,
            "createdOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "content": {
          "type": "string",
          "maxLength": 2200
         },
         "mediaIds": {
          "type": "array",
          "items": {}
         },
         "scheduledOn": {
          "type": "number",
          "description": "Null to revert to draft"
         }
        }
       },
       "example": {
        "content": "string",
        "mediaIds": [],
        "scheduledOn": 1
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "send-social_deletePost",
    "summary": "deletePost",
    "description": "Delete a post (soft, recoverable from logs). For scheduled posts this cancels the scheduled publish. Published posts are soft-deleted (history preserved). Cannot delete a post mid-publish (status='publishing'). Use ?preview=true to see the would-delete payload; ?confirm=true required to execute.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/social/media": {
   "get": {
    "operationId": "send-social_listMedia",
    "summary": "listMedia",
    "description": "Paginated media library for this school.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-social.Media"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "filename": "string",
           "mimeType": "string",
           "sizeBytes": 1,
           "width": 1,
           "height": 1,
           "tags": [],
           "previewUrl": "string",
           "thumbnailUrl": "string",
           "createdOn": 1,
           "lastUsedOn": 1,
           "deleted": false
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "tag",
      "in": "query",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send-social_uploadMedia",
    "summary": "uploadMedia",
    "description": "Upload media (multipart/form-data; field \"file\"). Optional \"tags\" field as JSON array or comma-list. Allowed types: image/jpeg, image/png, video/mp4, video/quicktime. Max 104857600 bytes. Counts toward the school's 10 GB storage quota; social media is NOT auto-purged (unlike chat attachments); user-initiated delete only.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-social.Media"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "filename": "string",
          "mimeType": "string",
          "sizeBytes": 1,
          "width": 1,
          "height": 1,
          "tags": [],
          "previewUrl": "string",
          "thumbnailUrl": "string",
          "createdOn": 1,
          "lastUsedOn": 1,
          "deleted": false
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ]
   }
  },
  "/v1/send/social/media/{id}": {
   "delete": {
    "operationId": "send-social_deleteMedia",
    "summary": "deleteMedia",
    "description": "Delete a media item. Bucket objects are removed (irreversible); row stays so historical posts can render '(media removed)' tombstones. Use ?preview=true to see how many historical posts will be affected; ?confirm=true required to execute.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/social/storage": {
   "get": {
    "operationId": "send-social_getStorageUsage",
    "summary": "getStorageUsage",
    "description": "Per-school storage snapshot used by the media library UI to render a usage bar. Returns the same StorageUsage shape that drives the 10 GB quota check at upload time.",
    "tags": [
     "send-social"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-social.StorageUsage"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "studentFilesBytes": 1,
          "chatAttachmentsBytes": 1,
          "totalBytes": 1,
          "limitBytes": 1,
          "pctUsed": 1,
          "overQuota": false,
          "availableBytes": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/segments": {
   "get": {
    "operationId": "send-segments_list",
    "summary": "list",
    "description": "List segments for the school (paginated). Each row is enriched with `sentence` (English rendering of the rule tree) and `_links`/`_actions` for direct navigation.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-segments.Segment"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "schoolId": 1,
           "name": "string",
           "description": "string",
           "category": "retention",
           "rules": {},
           "sentence": "string",
           "isDynamic": false,
           "cachedCount": 1,
           "cachedOn": 1,
           "createdOn": 1,
           "updatedOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Case-insensitive name match"
     },
     {
      "name": "includeStatic",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Include is_dynamic=0 segments (default false)"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Page number (default 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Page size 1-500 (default 50)"
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "name",
        "-name",
        "createdOn",
        "-createdOn",
        "cachedCount",
        "-cachedCount"
       ]
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send-segments_create",
    "summary": "create",
    "description": "Create a segment. Computes the initial cachedCount synchronously, so a new segment shows its count straight away.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-segments.Segment"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "retention",
            "rules": {},
            "sentence": "string",
            "isDynamic": false,
            "cachedCount": 1,
            "cachedOn": 1,
            "createdOn": 1,
            "updatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "retention",
            "rules": {},
            "sentence": "string",
            "isDynamic": false,
            "cachedCount": 1,
            "cachedOn": 1,
            "createdOn": 1,
            "updatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "maxLength": 200
         },
         "description": {
          "type": "string",
          "maxLength": 1000
         },
         "category": {
          "type": "string",
          "description": "Optional grouping bucket for the list view.",
          "enum": [
           "retention",
           "acquisition",
           "engagement",
           "lifecycle"
          ]
         },
         "rules": {
          "$ref": "#/components/schemas/send-segments.RuleTree",
          "description": "Rule tree: see RuleTree model below. Max depth 3, max 20 leaf conditions. See /v1/send/segments/fields for queryable fields and operator compatibility."
         },
         "isDynamic": {
          "type": "boolean",
          "description": "Default true. Set false for frozen/static segments (future use)."
         }
        },
        "required": [
         "name",
         "rules"
        ]
       },
       "example": {
        "name": "string",
        "rules": {
         "type": "AND",
         "rules": [],
         "field": "string",
         "operator": "eq",
         "value": {}
        }
       }
      }
     }
    }
   }
  },
  "/v1/send/segments/{id}": {
   "get": {
    "operationId": "send-segments_get",
    "summary": "get",
    "description": "Get a single segment by ID. Response includes an ETag header (\"v<timestamp>\") for optimistic concurrency — pass it back as If-Match on PATCH to avoid clobbering concurrent edits. Also returns `sentence` (English rule rendering) and `_links`/`_actions`.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-segments.Segment"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "schoolId": 1,
          "name": "string",
          "description": "string",
          "category": "retention",
          "rules": {},
          "sentence": "string",
          "isDynamic": false,
          "cachedCount": 1,
          "cachedOn": 1,
          "createdOn": 1,
          "updatedOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "send-segments_update",
    "summary": "update",
    "description": "Update a segment. Any change to `rules` triggers a synchronous count refresh; other field changes don't recompute. Supports optimistic concurrency via the If-Match header (use the ETag from a prior GET; mismatch returns 412).",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-segments.Segment"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "retention",
            "rules": {},
            "sentence": "string",
            "isDynamic": false,
            "cachedCount": 1,
            "cachedOn": 1,
            "createdOn": 1,
            "updatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "retention",
            "rules": {},
            "sentence": "string",
            "isDynamic": false,
            "cachedCount": 1,
            "cachedOn": 1,
            "createdOn": 1,
            "updatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "maxLength": 200
         },
         "description": {
          "type": "string",
          "maxLength": 1000
         },
         "category": {
          "type": "string",
          "enum": [
           "retention",
           "acquisition",
           "engagement",
           "lifecycle"
          ]
         },
         "rules": {
          "$ref": "#/components/schemas/send-segments.RuleTree",
          "description": "Replacement rule tree. Triggers count recompute."
         },
         "isDynamic": {
          "type": "boolean"
         }
        }
       },
       "example": {
        "name": "string",
        "description": "string",
        "category": "retention",
        "rules": {
         "type": "AND",
         "rules": [],
         "field": "string",
         "operator": "eq",
         "value": {}
        },
        "isDynamic": false
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "send-segments_delete",
    "summary": "delete",
    "description": "Soft-delete a segment. Preview (`?preview=true`) returns `wouldDelete` plus `cascadeEffects.affectedAutomations` (the count of segment_entry-trigger automations that will stop firing) so an agent can see what it affects before confirming. Confirm gate (`?confirm=true`) is required to actually delete; the confirm prompt also names the affected count. Supports optimistic concurrency via the If-Match header (use the ETag from a prior GET; mismatch returns 412) so an agent can't accidentally delete a segment another writer just edited.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/segments/{id}/duplicate": {
   "post": {
    "operationId": "send-segments_duplicate",
    "summary": "duplicate",
    "description": "Clone a segment into a new editable copy. Reuses rules/description/category from the source; recomputes cachedCount; name auto-suffixes \"(Copy)\" / \"(Copy 2)\" until a free slot is found. Source row is untouched.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-segments.Segment"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "retention",
            "rules": {},
            "sentence": "string",
            "isDynamic": false,
            "cachedCount": 1,
            "cachedOn": 1,
            "createdOn": 1,
            "updatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "schoolId": 1,
            "name": "string",
            "description": "string",
            "category": "retention",
            "rules": {},
            "sentence": "string",
            "isDynamic": false,
            "cachedCount": 1,
            "cachedOn": 1,
            "createdOn": 1,
            "updatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/segments/fields": {
   "get": {
    "operationId": "send-segments_fields",
    "summary": "fields",
    "description": "Queryable field catalog for the rule builder. Returns fields, their types, allowed operators, and enum values where applicable, grouped by category. Capability-gated by default: pass ?includeUnavailable=true to see fields whose required data isn't present.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-segments.SegmentFieldCatalog"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "fields": [],
          "byCategory": {},
          "capabilities": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "includeUnavailable",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Include fields whose required capabilities aren't met (each row gets `available: false`)."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/segments/capabilities": {
   "get": {
    "operationId": "send-segments_capabilities",
    "summary": "capabilities",
    "description": "Per-school capability map: which segment field categories have data for this school. Detected from data presence, not feature flags. Cached 10 minutes. Used to filter the field catalog and pre-built template library.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-segments.SegmentCapabilities"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "ranks": false,
          "styles": false,
          "families": false,
          "subscriptions": false,
          "bookings": false,
          "leadStages": false,
          "sendActivity": false,
          "tags": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/segments/{id}/count": {
   "get": {
    "operationId": "send-segments_count",
    "summary": "count",
    "description": "Evaluate the segment live against the current student population. Returns count + timestamp. Opportunistically refreshes the cached count.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-segments.SegmentCount"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "segmentId": 1,
          "count": 1,
          "evaluatedOn": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/segments/{id}/preview": {
   "get": {
    "operationId": "send-segments_preview",
    "summary": "preview",
    "description": "Cursor-paginated preview of matching students. Cursor = last student ID. Stable across refetches because the segment query orders by students.id ASC.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-segments.SegmentPreview"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "segmentId": 1,
          "students": [],
          "nextCursor": 1,
          "hasMore": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "1-100 (default 25)"
     },
     {
      "name": "afterId",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Last student ID from previous page"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/segments/preview-count": {
   "post": {
    "operationId": "send-segments_previewCount",
    "summary": "previewCount",
    "description": "Dry-run count for an UNSAVED rule tree. Used by the builder UI to show 'matches N students' as the user composes. Same Zod validation + SQL translator as create. A malformed tree fails fast.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-segments.SegmentRulesCount"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "count": 1,
          "sentence": "string",
          "evaluatedOn": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "rules": {
          "type": "object",
          "description": "Rule tree (see RuleTree model)"
         }
        },
        "required": [
         "rules"
        ]
       },
       "example": {
        "rules": {}
       }
      }
     }
    }
   }
  },
  "/v1/send/segments/preview-members": {
   "post": {
    "operationId": "send-segments_previewMembers",
    "summary": "previewMembers",
    "description": "Dry-run member preview for an UNSAVED rule tree. Returns first N matching students with display fields.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-segments.SegmentRulesPreview"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "students": [],
          "nextCursor": 1,
          "hasMore": false
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "rules": {
          "type": "object",
          "description": "Rule tree (see RuleTree model)"
         },
         "limit": {
          "type": "number",
          "description": "1-100 (default 25)"
         },
         "afterId": {
          "type": "number",
          "description": "Cursor: last student ID seen"
         }
        },
        "required": [
         "rules"
        ]
       },
       "example": {
        "rules": {}
       }
      }
     }
    }
   }
  },
  "/v1/send/segments/rank-audience": {
   "get": {
    "operationId": "send-segments_rankAudienceCounts",
    "summary": "rankAudienceCounts",
    "description": "Active and trial students at each rank, keyed by rank ID. A student counts at their latest rank in EACH style they train, not only their latest rank overall.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-segments.RankAudienceCounts"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "counts": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/segments/rank-audience/members": {
   "post": {
    "operationId": "send-segments_rankAudienceMembers",
    "summary": "rankAudienceMembers",
    "description": "Active and trial students currently at any of the given ranks (per style, as rankAudienceCounts), paged by student ID, with the de-duplicated total. Resolve a by-rank send's recipients with this.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-segments.RankAudienceMembers"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "students": [],
          "nextCursor": 1,
          "hasMore": false,
          "total": 1
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "rankIds": {
          "type": "array",
          "description": "Rank IDs (1-500)",
          "items": {}
         },
         "limit": {
          "type": "number",
          "description": "1-100 (default 100)"
         },
         "afterId": {
          "type": "number",
          "description": "Cursor: last student ID seen"
         }
        },
        "required": [
         "rankIds"
        ]
       },
       "example": {
        "rankIds": []
       }
      }
     }
    }
   }
  },
  "/v1/send/segments/{id}/refresh": {
   "post": {
    "operationId": "send-segments_refresh",
    "summary": "refresh",
    "description": "User-initiated refresh of the cached_count. Runs synchronously. Returns previousCount, count, changed bool, and delta so an agent polling for drift can act in one round trip.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-segments.SegmentRefreshResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "segmentId": 1,
            "previousCount": 1,
            "count": 1,
            "changed": false,
            "delta": 1,
            "evaluatedOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "segmentId": 1,
            "previousCount": 1,
            "count": 1,
            "changed": false,
            "delta": 1,
            "evaluatedOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/segments/{id}/snapshot": {
   "post": {
    "operationId": "send-segments_snapshot",
    "summary": "snapshot",
    "description": "Initial materialization of segment membership for segment_entry triggers. Populates the memberships table with current members WITHOUT emitting entered events (baseline). Call this once after attaching the first segment_entry trigger so existing members don't all immediately enrol. Requires ?confirm=true: wipes any existing baseline, which can cause phantom segment.entered events on the next diff if a trigger is already active.",
    "tags": [
     "send-segments"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-segments.SegmentSnapshotResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "segmentId": 1,
            "count": 1,
            "truncated": false,
            "snapshotAt": 1,
            "message": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "segmentId": 1,
            "count": 1,
            "truncated": false,
            "snapshotAt": 1,
            "message": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/analytics/overview": {
   "get": {
    "operationId": "send-analytics_overview",
    "summary": "overview",
    "description": "Headline aggregates across all channels: totals, delivery/open/click/bounce rates, per-channel breakdown, active automations, scheduled social posts.",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-analytics.Overview"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "range": {},
          "totals": {},
          "rates": {},
          "byChannel": {},
          "activeAutomations": 1,
          "scheduledSocialPosts": 1,
          "publishedSocialPosts": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to to-30d."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to now."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/analytics/daily-volume": {
   "get": {
    "operationId": "send-analytics_dailyVolume",
    "summary": "dailyVolume",
    "description": "Cross-channel send volume per school-tz day (email, sms, chat outbound, social posts) for the dashboard chart.",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to to-30d."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to now."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/analytics/email": {
   "get": {
    "operationId": "send-analytics_email",
    "summary": "email",
    "description": "Email-specific counts + rates + daily time series.",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-analytics.EmailAnalytics"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "range": {},
          "counts": {},
          "rates": {},
          "daily": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to to-30d."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to now."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/analytics/sms": {
   "get": {
    "operationId": "send-analytics_sms",
    "summary": "sms",
    "description": "SMS counts, delivery/failure rates, and total cost in the school's subunit (cents/pence).",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-analytics.SmsAnalytics"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "range": {},
          "counts": {},
          "rates": {},
          "totalCostSubunits": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to to-30d."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to now."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/analytics/chat": {
   "get": {
    "operationId": "send-analytics_chat",
    "summary": "chat",
    "description": "Chat activity. Response-time computation is deferred; field returns null until Chunk 13 conversation_messages join lands.",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-analytics.ChatAnalytics"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "range": {},
          "messagesSent": 1,
          "messagesReceived": 1,
          "avgResponseTimeSec": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to to-30d."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to now."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/analytics/social": {
   "get": {
    "operationId": "send-analytics_social",
    "summary": "social",
    "description": "Social post counts by status (scheduled/publishing/published/partial/failed).",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-analytics.SocialAnalytics"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "range": {},
          "totals": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to to-30d."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to now."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/analytics/automations": {
   "get": {
    "operationId": "send-analytics_automations",
    "summary": "automations",
    "description": "Per-automation funnel: enrollments (in range), active, completed, cancelled, steps executed (in range).",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-analytics.AutomationFunnels"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "range": {},
          "items": [
           {
            "automationId": 1,
            "name": "string",
            "status": "string",
            "enrollments": 1,
            "activeEnrollments": 1,
            "completed": 1,
            "cancelled": 1,
            "stepsExecuted": 1
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to to-30d."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to now."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/analytics/students/{id}/score": {
   "get": {
    "operationId": "send-analytics_studentScore",
    "summary": "studentScore",
    "description": "Weighted 0-100 communication score for a single student. Formula: 100 × (0.3 if delivered>0 else 0 + 0.4 × openRate + 0.3 × clickRate), evaluated over the last 14 days.",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-analytics.StudentScore"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "studentId": 1,
          "score": 1,
          "inputs": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/schedule": {
   "get": {
    "operationId": "send-analytics_schedule",
    "summary": "schedule",
    "description": "The feed behind the Send > Schedule page: everything scheduled across channels in the range (social posts and waiting automation enrollments; one-off scheduled sends are managed at /v1/send/schedule/queue). Sorted ascending by scheduledOn.",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-analytics.ScheduleList"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "range": {},
          "items": [
           {
            "kind": "social_post",
            "id": 1,
            "scheduledOn": 1,
            "title": "string",
            "detail": "string",
            "adminPath": "string"
           }
          ],
          "truncated": false,
          "truncatedKinds": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to to-30d."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to now."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/schedule/export": {
   "get": {
    "operationId": "send-analytics_scheduleExport",
    "summary": "scheduleExport",
    "description": "iCal (text/calendar) download of the same set. It needs the key like every other call, so a calendar app cannot subscribe to it; for that use the signed URL from scheduleFeedUrl.",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "text/calendar": {
        "schema": {
         "type": "string"
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "from",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to to-30d."
     },
     {
      "name": "to",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "Unix seconds. Defaults to now."
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/schedule/feed-url": {
   "get": {
    "operationId": "send-analytics_scheduleFeedUrl",
    "summary": "scheduleFeedUrl",
    "description": "The schedule's subscribable URL (/v1/public/send/schedule/:token/feed.ics): the week behind and three months ahead, refreshed as calendar apps poll it. The URL carries a signed per-school token, since calendar apps cannot send a key; paste it into Google, Apple or Outlook as a calendar subscription.",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-analytics.FeedUrl"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "url": "https://example.com"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/schedule/feed-url/rotate": {
   "post": {
    "operationId": "send-analytics_scheduleFeedUrlRotate",
    "summary": "scheduleFeedUrlRotate",
    "description": "Revoke the current feed URL and mint a new one. URLs issued before stop working at once; every calendar subscription on them must be re-added with the new URL. ?preview=true is a dry run that mints nothing.",
    "tags": [
     "send-analytics"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-analytics.FeedUrl"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "url": "https://example.com"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "url": "https://example.com"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/library": {
   "get": {
    "operationId": "send-library_listLibrary",
    "summary": "listLibrary",
    "description": "Browse library templates. Paginated in future; today returns all.",
    "tags": [
     "send-library"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-library.LibraryListItem"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": "string",
           "name": "string",
           "category": "onboarding",
           "summary": "string",
           "tags": [],
           "audience": "student",
           "reviewBeforeLaunch": false
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "category",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "onboarding",
        "retention",
        "milestones",
        "billing",
        "marketing",
        "operational"
       ]
      }
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Substring match on name/summary/tags"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/library/{id}": {
   "get": {
    "operationId": "send-library_getLibrary",
    "summary": "getLibrary",
    "description": "Full template detail including trigger + step definitions. Also includes `overlaps` computed for THIS school: installed automations (matched by libraryRef) that cover the same student moment, each {ref, automationId, name, status, reason}. Check it before importing; when it is non-empty, confirm with the admin first.",
    "tags": [
     "send-library"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-library.LibraryTemplate"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": "string",
          "name": "string",
          "category": "onboarding",
          "description": "string",
          "summary": "string",
          "longDescription": "string",
          "bestFor": "string",
          "tags": [],
          "audience": "student",
          "trigger": {
           "type": "event",
           "eventName": "string",
           "schedule": "string",
           "conditions": {},
           "reEnrollmentPolicy": "once",
           "reEnrollmentPeriodDays": 1
          },
          "steps": [
           {
            "id": "string",
            "parentId": "string",
            "branchPath": "yes",
            "order": 1,
            "type": "string",
            "config": {},
            "urgency": "buffered",
            "exitConditions": []
           }
          ],
          "reviewBeforeLaunch": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/library/{id}/import": {
   "post": {
    "operationId": "send-library_importLibrary",
    "summary": "importLibrary",
    "description": "Import the template into this school. Creates a DRAFT automation; admin reviews before activating. Templates that declare reviewPoints copy that checklist onto the automation; clear it via /v1/send/automations/:id/mark-reviewed or by activating. If the template is already installed (matched by libraryRef, not deleted), the existing automation is returned with alreadyInstalled=true and NOTHING is created; pass force=true to install a second copy anyway. Supports ?preview=true to dry-run without writing.",
    "tags": [
     "send-library"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-library.ImportResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "automationId": 1,
            "stepCount": 1,
            "triggerCount": 1,
            "reused": false,
            "alreadyInstalled": false,
            "overlaps": []
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "automationId": 1,
            "stepCount": 1,
            "triggerCount": 1,
            "reused": false,
            "alreadyInstalled": false,
            "overlaps": []
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "force": {
          "type": "boolean",
          "description": "Skip the already-installed dedupe and create another copy of a template this school has installed before. Default false."
         },
         "name": {
          "type": "string",
          "description": "Optional override for the automation name"
         },
         "recipientUserIds": {
          "type": "array",
          "description": "Admin user IDs that receive steps sending to admins (step config.recipient='admin'). Optional: delivery falls back to the school owner.",
          "items": {}
         },
         "recipientInstructorIds": {
          "type": "array",
          "description": "Reserved for the instructor lane (not deliverable yet).",
          "items": {}
         },
         "idempotencyKey": {
          "type": "string",
          "description": "Optional. Hashed into source_ref; the (school_id, source, source_ref) unique constraint catches retries. When a duplicate is detected the existing automation is returned with reused=true (HTTP 201 still). Omit to allow multiple distinct imports."
         },
         "slotValues": {
          "type": "object",
          "description": "Slot values for personalisation tokens declared on the template (`{{slot.X}}`). Required slots that are missing fail the import; unknown slots also fail."
         }
        }
       },
       "example": {
        "force": false,
        "name": "string",
        "recipientUserIds": [],
        "recipientInstructorIds": [],
        "idempotencyKey": "string",
        "slotValues": {}
       }
      }
     }
    }
   }
  },
  "/v1/send/library/playbooks": {
   "get": {
    "operationId": "send-library_listPlaybooks",
    "summary": "listPlaybooks",
    "description": "List curated playbook bundles. Each playbook is a curated set of segments + automation templates installed together with shared slot prompts.",
    "tags": [
     "send-library"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-library.PlaybookListItem"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "ref": "string",
           "version": "string",
           "name": "string",
           "lane": "foundations",
           "summary": "string",
           "segmentCount": 1,
           "templateCount": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/library/playbooks/{ref}": {
   "get": {
    "operationId": "send-library_getPlaybook",
    "summary": "getPlaybook",
    "description": "Full playbook detail including segment + template refs and shared slots.",
    "tags": [
     "send-library"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-library.LibraryPlaybook"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "ref": "string",
          "version": "string",
          "name": "string",
          "lane": "string",
          "summary": "string",
          "longDescription": "string",
          "segmentRefs": [],
          "templateRefs": [],
          "slots": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/library/playbooks/{ref}/install": {
   "post": {
    "operationId": "send-library_installPlaybook",
    "summary": "installPlaybook",
    "description": "Install the playbook bundle. Inserts any segments not yet installed, then imports each template with idempotency keys derived from `${playbook.ref}:${template.ref}`. Re-running surfaces existing IDs rather than creating duplicates. Supports ?preview=true to dry-run.",
    "tags": [
     "send-library"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-library.PlaybookInstallResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "playbookRef": "string",
            "playbookVersion": "string",
            "segments": [],
            "templates": [],
            "skipped": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "playbookRef": "string",
            "playbookVersion": "string",
            "segments": [],
            "templates": [],
            "skipped": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "slotValues": {
          "type": "object",
          "description": "Slot values for personalisation tokens declared by the playbook or any of its templates."
         }
        }
       },
       "example": {
        "slotValues": {}
       }
      }
     }
    }
   }
  },
  "/v1/send/library/segments": {
   "get": {
    "operationId": "send-library_listLibrarySegments",
    "summary": "listLibrarySegments",
    "description": "List curated library segments available for standalone install. These are protected segment definitions consumed by Pro automations and bundled in playbooks; this endpoint exposes them for schools that want the segment without the bundle.",
    "tags": [
     "send-library"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "description": "LibrarySegmentListItem"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {}
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/library/segments/{ref}": {
   "get": {
    "operationId": "send-library_getLibrarySegment",
    "summary": "getLibrarySegment",
    "description": "Full library segment detail including rules JSON and rationale.",
    "tags": [
     "send-library"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "object"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {}
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/library/segments/{ref}/install": {
   "post": {
    "operationId": "send-library_installLibrarySegment",
    "summary": "installLibrarySegment",
    "description": "Install a single library segment standalone. Idempotent on `(schoolId, libraryRef)`: re-running returns the existing segment id with `reused: true`. The resulting row is `source='library'`, protected from edits, and consumable by Pro automations and user-built automations alike.",
    "tags": [
     "send-library"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "ref",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/templates": {
   "get": {
    "operationId": "send_templates_list",
    "summary": "list",
    "description": "List templates for the school (paginated). Returns metadata only; use get-by-id for full content. Filterable by channel, category, and name search.",
    "tags": [
     "send/templates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send.templates.TemplateListItem"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "channel": "email",
           "category": "marketing",
           "thumbnail": "string",
           "isSystem": false,
           "templateKey": "string",
           "usageCount": 1,
           "lastUsedOn": 1793836800,
           "createdOn": 1793836800,
           "updatedOn": 1793836800
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "channel",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "email",
        "sms",
        "chat",
        "social"
       ]
      },
      "description": "Filter by channel"
     },
     {
      "name": "category",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "marketing",
        "transactional",
        "notification",
        "automation"
       ]
      },
      "description": "Filter by category"
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Search by template name (substring match)"
     },
     {
      "name": "sort",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Sort field. Prefix with - for descending. Default: name. Allowed fields: name, channel, category, createdOn, updatedOn, usageCount, lastUsedOn"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (default: 1)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page (default: 50, max: 10000)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send_templates_create",
    "summary": "create",
    "description": "Create a new template. Name must be unique per school+channel. Merge tags are auto-extracted from content if not provided.",
    "tags": [
     "send/templates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.templates.Template"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "channel": "email",
            "category": "marketing",
            "content": "string",
            "mergeTagsUsed": [
             "string"
            ],
            "thumbnail": "/path",
            "isSystem": false,
            "templateKey": "string",
            "usageCount": 1,
            "lastUsedOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "channel": "email",
            "category": "marketing",
            "content": "string",
            "mergeTagsUsed": [
             "string"
            ],
            "thumbnail": "/path",
            "isSystem": false,
            "templateKey": "string",
            "usageCount": 1,
            "lastUsedOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Template name (unique per channel within school)",
          "minLength": 1,
          "maxLength": 200
         },
         "channel": {
          "type": "string",
          "description": "Channel this template is for. Set on create, immutable after.",
          "enum": [
           "email",
           "sms",
           "chat",
           "social"
          ]
         },
         "category": {
          "type": "string",
          "description": "Template category. Optional.",
          "enum": [
           "marketing",
           "transactional",
           "notification",
           "automation"
          ]
         },
         "content": {
          "type": "string",
          "description": "Template content. For channel=email: a JSON-serialized EmailDocument (see the EmailDocument model in GET /v1/send/_schema for the full block schema: heading, text, image, button, divider, spacer, columns). For channel=sms/chat/social: plain text. Max 5 MB. Use POST /v1/send/templates/validate to verify shape before saving."
         },
         "mergeTagsUsed": {
          "type": "array",
          "description": "Merge tag names used in content. Auto-extracted if omitted (the extractor handles `{{tag}}`, `{{ tag }}`, and `{{dotted.path}}` forms).",
          "items": {
           "type": "string"
          }
         }
        },
        "required": [
         "name",
         "channel",
         "content"
        ]
       },
       "example": {
        "name": "string",
        "channel": "email",
        "content": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/templates/{id}": {
   "get": {
    "operationId": "send_templates_get",
    "summary": "get",
    "description": "Get a single template by ID with full content and merge tags. Response includes an ETag header (\"v<timestamp>\") for optimistic concurrency. Pass it back as If-Match on PATCH/DELETE to avoid clobbering concurrent edits.",
    "tags": [
     "send/templates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.templates.Template"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "channel": "email",
          "category": "marketing",
          "content": "string",
          "mergeTagsUsed": [
           "string"
          ],
          "thumbnail": "/path",
          "isSystem": false,
          "templateKey": "string",
          "usageCount": 1,
          "lastUsedOn": 1793836800,
          "createdOn": 1793836800,
          "updatedOn": 1793836800
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "send_templates_update",
    "summary": "update",
    "description": "Update an existing template. Channel is immutable. A platform system template (isSystem with no templateKey) cannot be modified (403); a seeded default (isSystem with a templateKey, such as the booking confirmations) can, and reset restores it. Supports optimistic concurrency via the If-Match header (use the ETag from a prior GET; mismatch returns 412).",
    "tags": [
     "send/templates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.templates.Template"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "channel": "email",
            "category": "marketing",
            "content": "string",
            "mergeTagsUsed": [
             "string"
            ],
            "thumbnail": "/path",
            "isSystem": false,
            "templateKey": "string",
            "usageCount": 1,
            "lastUsedOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "channel": "email",
            "category": "marketing",
            "content": "string",
            "mergeTagsUsed": [
             "string"
            ],
            "thumbnail": "/path",
            "isSystem": false,
            "templateKey": "string",
            "usageCount": 1,
            "lastUsedOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "New template name",
          "minLength": 1,
          "maxLength": 200
         },
         "category": {
          "type": "string",
          "description": "New category",
          "enum": [
           "marketing",
           "transactional",
           "notification",
           "automation"
          ]
         },
         "content": {
          "type": "string",
          "description": "New content. Same shape as create (EmailDocument JSON for email; plain text for sms/chat/social; see EmailDocument model in GET /v1/send/_schema). Merge tags are re-extracted automatically."
         },
         "mergeTagsUsed": {
          "type": "array",
          "description": "Override auto-extracted merge tags",
          "items": {
           "type": "string"
          }
         }
        }
       },
       "example": {
        "name": "string",
        "category": "marketing",
        "content": "string",
        "mergeTagsUsed": [
         "string"
        ]
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "send_templates_delete",
    "summary": "delete",
    "description": "Soft-delete a template. A platform system template (isSystem with no templateKey) cannot be deleted (403). No cascade effects; delivery log references are preserved. Supports optimistic concurrency via the If-Match header (use the ETag from a prior GET; mismatch returns 412) so an agent can't accidentally delete a template another writer just edited.",
    "tags": [
     "send/templates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/templates/validate": {
   "post": {
    "operationId": "send_templates_validate",
    "summary": "validate",
    "description": "Pure content validation: no DB writes, no sends. Returns a structured TemplateValidationReport with errors, warnings, merge-tag analysis, and channel-specific stats (SMS segments / email block count). Useful while drafting: returns 200 even when content is invalid so you can iterate on the report shape directly.",
    "tags": [
     "send/templates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send.templates.TemplateValidationReport"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "valid": false,
          "errors": [
           {}
          ],
          "warnings": [
           {}
          ],
          "mergeTags": {},
          "sms": {},
          "email": {}
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "read",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "channel": {
          "type": "string",
          "description": "Channel to validate against: drives format checks.",
          "enum": [
           "email",
           "sms",
           "chat",
           "social"
          ]
         },
         "content": {
          "type": "string",
          "description": "Template content. Block JSON for email, plain text for SMS/chat/social."
         },
         "audience": {
          "type": "string",
          "description": "Audience the template will be sent to. Controls which merge tags are valid. Default: student.",
          "enum": [
           "student",
           "admin",
           "instructor"
          ]
         }
        },
        "required": [
         "channel",
         "content"
        ]
       },
       "example": {
        "channel": "email",
        "content": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/templates/{id}/duplicate": {
   "post": {
    "operationId": "send_templates_duplicate",
    "summary": "duplicate",
    "description": "Copy a template into a new editable draft. Works for both school-owned and system templates. Duplicating a system template is the standard way to get an editable starting point. The new row is always isSystem=0 with reset usage counters; name auto-suffixes \"(Copy)\" / \"(Copy 2)\" etc. on collision.",
    "tags": [
     "send/templates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.templates.Template"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "channel": "email",
            "category": "marketing",
            "content": "string",
            "mergeTagsUsed": [
             "string"
            ],
            "thumbnail": "/path",
            "isSystem": false,
            "templateKey": "string",
            "usageCount": 1,
            "lastUsedOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "channel": "email",
            "category": "marketing",
            "content": "string",
            "mergeTagsUsed": [
             "string"
            ],
            "thumbnail": "/path",
            "isSystem": false,
            "templateKey": "string",
            "usageCount": 1,
            "lastUsedOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/templates/{id}/reset": {
   "post": {
    "operationId": "send_templates_reset",
    "summary": "reset",
    "description": "Restore an auto-seeded system default's content back to the platform's bundled defaults. Only valid on rows with `isSystem=true` AND `templateKey` non-null (e.g. public-bookings confirmation templates): refused 400 VALIDATION_ERROR otherwise. The template's name and category are preserved (so a renamed copy keeps its rename); only `content` and `mergeTagsUsed` are overwritten.",
    "tags": [
     "send/templates"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send.templates.Template"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "channel": "email",
            "category": "marketing",
            "content": "string",
            "mergeTagsUsed": [
             "string"
            ],
            "thumbnail": "/path",
            "isSystem": false,
            "templateKey": "string",
            "usageCount": 1,
            "lastUsedOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "channel": "email",
            "category": "marketing",
            "content": "string",
            "mergeTagsUsed": [
             "string"
            ],
            "thumbnail": "/path",
            "isSystem": false,
            "templateKey": "string",
            "usageCount": 1,
            "lastUsedOn": 1793836800,
            "createdOn": 1793836800,
            "updatedOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/credits": {
   "get": {
    "operationId": "send-credits_getBalance",
    "summary": "getBalance",
    "description": "Current balance + auto-recharge config. Returns an `ETag` header in `\"v<timestamp>\"` format reflecting the auto-recharge config row's version (NOT the balance, which mutates constantly via the spend hot-path). Echo this back as `If-Match` on PATCH /auto-recharge for optimistic concurrency.",
    "tags": [
     "send-credits"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-credits.Balance"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "balance": 1,
          "autoRecharge": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/credits/pricing": {
   "get": {
    "operationId": "send-credits_getPricing",
    "summary": "getPricing",
    "description": "School's default pricing row + all supported currencies. Subunits are cents/pence.",
    "tags": [
     "send-credits"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-credits.PricingResponse"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "schoolCurrency": "string",
          "schoolPricing": {},
          "allPricing": [
           {
            "country": "string",
            "currency": "string",
            "subunitsPerSegment": 1,
            "taxRate": 1,
            "taxLabel": "string",
            "label": "string"
           }
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/credits/payment-context": {
   "get": {
    "operationId": "send-credits_getPaymentContext",
    "summary": "getPaymentContext",
    "description": "What the purchase UI needs before committing: the school's saved default card on the platform account (null when none; the purchase will then return a client secret for inline card entry) and the platform Stripe publishable key (null when the environment isn't configured).",
    "tags": [
     "send-credits"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-credits.PaymentContext"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "defaultCard": {},
          "publishableKey": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/credits/purchase": {
   "post": {
    "operationId": "send-credits_purchase",
    "summary": "purchase",
    "description": "Buy credits on the platform-billing rails, with no hosted checkout or redirect. Price is computed server-side from the pricing table. With a saved default card the charge confirms off-session and credits are granted before this returns (status=succeeded). A 3DS-mandated card returns status=requires_action with a client secret; no saved card (or newCard=true) returns status=requires_payment_method with a client secret for inline card entry; both finish via POST /purchase/finalize after the client confirms with Stripe. Errors: 409 CONFLICT if the card is declined (Stripe's message passed through) or the school's currency isn't supported; 500 INTERNAL_ERROR if the Stripe platform keys are unset (operator action). Use ?preview=true to validate and compute the total cost without moving money.",
    "tags": [
     "send-credits"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-credits.PurchaseOutcome"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "status": "succeeded",
            "paymentIntentId": "string",
            "credits": 1,
            "balanceAfter": 1,
            "clientSecret": "string",
            "publishableKey": "string"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "status": "succeeded",
            "paymentIntentId": "string",
            "credits": 1,
            "balanceAfter": 1,
            "clientSecret": "string",
            "publishableKey": "string"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "credits": {
          "type": "number",
          "description": "100 to 100000"
         },
         "purchaseId": {
          "type": "string",
          "description": "Client-generated UUID, stable across retries of the same logical purchase. Derives the Stripe idempotency key so a retry can't charge twice.",
          "format": "uuid"
         },
         "newCard": {
          "type": "boolean",
          "description": "Skip the saved card and collect a new one inline."
         },
         "saveCard": {
          "type": "boolean",
          "description": "Save the inline-collected card as the default for next time."
         }
        },
        "required": [
         "credits",
         "purchaseId"
        ]
       },
       "example": {
        "credits": 1,
        "purchaseId": "4c3a4e1e-7b2f-4f0a-9d1c-2a5b6c7d8e9f"
       }
      }
     }
    }
   }
  },
  "/v1/send/credits/purchase/finalize": {
   "post": {
    "operationId": "send-credits_finalizePurchase",
    "summary": "finalizePurchase",
    "description": "Synchronous fulfillment for client-confirmed purchases (3DS challenge, inline new card). Verifies the PaymentIntent server-side (our metadata marker, this school, actually paid) and grants idempotently on the PI id. Safe to call after a webhook already granted. Returns status=pending with the PI's payment status when the payment hasn't succeeded (yet).",
    "tags": [
     "send-credits"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-credits.FinalizeResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "status": "succeeded",
          "credits": 1,
          "balanceAfter": 1,
          "paymentStatus": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "paymentIntentId": {
          "type": "string",
          "description": "pi_... from the purchase call"
         }
        },
        "required": [
         "paymentIntentId"
        ]
       },
       "example": {
        "paymentIntentId": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/credits/auto-recharge": {
   "patch": {
    "operationId": "send-credits_autoRecharge",
    "summary": "autoRecharge",
    "description": "Enable / disable / configure auto-recharge. When enabled, credits are topped up whenever balance falls below thresholdCredits. Use ?preview=true to see the current vs proposed config plus the estimated currency cost per recharge cycle (no write). When the resulting enabled=true AND topupCredits >= 10,000, ?confirm=true is required as a typo guard (a one-extra-zero mistake on AUD pricing is a several-thousand-dollar surprise per cycle). Optional optimistic concurrency: pass `If-Match: \"v<timestamp>\"` from a prior GET /v1/send/credits ETag to detect concurrent admin edits — returns 412 PRECONDITION_FAILED on mismatch with a recovery hint pointing back at /credits to re-fetch.",
    "tags": [
     "send-credits"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-credits.AutoRecharge"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "enabled": false,
            "thresholdCredits": 1,
            "topupCredits": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "enabled": false,
            "thresholdCredits": 1,
            "topupCredits": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Confirmation required (condition: high_value_only). Pass confirm=true to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "enabled": {
          "type": "boolean"
         },
         "thresholdCredits": {
          "type": "number"
         },
         "topupCredits": {
          "type": "number"
         }
        },
        "required": [
         "enabled"
        ]
       },
       "example": {
        "enabled": false
       }
      }
     }
    }
   }
  },
  "/v1/send/credits/history": {
   "get": {
    "operationId": "send-credits_history",
    "summary": "history",
    "description": "Paginated transaction history (topups, spends, adjustments).",
    "tags": [
     "send-credits"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-credits.HistoryEntry"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "type": "topup",
           "creditsDelta": 1,
           "balanceAfter": 1,
           "amountSubunits": 1,
           "currency": "string",
           "note": "string",
           "createdOn": 1
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/marketplace": {
   "get": {
    "operationId": "send-marketplace_listMarketplace",
    "summary": "listMarketplace",
    "description": "Browse approved listings, newest first. Supports filtering by category and free-text search across title/description/tags. Pagination via page/limit. Append `?include=links` for HATEOAS envelope including the publish action.",
    "tags": [
     "send-marketplace"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-marketplace.ListingSummary"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "title": "string",
           "description": "string",
           "category": "string",
           "tags": [],
           "publisherSchoolName": "string",
           "publisherSchoolId": 1,
           "statsImports": 1,
           "publishedOn": 1,
           "status": "approved"
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "category",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "onboarding",
        "retention",
        "milestones",
        "billing",
        "marketing",
        "operational",
        "other"
       ]
      }
     },
     {
      "name": "tag",
      "in": "query",
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Matches title / description / tags (case-insensitive)"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "1-100 (default 25)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/marketplace/{id}": {
   "get": {
    "operationId": "send-marketplace_getListing",
    "summary": "getListing",
    "description": "Listing detail including a sanitized automation shape (step types and counts only; full step config is delivered on import). When the viewer is the publisher, `sourceAutomationIdForViewer` is set so the UI can deep-link to the source automation. Returns 404 for unapproved listings (pending_review/rejected/removed are hidden).",
    "tags": [
     "send-marketplace"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-marketplace.ListingDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "title": "string",
          "description": "string",
          "category": "string",
          "tags": [],
          "publisherSchoolName": "string",
          "publisherSchoolId": 1,
          "statsImports": 1,
          "publishedOn": 1,
          "status": "string",
          "shape": {},
          "alreadyImported": false,
          "sourceAutomationIdForViewer": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "delete": {
    "operationId": "send-marketplace_removeListing",
    "summary": "removeListing",
    "description": "Remove YOUR OWN listing (publisher-only). Soft-delete via status='removed'; already-imported copies in other schools are unaffected. Idempotent: repeated calls on an already-removed listing return success with `alreadyRemoved=true`. Errors: 404 NOT_FOUND; 403 FORBIDDEN when the listing belongs to a different school (distinct from 404: the listing exists, you just can't act on it).",
    "tags": [
     "send-marketplace"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-marketplace.RemoveResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "removed": false,
            "alreadyRemoved": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "removed": false,
            "alreadyRemoved": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/send/marketplace/publish": {
   "post": {
    "operationId": "send-marketplace_publishListing",
    "summary": "publishListing",
    "description": "Submit one of your active, school-authored automations. Goes into pending_review; Martialytics approves asynchronously. Eligibility: source automation must belong to the calling school, be status=active, and not be a system / marketplace-imported / share-imported automation. Errors: 404 when the automationId doesn't belong to your school; 403 when the source is ineligible (status / source kind); 409 SHAPE_DUPLICATE when an existing approved/pending listing has the same shape (trigger + audience + ordered step types), and the response carries the duplicate listing id so you can import it instead; 429 RATE_LIMITED when the school has already published 5 listings in the last rolling 24-hour window (response includes Retry-After header + the exact unix timestamp when the next slot opens). Use ?preview=true to dry-run all blockers without submitting.",
    "tags": [
     "send-marketplace"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-marketplace.PublishResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "listingId": 1,
            "status": "pending_review"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "listingId": 1,
            "status": "pending_review"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "automationId": {
          "type": "integer",
          "description": "Id of an automation in your school"
         },
         "title": {
          "type": "string",
          "maxLength": 200
         },
         "description": {
          "type": "string",
          "maxLength": 2000
         },
         "category": {
          "type": "string",
          "enum": [
           "onboarding",
           "retention",
           "milestones",
           "billing",
           "marketing",
           "operational",
           "other"
          ]
         },
         "tags": {
          "type": "array",
          "description": "Up to 10 short tags, each max 40 chars",
          "items": {}
         }
        },
        "required": [
         "automationId",
         "title",
         "description"
        ]
       },
       "example": {
        "automationId": 1,
        "title": "string",
        "description": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/marketplace/{id}/import": {
   "post": {
    "operationId": "send-marketplace_importListing",
    "summary": "importListing",
    "description": "Deep-copy an approved listing into your account as a DRAFT automation. Segment-entry triggers won't resolve (segment ids are publisher-specific); they're cleared on import, so re-wire manually after review. Per-listing idempotency: by default a school can hold only one import per listing (retries return the existing automation with reused=true). Pass an `idempotencyKey` to override and hold multiple distinct imports of the same listing under different keys. Errors: 404 NOT_FOUND; 409 LISTING_NOT_IMPORTABLE (status != approved); 409 SELF_IMPORT (you're the publisher; open the source directly); 409 SOURCE_MISSING (publisher deleted the source automation since the listing was created). Use ?preview=true to dry-run: same blockers checked without writing; a dry run that finds one refuses with the same status and message as the real call, otherwise it answers with the source shape and `wouldReuseExisting`.",
    "tags": [
     "send-marketplace"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-marketplace.ImportResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "listingId": 1,
            "automationId": 1,
            "stepCount": 1,
            "reused": false,
            "notes": [
             "string"
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "listingId": 1,
            "automationId": 1,
            "stepCount": 1,
            "reused": false,
            "notes": [
             "string"
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Optional override for the imported automation's name. Defaults to the listing title.",
          "maxLength": 200
         },
         "idempotencyKey": {
          "type": "string",
          "description": "Optional. Hashed into source_ref to allow multiple distinct imports of the same listing under different keys. Without a key, source_ref defaults to listingId so the (school, source='marketplace', source_ref) unique constraint provides per-listing idempotency. Either way, retries with the same effective source_ref return reused=true (HTTP 201 still).",
          "minLength": 1,
          "maxLength": 128
         }
        }
       },
       "example": {
        "name": "string",
        "idempotencyKey": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/share-imports/{slug}": {
   "get": {
    "operationId": "send-share-import_previewShareImport",
    "summary": "previewShareImport",
    "description": "Shape-only preview of a publicly-shared automation. Returns trigger label + step labels + publisher attribution (when the publisher has it enabled), but never step config; content only lands in the importer's school via the POST. 404 when the slug doesn't resolve, the publisher disabled sharing, the publisher's school is inactive, or the slug never existed (collapsed to avoid cross-school existence leaks). When the viewer IS the publisher (`canImport=false`), the source automationId is returned so the UI can deep-link instead of importing.",
    "tags": [
     "send-share-import"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-share-import.SharePreview"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "shareSlug": "string",
          "shareTitle": "string",
          "shareDescription": "string",
          "publisherName": "string",
          "publisherRefSlug": "string",
          "ogImageUrl": "https://example.com",
          "triggerLabel": "string",
          "stepLabels": [
           {}
          ],
          "canImport": false,
          "automationId": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "slug",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "send-share-import_importShare",
    "summary": "importShare",
    "description": "Deep-clone the shared automation into the caller's school as a DRAFT. Body is optional; the only field is the publisher's attribution ref carried through from the share URL, persisted on the new automation row as share_source_ref_slug for attribution reporting. Errors: 404 when the slug no longer resolves to an actively-shared automation; 409 SELF when the caller is the publisher (open the source instead); 429 RATE_LIMITED when the importer has already pulled 5 shares in the last 7 days (response includes Retry-After header + the exact unix timestamp when the next slot opens up). Use ?preview=true to dry-run: same blockers (rate limit, source resolution, self-import) are checked without writing; a dry run that finds one refuses with the same status and message as the real call, otherwise it answers with the source shape and remaining-rate-limit slot count.",
    "tags": [
     "send-share-import"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-share-import.ImportResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "automationId": 1,
            "reused": false,
            "notes": [
             "string"
            ]
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "automationId": 1,
            "reused": false,
            "notes": [
             "string"
            ]
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "slug",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "ref": {
          "type": "string",
          "description": "Publisher's school-level ref slug from the share URL's ?ref= query param. Persisted on the new automation as share_source_ref_slug for attribution reporting. Optional: omit or pass null when the URL had no ref.",
          "maxLength": 40
         },
         "idempotencyKey": {
          "type": "string",
          "description": "Optional. Hashed into source_ref; the (school_id, source, source_ref) unique constraint catches retries. When a duplicate is detected the existing automation is returned with reused=true (HTTP 201 still). Omit to allow multiple distinct imports of the same share. Useful when an importer wants several variations with different `ref` attributions.",
          "minLength": 1,
          "maxLength": 128
         }
        }
       },
       "example": {
        "ref": "string",
        "idempotencyKey": "string"
       }
      }
     }
    }
   }
  },
  "/v1/send/system": {
   "get": {
    "operationId": "send-system_listSystem",
    "summary": "listSystem",
    "description": "List all system automations with this school's current configuration. Returns 'not_installed' status for any that haven't been enabled yet.",
    "tags": [
     "send-system"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-system.SystemAutomation"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "key": "string",
           "name": "string",
           "description": "string",
           "audience": "admin",
           "sections": [],
           "status": "active",
           "deliveryHour": 1,
           "schedule": "string",
           "recipientUserIds": [],
           "recipientInstructorIds": [],
           "automationId": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/system/{key}": {
   "get": {
    "operationId": "send-system_getSystem",
    "summary": "getSystem",
    "description": "Detail for a single system automation. 'key' is one of: morning_briefing, weekly_school_report, monthly_health_report. (Instructor automations are gated until instructor management ships and 404 until then.)",
    "tags": [
     "send-system"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/send-system.SystemAutomation"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "key": "string",
          "name": "string",
          "description": "string",
          "audience": "admin",
          "sections": [],
          "status": "active",
          "deliveryHour": 1,
          "schedule": "string",
          "recipientUserIds": [],
          "recipientInstructorIds": [],
          "automationId": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "key",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "send-system_updateSystem",
    "summary": "updateSystem",
    "description": "Enable/disable, change delivery hour, or update recipients. First enable materializes the automation + trigger + step rows.",
    "tags": [
     "send-system"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-system.SystemAutomation"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "key": "string",
            "name": "string",
            "description": "string",
            "audience": "admin",
            "sections": [],
            "status": "active",
            "deliveryHour": 1,
            "schedule": "string",
            "recipientUserIds": [],
            "recipientInstructorIds": [],
            "automationId": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "key": "string",
            "name": "string",
            "description": "string",
            "audience": "admin",
            "sections": [],
            "status": "active",
            "deliveryHour": 1,
            "schedule": "string",
            "recipientUserIds": [],
            "recipientInstructorIds": [],
            "automationId": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "key",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "status": {
          "type": "string",
          "enum": [
           "active",
           "paused"
          ]
         },
         "deliveryHour": {
          "type": "number",
          "description": "0-23, rewrites the CRON hour portion"
         },
         "recipientUserIds": {
          "type": "array",
          "description": "Admin-audience only. Null = school owner.",
          "items": {}
         },
         "recipientInstructorIds": {
          "type": "array",
          "description": "Instructor-audience only. Null = all.",
          "items": {}
         }
        }
       },
       "example": {
        "status": "active",
        "deliveryHour": 1,
        "recipientUserIds": [],
        "recipientInstructorIds": []
       }
      }
     }
    }
   }
  },
  "/v1/send/suppression": {
   "get": {
    "operationId": "send-suppression_listSuppression",
    "summary": "listSuppression",
    "description": "Paginated active suppression list.",
    "tags": [
     "send-suppression"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/send-suppression.SuppressionEntry"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "channel": "email",
           "recipientAddress": "string",
           "reason": "hard_bounce",
           "detail": "string",
           "createdOn": 1,
           "createdByType": "string"
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "channel",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "email",
        "sms"
       ]
      }
     },
     {
      "name": "reason",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "hard_bounce",
        "spam_complaint",
        "opt_out",
        "unsubscribe_link",
        "manual"
       ]
      }
     },
     {
      "name": "search",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Substring match on recipient_address"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "number"
      }
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "1-100 (default 50)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/send/suppression/{id}": {
   "delete": {
    "operationId": "send-suppression_removeSuppression",
    "summary": "removeSuppression",
    "description": "Remove one suppression row. An address can hold more than one row (an unsubscribe beside a bounce, say), and the others stay: email resumes only if no other row still stops it. The preview's `effect` says what will happen, and `stillBlockedBy` / `marketingStaysOff` (in the preview and the result) say what still stands. The entry is marked removed_on; the row is kept for audit. An email entry is also cleared from Postmark's server-side suppression list on every stream, unless another row still stops every email to the address; the response's `provider` reports the outcome (cleared | failed | unconfigured, or not_applicable for SMS, where a carrier STOP is only lifted by the recipient texting START, and for email still blocked by another row). Entries with reason spam_complaint cannot be removed (409): Postmark will not lift a complaint and neither will Martialytics.",
    "tags": [
     "send-suppression"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/send-suppression.RemoveResult"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "removed": false,
            "channel": "email",
            "recipientAddress": "string",
            "provider": {},
            "stillBlockedBy": "hard_bounce",
            "marketingStaysOff": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "removed": false,
            "channel": "email",
            "recipientAddress": "string",
            "provider": {},
            "stillBlockedBy": "hard_bounce",
            "marketingStaysOff": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/school/settings": {
   "get": {
    "operationId": "school_getSettings",
    "summary": "getSettings",
    "description": "Get all school settings including name, timezone, locale, branding colours, kiosk config, notification preferences, and tax settings",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.SchoolSettings"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "timezone": "string",
          "locale": "string",
          "currency": "string",
          "dateFormat": "string",
          "primaryColor": "string",
          "secondaryColor": "string",
          "logoUrl": "string",
          "kioskPin": "string",
          "kioskLockout": 1,
          "attendanceLimitOverride": false,
          "gateOnPayment": false,
          "hideProgress": false,
          "taxName": "string",
          "taxRate": 1,
          "taxNumber": "string",
          "taxMode": "inclusive"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "school_updateSettings",
    "summary": "updateSettings",
    "description": "Update general settings. All fields optional: only provided fields are updated. Supports ?preview=true. Changing taxRate, taxMode or taxName rolls the new tax out to every member's live recurring plan from their next payment (Stripe tax rate, GoCardless amount), as a queued billing job: the response carries taxChange { jobId, total } to watch with the billing job endpoint. Months before the change keep the tax they had. See previewTaxChange for who it reaches. Refused (409) while a price change, plan migration or tax change is running.",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/school.SchoolSettings"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "timezone": "string",
            "locale": "string",
            "currency": "string",
            "dateFormat": "string",
            "primaryColor": "string",
            "secondaryColor": "string",
            "logoUrl": "string",
            "kioskPin": "string",
            "kioskLockout": 1,
            "attendanceLimitOverride": false,
            "gateOnPayment": false,
            "hideProgress": false,
            "taxName": "string",
            "taxRate": 1,
            "taxNumber": "string",
            "taxMode": "inclusive"
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "timezone": "string",
            "locale": "string",
            "currency": "string",
            "dateFormat": "string",
            "primaryColor": "string",
            "secondaryColor": "string",
            "logoUrl": "string",
            "kioskPin": "string",
            "kioskLockout": 1,
            "attendanceLimitOverride": false,
            "gateOnPayment": false,
            "hideProgress": false,
            "taxName": "string",
            "taxRate": 1,
            "taxNumber": "string",
            "taxMode": "inclusive"
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "School name",
          "maxLength": 500
         },
         "timezone": {
          "type": "string",
          "description": "IANA timezone (e.g. Australia/Sydney)"
         },
         "primaryColor": {
          "type": "string",
          "description": "Primary brand colour hex",
          "pattern": "^#[0-9A-Fa-f]{6}$"
         },
         "secondaryColor": {
          "type": "string",
          "description": "Secondary brand colour hex",
          "pattern": "^#[0-9A-Fa-f]{6}$"
         },
         "kioskPin": {
          "type": "string",
          "description": "4-digit kiosk PIN",
          "pattern": "^\\d{4}$"
         },
         "kioskLockout": {
          "type": "integer",
          "description": "Minutes during which a second check-in for the same member is refused, on every check-in path; 0 means 15",
          "minimum": 0,
          "maximum": 1440
         },
         "attendanceLimitOverride": {
          "type": "boolean",
          "description": "Allow attendance beyond class capacity"
         },
         "gateOnPayment": {
          "type": "boolean",
          "description": "Refuse kiosk check-in when the student's plan is overdue or expired (default false)"
         },
         "ageOfMajority": {
          "type": "integer",
          "description": "Age of majority used by waiver guardian logic. Overrides the country table, which indexes on the locale's region and therefore cannot express US state law (AL/NE 19, MS/PR 21). null clears the override and falls back to the region-derived value.",
          "minimum": 1,
          "maximum": 30
         },
         "hideProgress": {
          "type": "boolean",
          "description": "Hide rank progress from students"
         },
         "notifications": {
          "type": "object",
          "description": "Map of setting ID to enabled boolean (e.g. {\"201\": true})"
         },
         "currency": {
          "type": "string",
          "description": "Currency code (e.g. AUD, USD, GBP)"
         },
         "taxName": {
          "type": "string",
          "description": "Tax label (e.g. GST, VAT)",
          "maxLength": 50
         },
         "taxRate": {
          "type": "number",
          "description": "Tax rate percentage",
          "minimum": 0,
          "maximum": 100
         },
         "taxNumber": {
          "type": "string",
          "description": "Tax registration number",
          "maxLength": 100
         },
         "taxMode": {
          "type": "string",
          "description": "Whether prices include or exclude tax",
          "enum": [
           "inclusive",
           "exclusive"
          ]
         },
         "assistantAutonomy": {
          "type": "string",
          "description": "AI assistant autonomy (#D2): which previewed changes the assistant may apply without a confirmation click. Financial operations always require confirmation regardless of this setting.",
          "enum": [
           "off",
           "reversible-only",
           "all-but-financial"
          ]
         }
        }
       },
       "example": {
        "name": "string",
        "timezone": "string",
        "primaryColor": "#1F7F5C",
        "secondaryColor": "#1F7F5C",
        "kioskPin": "1234",
        "kioskLockout": 1,
        "attendanceLimitOverride": false,
        "gateOnPayment": false,
        "ageOfMajority": 1,
        "hideProgress": false,
        "notifications": {},
        "currency": "string",
        "taxName": "string",
        "taxRate": 1,
        "taxNumber": "string",
        "taxMode": "inclusive",
        "assistantAutonomy": "off"
       }
      }
     }
    }
   }
  },
  "/v1/school/branding": {
   "get": {
    "operationId": "school_getBranding",
    "summary": "getBranding",
    "description": "Get school branding info (logo URL, colours, display name). Lighter than getSettings for theme loading.",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.SchoolBranding"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "schoolName": "string",
          "logoUrl": "string",
          "primaryColour": "string",
          "secondaryColour": "string"
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/school/settings/tax-change-preview": {
   "get": {
    "operationId": "school_previewTaxChange",
    "summary": "previewTaxChange",
    "description": "Who a change to the school's tax would reach, without changing anything: members on live recurring plans not already on this tax, by gateway, and how many would be charged a different amount (tax on top added, removed or re-rated).",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.TaxChangePreview"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "total": 1,
          "stripe": 1,
          "gocardless": 1,
          "local": 1,
          "chargeChanges": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "taxRate",
      "in": "query",
      "schema": {
       "type": "number"
      },
      "description": "The new tax rate percentage, 0 to 100; empty for no tax"
     },
     {
      "name": "taxMode",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "inclusive",
        "exclusive"
       ]
      },
      "description": "The new tax mode (default inclusive)"
     },
     {
      "name": "taxName",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "The new tax label (e.g. GST), up to 50 characters"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/school/settings/tax-change/retry": {
   "post": {
    "operationId": "school_retryTaxChange",
    "summary": "retryTaxChange",
    "description": "Try a failed tax rollout again: roll the school's CURRENT tax out to every live recurring plan not already on it, as a queued billing job. For when a rollout failed after its retries and left the new tax saved on the school but not on members' plans; saving the same tax again starts nothing. ?preview=true returns who it would reach (TaxChangePreview); ?confirm=true starts it and returns { jobId, total } (jobId null when nobody needs it). Refused (409) while a price change, plan migration or tax change is running.",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/school.TaxChangePreview"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "total": 1,
            "stripe": 1,
            "gocardless": 1,
            "local": 1,
            "chargeChanges": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "total": 1,
            "stripe": 1,
            "gocardless": 1,
            "local": 1,
            "chargeChanges": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "financial",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/school/logo/presign": {
   "post": {
    "operationId": "school_logoPresign",
    "summary": "logoPresign",
    "description": "Get a presigned S3 URL for direct logo upload. Upload the file to the returned URL, then call logoConfirm.",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.PresignedUpload"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "uploadUrl": "string",
          "storageKey": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "filename": {
          "type": "string",
          "description": "Original filename",
          "maxLength": 255
         },
         "mimeType": {
          "type": "string",
          "description": "Image MIME type",
          "enum": [
           "image/png",
           "image/jpeg",
           "image/webp"
          ]
         },
         "fileSize": {
          "type": "integer",
          "description": "File size in bytes (max 4MB)",
          "maximum": 4194304
         }
        },
        "required": [
         "filename",
         "mimeType",
         "fileSize"
        ]
       },
       "example": {
        "filename": "string",
        "mimeType": "image/png",
        "fileSize": 1
       }
      }
     }
    }
   }
  },
  "/v1/school/logo/confirm": {
   "post": {
    "operationId": "school_logoConfirm",
    "summary": "logoConfirm",
    "description": "Confirm a logo upload after the client has uploaded to the presigned URL. Returns updated branding.",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.SchoolBranding"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "schoolName": "string",
          "logoUrl": "string",
          "primaryColour": "string",
          "secondaryColour": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "storageKey": {
          "type": "string",
          "description": "Storage key returned from presign step"
         }
        },
        "required": [
         "storageKey"
        ]
       },
       "example": {
        "storageKey": "string"
       }
      }
     }
    }
   }
  },
  "/v1/school/logo/version": {
   "post": {
    "operationId": "school_logoVersion",
    "summary": "logoVersion",
    "description": "Choose which logo every surface shows: the cleaned copy (light background removed, trimmed; the default) or the file as uploaded; and whether the logo already spells the school's name, so surfaces stop repeating the name beside it. Send either or both. Returns updated branding.",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.SchoolBranding"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "schoolName": "string",
          "logoUrl": "string",
          "primaryColour": "string",
          "secondaryColour": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "useOriginal": {
          "type": "boolean",
          "description": "true shows the file as uploaded; false the cleaned copy"
         },
         "includesName": {
          "type": "boolean",
          "description": "true when the logo already spells the school's name"
         }
        }
       },
       "example": {
        "useOriginal": false,
        "includesName": false
       }
      }
     }
    }
   }
  },
  "/v1/school/logo": {
   "delete": {
    "operationId": "school_logoDelete",
    "summary": "logoDelete",
    "description": "Remove the school logo",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/school/icon/presign": {
   "post": {
    "operationId": "school_iconPresign",
    "summary": "iconPresign",
    "description": "Get a presigned S3 URL for the school's optional square icon, the small mark shown where a wide logo does not fit (top bar, kiosk, members app). Upload the file, then call iconConfirm.",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.PresignedUpload"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "uploadUrl": "string",
          "storageKey": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "filename": {
          "type": "string",
          "description": "Original filename",
          "maxLength": 255
         },
         "mimeType": {
          "type": "string",
          "description": "Image MIME type",
          "enum": [
           "image/png",
           "image/jpeg",
           "image/webp"
          ]
         },
         "fileSize": {
          "type": "integer",
          "description": "File size in bytes (max 4MB)",
          "maximum": 4194304
         }
        },
        "required": [
         "filename",
         "mimeType",
         "fileSize"
        ]
       },
       "example": {
        "filename": "string",
        "mimeType": "image/png",
        "fileSize": 1
       }
      }
     }
    }
   }
  },
  "/v1/school/icon/confirm": {
   "post": {
    "operationId": "school_iconConfirm",
    "summary": "iconConfirm",
    "description": "Confirm the icon upload. The icon is cleaned like the logo (plain light background removed, trimmed). Returns updated branding.",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.SchoolBranding"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "schoolName": "string",
          "logoUrl": "string",
          "primaryColour": "string",
          "secondaryColour": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "storageKey": {
          "type": "string",
          "description": "Storage key returned from iconPresign"
         }
        },
        "required": [
         "storageKey"
        ]
       },
       "example": {
        "storageKey": "string"
       }
      }
     }
    }
   }
  },
  "/v1/school/icon": {
   "delete": {
    "operationId": "school_iconDelete",
    "summary": "iconDelete",
    "description": "Remove the square icon; small spots show the logo again",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/school/content-images/presign": {
   "post": {
    "operationId": "school_contentImagePresign",
    "summary": "contentImagePresign",
    "description": "Get a presigned S3 URL for content image upload (rich text editor). PNG, JPEG, GIF and WebP only.",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.PresignedUpload"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "uploadUrl": "string",
          "storageKey": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "filename": {
          "type": "string",
          "description": "Original filename",
          "maxLength": 255
         },
         "mimeType": {
          "type": "string",
          "description": "image/png, image/jpeg, image/gif or image/webp"
         },
         "fileSize": {
          "type": "integer",
          "description": "File size in bytes (max 4MB); optional",
          "maximum": 4194304
         }
        },
        "required": [
         "filename",
         "mimeType"
        ]
       },
       "example": {
        "filename": "string",
        "mimeType": "string"
       }
      }
     }
    }
   }
  },
  "/v1/school/content-images/confirm": {
   "post": {
    "operationId": "school_contentImageConfirm",
    "summary": "contentImageConfirm",
    "description": "Confirm a content image upload. Returns a permanent public URL for embedding (it never expires).",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.ContentImageResult"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "url": "string"
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "IDEMPOTENCY_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "storageKey": {
          "type": "string",
          "description": "Storage key returned from presign step"
         }
        },
        "required": [
         "storageKey"
        ]
       },
       "example": {
        "storageKey": "string"
       }
      }
     }
    }
   }
  },
  "/v1/school/settings/member-self-service": {
   "get": {
    "operationId": "school_getMemberSelfServiceSettings",
    "summary": "getMemberSelfServiceSettings",
    "description": "What members may do to their own plan from the portal and the app: buy a plan, buy passes, change plan, pause, cancel",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.MemberSelfServiceSettings"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "buyPlan": false,
          "buyPasses": false,
          "changePlan": false,
          "pause": false,
          "cancel": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "school_updateMemberSelfServiceSettings",
    "summary": "updateMemberSelfServiceSettings",
    "description": "Open or close each member self-service action; off hides it everywhere",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/school.MemberSelfServiceSettings"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "buyPlan": false,
            "buyPasses": false,
            "changePlan": false,
            "pause": false,
            "cancel": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "buyPlan": false,
            "buyPasses": false,
            "changePlan": false,
            "pause": false,
            "cancel": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "buyPlan": {
          "type": "boolean",
          "description": "Members with no plan can start one"
         },
         "buyPasses": {
          "type": "boolean",
          "description": "Packs and drop-ins alongside a plan"
         },
         "changePlan": {
          "type": "boolean",
          "description": "Switch plan immediately, prorated"
         },
         "pause": {
          "type": "boolean",
          "description": "Pause with a return date; the school is alerted each time"
         },
         "cancel": {
          "type": "boolean",
          "description": "End the plan at the end of the paid period"
         }
        }
       },
       "example": {
        "buyPlan": false,
        "buyPasses": false,
        "changePlan": false,
        "pause": false,
        "cancel": false
       }
      }
     }
    }
   }
  },
  "/v1/school/settings/reports-income": {
   "get": {
    "operationId": "school_getReportsIncomeSettings",
    "summary": "getReportsIncomeSettings",
    "description": "Get the per-school configuration for the Income card on /reports (projection horizon, included sources, churn fallback, etc.).",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school.ReportsIncomeSettings"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "horizonMonths": 3,
          "includedSources": [
           "subscription"
          ],
          "churnFallbackRate": 1,
          "includePausedSubs": false,
          "paygSmoothingWindow": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "school_updateReportsIncomeSettings",
    "summary": "updateReportsIncomeSettings",
    "description": "Update Income card settings. All fields optional: only provided fields are persisted.",
    "tags": [
     "school"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/school.ReportsIncomeSettings"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "horizonMonths": 3,
            "includedSources": [
             "subscription"
            ],
            "churnFallbackRate": 1,
            "includePausedSubs": false,
            "paygSmoothingWindow": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "horizonMonths": 3,
            "includedSources": [
             "subscription"
            ],
            "churnFallbackRate": 1,
            "includePausedSubs": false,
            "paygSmoothingWindow": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "horizonMonths": {
          "type": "integer",
          "description": "Projection lookahead in months",
          "enum": [
           3,
           6,
           12
          ]
         },
         "includedSources": {
          "type": "array",
          "description": "Revenue sources to include in headline totals",
          "items": {
           "type": "string",
           "enum": [
            "subscription",
            "payg",
            "shop",
            "events",
            "one_off",
            "other"
           ]
          }
         },
         "churnFallbackRate": {
          "type": "number",
          "description": "Decimal churn rate used when history is too thin",
          "minimum": 0,
          "maximum": 1
         },
         "includePausedSubs": {
          "type": "boolean",
          "description": "Count paused subscriptions toward MRR"
         },
         "paygSmoothingWindow": {
          "type": "integer",
          "description": "Months of history smoothed for non-subscription extrapolation",
          "minimum": 3,
          "maximum": 12
         }
        }
       },
       "example": {
        "horizonMonths": 3,
        "includedSources": [
         "subscription"
        ],
        "churnFallbackRate": 1,
        "includePausedSubs": false,
        "paygSmoothingWindow": 3
       }
      }
     }
    }
   }
  },
  "/v1/school/users": {
   "get": {
    "operationId": "school-users_list",
    "summary": "list",
    "description": "List the school's sub-accounts (name, email, granted permission ids, created/last-login info). The primary account is listed too, with isPrimary: true.",
    "tags": [
     "school-users"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/school-users.SchoolUser"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "email": "jo@example.com",
           "permissions": [],
           "createdOn": 1,
           "invited": false
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "school-users_create",
    "summary": "create",
    "description": "Invite a sub-account. Email must be unique across the platform. Permissions default to none: grant granular ids explicitly. The person is emailed a link, valid for 7 days, to choose their own password; nobody else sets it. ?preview=true is a dry run: who would be invited, with which permissions by name.",
    "tags": [
     "school-users"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/school-users.SchoolUser"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "jo@example.com",
            "permissions": [],
            "createdOn": 1,
            "invited": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "jo@example.com",
            "permissions": [],
            "createdOn": 1,
            "invited": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Display/role name for the sub-account (e.g. 'Front Desk').",
          "maxLength": 150
         },
         "email": {
          "type": "string",
          "description": "Login email (lowercased, unique).",
          "format": "email"
         },
         "permissions": {
          "type": "array",
          "description": "Permission ids to grant, from GET /v1/school/users/permissions. Empty = no access beyond login.",
          "items": {}
         }
        },
        "required": [
         "name",
         "email"
        ]
       },
       "example": {
        "name": "string",
        "email": "jo@example.com"
       }
      }
     }
    }
   }
  },
  "/v1/school/users/permissions": {
   "get": {
    "operationId": "school-users_permissions",
    "summary": "permissions",
    "description": "The permission ids create and update grant, each with its area (Attendance, Students, Billing...), name and what it allows. grantable says whether this caller may grant it: an API key grants only what its own scopes cover.",
    "tags": [
     "school-users"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/school-users.Permission"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "area": "string",
           "name": "string",
           "description": "string",
           "grantable": false
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/school/users/{id}": {
   "get": {
    "operationId": "school-users_get",
    "summary": "get",
    "description": "Get a single sub-account by ID.",
    "tags": [
     "school-users"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/school-users.SchoolUser"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "email": "jo@example.com",
          "permissions": [],
          "createdOn": 1,
          "invited": false
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "school-users_update",
    "summary": "update",
    "description": "Update a sub-account's name, email, password and/or permission grants. Omitted fields are untouched. ?preview=true is a dry run: current vs would-become permissions by name, and what they gain or lose.",
    "tags": [
     "school-users"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/school-users.SchoolUser"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "jo@example.com",
            "permissions": [],
            "createdOn": 1,
            "invited": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "jo@example.com",
            "permissions": [],
            "createdOn": 1,
            "invited": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "maxLength": 150
         },
         "email": {
          "type": "string",
          "format": "email"
         },
         "password": {
          "type": "string",
          "description": "New password. Only a signed-in admin may send it: an API key sending a password is refused 403, whatever else the body carries."
         },
         "permissions": {
          "type": "array",
          "description": "Replacement set of permission ids, from GET /v1/school/users/permissions.",
          "items": {}
         }
        }
       },
       "example": {
        "name": "string",
        "email": "jo@example.com",
        "password": "string",
        "permissions": []
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "school-users_delete",
    "summary": "delete",
    "description": "Soft-delete a sub-account (login revoked immediately). Requires ?confirm=true. ?preview=true is a dry run: the permissions they lose and the kiosk tablets they signed in, which are signed out.",
    "tags": [
     "school-users"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/school-users.SchoolUser"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "jo@example.com",
            "permissions": [],
            "createdOn": 1,
            "invited": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "jo@example.com",
            "permissions": [],
            "createdOn": 1,
            "invited": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/school/users/{id}/invite": {
   "post": {
    "operationId": "school-users_resendInvite",
    "summary": "resendInvite",
    "description": "Email an invited sub-account a fresh link to choose their password (valid 7 days); the link sent before stops working. Refused once they have set a password. ?preview=true is a dry run: who would be emailed.",
    "tags": [
     "school-users"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/school-users.SchoolUser"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "jo@example.com",
            "permissions": [],
            "createdOn": 1,
            "invited": false
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "email": "jo@example.com",
            "permissions": [],
            "createdOn": 1,
            "invited": false
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/school/lead-stages": {
   "get": {
    "operationId": "lead-stages_list",
    "summary": "list",
    "description": "List all pipeline stages for the school with lead counts, ordered by position",
    "tags": [
     "lead-stages"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/lead-stages.LeadStage"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "color": "string",
           "position": 1,
           "isSystem": false,
           "terminalType": "won",
           "leadCount": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "lead-stages_create",
    "summary": "create",
    "description": "Create a custom pipeline stage. Inserted before terminal stages (Won/Lost). Cannot create stages with duplicate names.",
    "tags": [
     "lead-stages"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/lead-stages.LeadStage"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "color": "string",
            "position": 1,
            "isSystem": false,
            "terminalType": "won",
            "leadCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "color": "string",
            "position": 1,
            "isSystem": false,
            "terminalType": "won",
            "leadCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Stage name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 100
         },
         "color": {
          "type": "string",
          "description": "Hex color code (e.g., #5A9AA8). Defaults to \"#5A9AA8\".",
          "pattern": "^#[0-9A-Fa-f]{6}$",
          "format": "hex-color"
         }
        },
        "required": [
         "name"
        ]
       },
       "example": {
        "name": "string"
       }
      }
     }
    }
   }
  },
  "/v1/school/lead-stages/{id}": {
   "get": {
    "operationId": "lead-stages_get",
    "summary": "get",
    "description": "Get a single pipeline stage by ID",
    "tags": [
     "lead-stages"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/lead-stages.LeadStage"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "color": "string",
          "position": 1,
          "isSystem": false,
          "terminalType": "won",
          "leadCount": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "lead-stages_update",
    "summary": "update",
    "description": "Update a stage's name or color. System stages can be renamed/recolored but not deleted.",
    "tags": [
     "lead-stages"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/lead-stages.LeadStage"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "color": "string",
            "position": 1,
            "isSystem": false,
            "terminalType": "won",
            "leadCount": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "color": "string",
            "position": 1,
            "isSystem": false,
            "terminalType": "won",
            "leadCount": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "New stage name (must be unique within the school)",
          "minLength": 1,
          "maxLength": 100
         },
         "color": {
          "type": "string",
          "description": "Hex color code (e.g., #E56C69)",
          "pattern": "^#[0-9A-Fa-f]{6}$",
          "format": "hex-color"
         }
        }
       },
       "example": {
        "name": "string",
        "color": "#1F7F5C"
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "lead-stages_delete",
    "summary": "delete",
    "description": "Delete a custom stage. Leads in the deleted stage are moved to \"New\". System stages cannot be deleted.",
    "tags": [
     "lead-stages"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/school/lead-stages/reorder": {
   "patch": {
    "operationId": "lead-stages_reorder",
    "summary": "reorder",
    "description": "Reorder non-terminal stages. Pass the stage IDs in the desired order. Terminal stages (Won/Lost) are always last.",
    "tags": [
     "lead-stages"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "array",
             "items": {
              "$ref": "#/components/schemas/lead-stages.LeadStage"
             }
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": [
            {
             "id": 1,
             "name": "string",
             "color": "string",
             "position": 1,
             "isSystem": false,
             "terminalType": "won",
             "leadCount": 1
            }
           ]
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": [
            {
             "id": 1,
             "name": "string",
             "color": "string",
             "position": 1,
             "isSystem": false,
             "terminalType": "won",
             "leadCount": 1
            }
           ],
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "stageIds": {
          "type": "array",
          "description": "Ordered array of non-terminal stage IDs",
          "items": {
           "type": "integer"
          }
         }
        },
        "required": [
         "stageIds"
        ]
       },
       "example": {
        "stageIds": [
         1
        ]
       }
      }
     }
    }
   }
  },
  "/v1/webhooks/events": {
   "get": {
    "operationId": "webhooks_eventsCatalog",
    "summary": "eventsCatalog",
    "description": "Every event name a webhook may subscribe to, sorted. The data each carries is the domain event's own payload: ids at the least, the full record where the module description says so (waivers, shop orders).",
    "tags": [
     "webhooks"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/webhooks.WebhookEventCatalog"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "events": [
           "string"
          ]
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/webhooks/{id}/rotate-secret": {
   "post": {
    "operationId": "webhooks_rotateSecret",
    "summary": "rotateSecret",
    "description": "Mint a new HMAC signing secret for a webhook. The new secret is returned once and deliveries are signed with it immediately; the old secret stops verifying. Use instead of delete-and-recreate so delivery counters and the subscription id survive. ?preview=true is a dry run that never generates a secret.",
    "tags": [
     "webhooks"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/webhooks/{id}/deliveries": {
   "get": {
    "operationId": "webhooks_listDeliveries",
    "summary": "listDeliveries",
    "description": "The webhook's delivery log, newest first, kept 30 days. Every event is written here before it is sent; a failure worth retrying (network, 5xx, 408, 429) is tried again 1 minute, 5 minutes, 30 minutes, 2 hours and 6 hours later, so status 'pending' with nextAttemptAt means a retry is scheduled. A receiver dedupes on the X-Webhook-Delivery header, which a retry repeats.",
    "tags": [
     "webhooks"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/webhooks.WebhookDelivery"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "event": "string",
           "status": "pending",
           "attempts": 1,
           "nextAttemptAt": 1793836800,
           "lastStatusCode": 1,
           "lastError": "string",
           "createdOn": 1793836800,
           "deliveredOn": 1793836800,
           "replayOf": 1,
           "payload": {}
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "status",
      "in": "query",
      "schema": {
       "type": "string",
       "enum": [
        "pending",
        "delivered",
        "failed"
       ]
      },
      "description": "Only deliveries in this state"
     },
     {
      "name": "event",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "description": "Only this event, e.g. student.created"
     },
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Page number (1-indexed)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer"
      },
      "description": "Items per page"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/webhooks/{id}/deliveries/{deliveryId}": {
   "get": {
    "operationId": "webhooks_getDelivery",
    "summary": "getDelivery",
    "description": "One delivery, with the exact body that was sent (payload) and how its last attempt went.",
    "tags": [
     "webhooks"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/webhooks.WebhookDelivery"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "event": "string",
          "status": "pending",
          "attempts": 1,
          "nextAttemptAt": 1793836800,
          "lastStatusCode": 1,
          "lastError": "string",
          "createdOn": 1793836800,
          "deliveredOn": 1793836800,
          "replayOf": 1,
          "payload": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "deliveryId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/webhooks/{id}/deliveries/{deliveryId}/replay": {
   "post": {
    "operationId": "webhooks_replayDelivery",
    "summary": "replayDelivery",
    "description": "Send a logged delivery's event again, as a new delivery (its own X-Webhook-Delivery id, a fresh timestamp, the current secret) whose body names the one it repeats in replayOf, so a receiver can tell it from a new event. Refused while the webhook is switched off. ?preview=true sends nothing.",
    "tags": [
     "webhooks"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/webhooks.WebhookDelivery"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "event": "string",
            "status": "pending",
            "attempts": 1,
            "nextAttemptAt": 1793836800,
            "lastStatusCode": 1,
            "lastError": "string",
            "createdOn": 1793836800,
            "deliveredOn": 1793836800,
            "replayOf": 1,
            "payload": {}
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "event": "string",
            "status": "pending",
            "attempts": 1,
            "nextAttemptAt": 1793836800,
            "lastStatusCode": 1,
            "lastError": "string",
            "createdOn": 1793836800,
            "deliveredOn": 1793836800,
            "replayOf": 1,
            "payload": {}
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "deliveryId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/webhooks": {
   "get": {
    "operationId": "webhooks_list",
    "summary": "list",
    "description": "List all registered webhooks for the school",
    "tags": [
     "webhooks"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/webhooks.Webhook"
           }
          },
          "meta": {
           "$ref": "#/components/schemas/PaginationMeta"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "id": 1,
           "name": "string",
           "url": "https://example.com",
           "events": [
            "string"
           ],
           "description": "string",
           "isActive": 0,
           "successCount": 1,
           "failureCount": 1,
           "lastSuccessAt": 1793836800,
           "lastFailureAt": 1793836800,
           "lastStatusCode": 1,
           "consecutiveFailures": 1,
           "disabledReason": "string",
           "disabledAt": 1793836800,
           "createdOn": 1793836800
          }
         ],
         "meta": {
          "total": 1,
          "page": 1,
          "limit": 50,
          "totalPages": 1
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "page",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 1
      },
      "description": "Page number (1-indexed)"
     },
     {
      "name": "limit",
      "in": "query",
      "schema": {
       "type": "integer",
       "default": 25
      },
      "description": "Items per page (1-100)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "post": {
    "operationId": "webhooks_create",
    "summary": "create",
    "description": "Register a new webhook endpoint. ?preview=true is a dry run (the same URL checks; no secret generated, no test delivery).",
    "tags": [
     "webhooks"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/webhooks.WebhookCreated"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "url": "https://example.com",
            "events": [
             "string"
            ],
            "description": "string",
            "isActive": 0,
            "secret": "string",
            "createdOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "url": "https://example.com",
            "events": [
             "string"
            ],
            "description": "string",
            "isActive": 0,
            "secret": "string",
            "createdOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Human-readable name for the webhook",
          "minLength": 1,
          "maxLength": 100
         },
         "url": {
          "type": "string",
          "description": "HTTPS endpoint URL to receive webhook payloads. Must resolve to a public address: private, loopback and link-local destinations are rejected at create time and again at delivery.",
          "maxLength": 2048,
          "format": "url"
         },
         "events": {
          "type": "array",
          "description": "Event patterns to subscribe to (e.g., 'student.created', 'billing.*'). Wildcards supported.",
          "items": {
           "type": "string"
          }
         },
         "description": {
          "type": "string",
          "description": "Optional description of the webhook's purpose",
          "maxLength": 500
         }
        },
        "required": [
         "name",
         "url",
         "events"
        ]
       },
       "example": {
        "name": "string",
        "url": "https://example.com",
        "events": [
         "string"
        ]
       }
      }
     }
    }
   }
  },
  "/v1/webhooks/{id}": {
   "get": {
    "operationId": "webhooks_get",
    "summary": "get",
    "description": "Get a single webhook by ID, including delivery statistics",
    "tags": [
     "webhooks"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/webhooks.Webhook"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "id": 1,
          "name": "string",
          "url": "https://example.com",
          "events": [
           "string"
          ],
          "description": "string",
          "isActive": 0,
          "successCount": 1,
          "failureCount": 1,
          "lastSuccessAt": 1793836800,
          "lastFailureAt": 1793836800,
          "lastStatusCode": 1,
          "consecutiveFailures": 1,
          "disabledReason": "string",
          "disabledAt": 1793836800,
          "createdOn": 1793836800
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   },
   "patch": {
    "operationId": "webhooks_update",
    "summary": "update",
    "description": "Update an existing webhook. ?preview=true is a dry run: current vs would-become and what deliveries do next.",
    "tags": [
     "webhooks"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/webhooks.Webhook"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "name": "string",
            "url": "https://example.com",
            "events": [
             "string"
            ],
            "description": "string",
            "isActive": 0,
            "successCount": 1,
            "failureCount": 1,
            "lastSuccessAt": 1793836800,
            "lastFailureAt": 1793836800,
            "lastStatusCode": 1,
            "consecutiveFailures": 1,
            "disabledReason": "string",
            "disabledAt": 1793836800,
            "createdOn": 1793836800
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "name": "string",
            "url": "https://example.com",
            "events": [
             "string"
            ],
            "description": "string",
            "isActive": 0,
            "successCount": 1,
            "failureCount": 1,
            "lastSuccessAt": 1793836800,
            "lastFailureAt": 1793836800,
            "lastStatusCode": 1,
            "consecutiveFailures": 1,
            "disabledReason": "string",
            "disabledAt": 1793836800,
            "createdOn": 1793836800
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "name": {
          "type": "string",
          "description": "Human-readable name",
          "minLength": 1,
          "maxLength": 100
         },
         "url": {
          "type": "string",
          "description": "HTTPS endpoint URL. Must resolve to a public address.",
          "maxLength": 2048,
          "format": "url"
         },
         "events": {
          "type": "array",
          "description": "Event patterns to subscribe to",
          "items": {
           "type": "string"
          }
         },
         "description": {
          "type": "string",
          "description": "Optional description",
          "maxLength": 500
         },
         "isActive": {
          "type": "boolean",
          "description": "Enable or disable the webhook"
         }
        }
       },
       "example": {
        "name": "string",
        "url": "https://example.com",
        "events": [
         "string"
        ],
        "description": "string",
        "isActive": false
       }
      }
     }
    }
   },
   "delete": {
    "operationId": "webhooks_delete",
    "summary": "delete",
    "description": "Remove a webhook registration. ?preview=true is a dry run: the URL and events that stop being delivered.",
    "tags": [
     "webhooks"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "type": "object"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {}
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {},
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR, CONFIRMATION_REQUIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "CONFIRMATION_REQUIRED",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "NOT_FOUND",
     "CONFLICT",
     "PRECONDITION_FAILED",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "id",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      }
     },
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "confirm",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Destructive operation: confirm=true is required to execute."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ]
   }
  },
  "/v1/batch": {
   "post": {
    "operationId": "batch_execute",
    "summary": "execute",
    "description": "Execute a batch of operations. Each operation is processed sequentially and returns its own status code. An operation's path carries its own query string (?confirm=true, filters, limits), exactly as if sent alone. Supports ?preview=true: each operation whose own _schema declares preview runs as its dry run (in order, each result under its id); any other operation, reads included, is not run and comes back with dryRun false and a note.",
    "tags": [
     "batch"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/batch.BatchResponse"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "results": [
             {}
            ],
            "summary": {
             "total": 1,
             "succeeded": 1,
             "failed": 1
            }
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "results": [
             {}
            ],
            "summary": {
             "total": 1,
             "succeeded": 1,
             "failed": 1
            }
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "irreversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "operations": {
          "type": "array",
          "description": "Array of operations to execute (1-20)",
          "items": {
           "$ref": "#/components/schemas/batch.BatchOperation"
          }
         }
        },
        "required": [
         "operations"
        ]
       },
       "example": {
        "operations": [
         {
          "id": "string",
          "method": "GET",
          "path": "string",
          "body": {},
          "headers": {}
         }
        ]
       }
      }
     }
    }
   }
  },
  "/v1/student-insight/classes/{eventId}/{date}": {
   "get": {
    "operationId": "student-insight_classInsight",
    "summary": "classInsight",
    "description": "Roster with one primary signal per student, a summary of up to five people with Insight, and overlapping counts (checked in, expected, eligible, people with Insight). Students are tiered: 1 checked in, 2 booked or enrolled, 3 eligible and usually attends (unconfirmed), 4 eligible with class-specific Insight, 5 other eligible.",
    "tags": [
     "student-insight"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/student-insight.ClassInsight"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "eventId": 1,
          "date": "2026-11-05",
          "eventName": "string",
          "isCancelled": false,
          "asOf": 1,
          "ruleVersion": "string",
          "counts": {},
          "dataCoverage": {},
          "summary": [],
          "roster": []
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "eventId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Event id"
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "Occurrence date (YYYY-MM-DD)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/student-insight/classes/{eventId}/{date}/students/{studentId}": {
   "get": {
    "operationId": "student-insight_studentDetail",
    "summary": "studentDetail",
    "description": "All signals for one student on the occurrence with evidence and suggested actions. Owner/admin callers additionally receive rule-baseline retention context and an account follow-up flag.",
    "tags": [
     "student-insight"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "$ref": "#/components/schemas/student-insight.StudentInsightDetail"
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": {
          "studentId": 1,
          "signals": [],
          "retention": {},
          "account": {}
         }
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "404": {
      "description": "NOT_FOUND",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "NOT_FOUND",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "NOT_FOUND",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "eventId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Event id"
     },
     {
      "name": "date",
      "in": "path",
      "required": true,
      "schema": {
       "type": "string",
       "format": "date"
      },
      "description": "Occurrence date (YYYY-MM-DD)"
     },
     {
      "name": "studentId",
      "in": "path",
      "required": true,
      "schema": {
       "type": "integer"
      },
      "description": "Student id"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/student-insight/day": {
   "get": {
    "operationId": "student-insight_dayCounts",
    "summary": "dayCounts",
    "description": "Per-occurrence count of people with Insight for every non-cancelled class on a day.",
    "tags": [
     "student-insight"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "ETag": {
        "$ref": "#/components/headers/ETag"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "type": "object",
         "properties": {
          "success": {
           "type": "boolean",
           "enum": [
            true
           ]
          },
          "data": {
           "type": "array",
           "items": {
            "$ref": "#/components/schemas/student-insight.DayInsightCount"
           }
          }
         },
         "required": [
          "success",
          "data"
         ]
        },
        "example": {
         "success": true,
         "data": [
          {
           "eventId": 1,
           "startTime": "string",
           "withInsight": 1
          }
         ]
        }
       }
      }
     },
     "304": {
      "description": "Not modified: the If-None-Match ETag is still current."
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "FORBIDDEN",
     "RATE_LIMITED"
    ],
    "parameters": [
     {
      "name": "date",
      "in": "query",
      "schema": {
       "type": "string"
      },
      "required": true,
      "description": "Day (YYYY-MM-DD)"
     },
     {
      "name": "If-None-Match",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The ETag of the copy you hold: 304 when it is still current."
     }
    ]
   }
  },
  "/v1/student-insight/actions": {
   "post": {
    "operationId": "student-insight_recordAction",
    "summary": "recordAction",
    "description": "Record a staff action on a signal. 'spoke' completes the conversation for that occurrence (the person leaves the summary; the signal stays). 'not_relevant' suppresses that signal type for the student for 7 days.",
    "tags": [
     "student-insight"
    ],
    "responses": {
     "200": {
      "description": "Success",
      "headers": {
       "X-RateLimit-Limit": {
        "$ref": "#/components/headers/X-RateLimit-Limit"
       },
       "X-RateLimit-Remaining": {
        "$ref": "#/components/headers/X-RateLimit-Remaining"
       },
       "X-RateLimit-Reset": {
        "$ref": "#/components/headers/X-RateLimit-Reset"
       },
       "X-Preview-Token": {
        "$ref": "#/components/headers/X-Preview-Token"
       },
       "Preview-Token-Status": {
        "$ref": "#/components/headers/Preview-Token-Status"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "oneOf": [
          {
           "type": "object",
           "properties": {
            "success": {
             "type": "boolean",
             "enum": [
              true
             ]
            },
            "data": {
             "$ref": "#/components/schemas/student-insight.InsightAction"
            }
           },
           "required": [
            "success",
            "data"
           ]
          },
          {
           "$ref": "#/components/schemas/PreviewResponse"
          }
         ]
        },
        "examples": {
         "committed": {
          "summary": "The commit",
          "value": {
           "success": true,
           "data": {
            "id": 1,
            "expiresOn": 1
           }
          }
         },
         "dryRun": {
          "summary": "With ?preview=true",
          "value": {
           "success": true,
           "preview": true,
           "data": {
            "id": 1,
            "expiresOn": 1
           },
           "validation": "ok",
           "previewToken": "p1.k7Qx…"
          }
         }
        }
       }
      }
     },
     "400": {
      "description": "VALIDATION_ERROR",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "401": {
      "description": "UNAUTHORIZED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "UNAUTHORIZED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "402": {
      "description": "ACCOUNT_LOCKED, TRIAL_EXPIRED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "ACCOUNT_LOCKED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "403": {
      "description": "FORBIDDEN",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "FORBIDDEN",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "409": {
      "description": "CONFLICT, IDEMPOTENCY_IN_PROGRESS",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "CONFLICT",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "412": {
      "description": "PRECONDITION_FAILED",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "PRECONDITION_FAILED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "422": {
      "description": "VALIDATION_ERROR, CONFLICT",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "VALIDATION_ERROR",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "429": {
      "description": "RATE_LIMITED",
      "headers": {
       "Retry-After": {
        "$ref": "#/components/headers/Retry-After"
       }
      },
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "RATE_LIMITED",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "503": {
      "description": "SERVICE_UNAVAILABLE, IDEMPOTENCY_UNAVAILABLE",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        },
        "example": {
         "success": false,
         "error": {
          "code": "SERVICE_UNAVAILABLE",
          "message": "Why it was refused, in words.",
          "recovery": {
           "suggestion": "What to do next."
          }
         }
        }
       }
      }
     },
     "default": {
      "description": "Error",
      "content": {
       "application/json": {
        "schema": {
         "$ref": "#/components/schemas/Error"
        }
       }
      }
     }
    },
    "x-error-codes": [
     "VALIDATION_ERROR",
     "UNAUTHORIZED",
     "ACCOUNT_LOCKED",
     "TRIAL_EXPIRED",
     "FORBIDDEN",
     "CONFLICT",
     "IDEMPOTENCY_IN_PROGRESS",
     "PRECONDITION_FAILED",
     "VALIDATION_ERROR",
     "CONFLICT",
     "RATE_LIMITED",
     "SERVICE_UNAVAILABLE",
     "IDEMPOTENCY_UNAVAILABLE"
    ],
    "x-risk": "reversible",
    "parameters": [
     {
      "name": "preview",
      "in": "query",
      "schema": {
       "type": "boolean"
      },
      "description": "Set preview=true to dry-run this operation without persisting changes."
     },
     {
      "name": "Idempotency-Key",
      "in": "header",
      "schema": {
       "type": "string",
       "maxLength": 255
      },
      "description": "Safe retries: the same key within 24h returns the first answer; the same key while the first is still running is refused 409; the same key on a different request 422."
     },
     {
      "name": "X-Preview-Token",
      "in": "header",
      "schema": {
       "type": "string"
      },
      "description": "The previewToken of the dry run the person approved. Required from AI callers; checked when a plain integration sends one. A stale one is refused 409 with a fresh preview, a bad or missing one 412."
     }
    ],
    "requestBody": {
     "required": true,
     "content": {
      "application/json": {
       "schema": {
        "type": "object",
        "properties": {
         "eventId": {
          "type": "number",
          "description": "Event id"
         },
         "date": {
          "type": "string",
          "description": "Occurrence date",
          "format": "date"
         },
         "studentId": {
          "type": "number",
          "description": "Student id"
         },
         "signalType": {
          "type": "string",
          "description": "Signal the action answers",
          "enum": [
           "first_class",
           "returning",
           "birthday",
           "attendance_decline",
           "milestone",
           "recent_note"
          ]
         },
         "action": {
          "type": "string",
          "description": "Action taken",
          "enum": [
           "spoke",
           "not_relevant"
          ]
         }
        },
        "required": [
         "eventId",
         "date",
         "studentId",
         "signalType",
         "action"
        ]
       },
       "example": {
        "eventId": 1,
        "date": "2026-11-05",
        "studentId": 1,
        "signalType": "first_class",
        "action": "spoke"
       }
      }
     }
    }
   }
  }
 },
 "components": {
  "schemas": {
   "Error": {
    "type": "object",
    "properties": {
     "success": {
      "type": "boolean",
      "enum": [
       false
      ]
     },
     "error": {
      "type": "object",
      "properties": {
       "code": {
        "type": "string",
        "description": "Stable machine code; the operation's x-error-codes lists the ones it can answer with."
       },
       "message": {
        "type": "string",
        "description": "Why, in words a person can act on."
       },
       "details": {
        "type": "array",
        "description": "Field-level problems: field, message, code.",
        "items": {
         "type": "object",
         "properties": {
          "field": {
           "type": "string"
          },
          "message": {
           "type": "string"
          },
          "code": {
           "type": "string"
          }
         }
        }
       },
       "recovery": {
        "type": "object",
        "description": "What to do next: a suggestion, and actions (method + href) where there is one.",
        "properties": {
         "suggestion": {
          "type": "string"
         },
         "actions": {
          "type": "array",
          "items": {
           "type": "object",
           "properties": {
            "method": {
             "type": "string"
            },
            "href": {
             "type": "string"
            },
            "description": {
             "type": "string"
            }
           }
          }
         }
        }
       },
       "data": {
        "type": "object",
        "additionalProperties": true,
        "description": "What the refusal carries: a stale preview's 409 has preview, validation and a fresh previewToken; WAIVER_REQUIRED has the waiver; PAYMENT_DETAILS_NEEDED says where."
       },
       "billingCode": {
        "type": "string",
        "description": "On a billing refusal, the finer code (PLAN_NOT_FOUND, SUBSCRIPTION_NOT_FOUND, PLAN_COLLISION, …) beside the standard one."
       }
      },
      "required": [
       "code",
       "message"
      ]
     }
    },
    "required": [
     "success",
     "error"
    ]
   },
   "PreviewResponse": {
    "type": "object",
    "description": "A dry run's answer (?preview=true): nothing was written.",
    "properties": {
     "success": {
      "type": "boolean",
      "enum": [
       true
      ]
     },
     "preview": {
      "type": "boolean",
      "enum": [
       true
      ]
     },
     "data": {
      "type": "object",
      "additionalProperties": true,
      "description": "What would happen: wouldCreate, or current / wouldUpdate / wouldBecome, or wouldDelete, or affected / affectedItems."
     },
     "validation": {
      "oneOf": [
       {
        "type": "string",
        "enum": [
         "ok"
        ]
       },
       {
        "type": "array",
        "items": {
         "type": "object",
         "properties": {
          "field": {
           "type": "string"
          },
          "message": {
           "type": "string"
          }
         }
        }
       }
      ],
      "description": "ok, or notes the person should see (a possible duplicate)."
     },
     "previewToken": {
      "type": "string",
      "description": "Send it in X-Preview-Token to commit exactly this. Lasts 15 minutes; commits once."
     }
    },
    "required": [
     "success",
     "preview",
     "data",
     "validation"
    ]
   },
   "PaginationMeta": {
    "type": "object",
    "description": "Page lists.",
    "properties": {
     "total": {
      "type": "integer"
     },
     "page": {
      "type": "integer"
     },
     "limit": {
      "type": "integer"
     },
     "totalPages": {
      "type": "integer"
     }
    },
    "required": [
     "total",
     "page",
     "limit",
     "totalPages"
    ]
   },
   "CursorMeta": {
    "type": "object",
    "description": "Cursor lists: pass nextCursor as ?cursor= for the next page; null on the last.",
    "properties": {
     "count": {
      "type": "integer"
     },
     "total": {
      "type": "integer"
     },
     "nextCursor": {
      "type": [
       "string",
       "null"
      ]
     }
    },
    "required": [
     "count",
     "nextCursor"
    ]
   },
   "ActionMeta": {
    "type": "object",
    "description": "What a write did.",
    "properties": {
     "action": {
      "type": "string",
      "enum": [
       "created",
       "updated",
       "deleted"
      ]
     },
     "message": {
      "type": "string"
     },
     "timestamp": {
      "type": "integer",
      "description": "Unix milliseconds."
     }
    },
    "required": [
     "action",
     "timestamp"
    ]
   },
   "auth.AuthTokens": {
    "type": "object",
    "properties": {
     "accessToken": {
      "type": "string",
      "description": "JWT access token (include as Authorization: Bearer <token>)",
      "readOnly": true
     },
     "refreshToken": {
      "type": "string",
      "description": "Refresh token for obtaining new access tokens",
      "readOnly": true
     },
     "expiresIn": {
      "type": "integer",
      "description": "Access token expiry in seconds",
      "readOnly": true
     }
    }
   },
   "auth.CurrentUser": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "User ID",
      "readOnly": true
     },
     "email": {
      "type": "string",
      "description": "User email",
      "readOnly": true
     },
     "firstName": {
      "type": "string",
      "description": "First name",
      "readOnly": true
     },
     "lastName": {
      "type": "string",
      "description": "Last name",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "description": "School ID this user belongs to",
      "readOnly": true
     },
     "permissions": {
      "type": "array",
      "description": "Permission IDs granted to this user",
      "readOnly": true,
      "items": {
       "type": "integer"
      }
     }
    }
   },
   "students.MemberInNoStyle": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "firstName": {
      "type": "string",
      "description": "First name"
     },
     "lastName": {
      "type": "string",
      "description": "Last name"
     }
    }
   },
   "students.Student": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "firstName": {
      "type": "string",
      "description": "First name"
     },
     "lastName": {
      "type": "string",
      "description": "Last name"
     },
     "emailAddress": {
      "type": "string",
      "description": "Email address. Absent when the caller lacks the Email sub-permission",
      "format": "email"
     },
     "mobileNumber": {
      "type": [
       "string",
       "null"
      ],
      "description": "Mobile number. Absent when the caller lacks the Phone sub-permission"
     },
     "isActive": {
      "type": "integer",
      "description": "1 for a current member. 0/1 on read; the write bodies take a boolean",
      "readOnly": true,
      "enum": [
       0,
       1
      ]
     },
     "isLead": {
      "type": "integer",
      "description": "1 for a lead (not a member)",
      "readOnly": true,
      "enum": [
       0,
       1
      ]
     },
     "isTrial": {
      "type": "integer",
      "description": "1 for a trial",
      "readOnly": true,
      "enum": [
       0,
       1
      ]
     },
     "trialStartedOn": {
      "type": [
       "string",
       "null"
      ],
      "description": "YYYY-MM-DD",
      "format": "date"
     },
     "trialExpiresOn": {
      "type": [
       "string",
       "null"
      ],
      "description": "YYYY-MM-DD",
      "format": "date"
     },
     "trialClassesLimit": {
      "type": [
       "integer",
       "null"
      ]
     },
     "trialClassesUsed": {
      "type": "integer"
     },
     "joinedOn": {
      "type": [
       "string",
       "null"
      ],
      "description": "YYYY-MM-DD",
      "format": "date"
     },
     "birthday": {
      "type": [
       "string",
       "null"
      ],
      "description": "YYYY-MM-DD. Absent when the caller lacks the Birthday sub-permission",
      "format": "date"
     },
     "memberNumber": {
      "type": [
       "string",
       "null"
      ]
     },
     "lastSeenOn": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Last check-in",
      "format": "unix-seconds"
     },
     "planStatus": {
      "type": [
       "string",
       "null"
      ],
      "description": "The primary plan's status; null with no plan",
      "readOnly": true,
      "enum": [
       "active",
       "paused",
       "cancelled",
       "expired",
       "overdue",
       "pending"
      ]
     },
     "passesRemaining": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Across pass plans; null without one",
      "readOnly": true
     },
     "currentRank": {
      "type": "object",
      "description": "{ id, name, color, styleName }; absent with no rank",
      "readOnly": true
     },
     "ranks": {
      "type": "array",
      "description": "{ id, name, color, styleName, order } per style",
      "readOnly": true,
      "items": {}
     },
     "tags": {
      "type": "array",
      "description": "{ id, name, colour }",
      "readOnly": true,
      "items": {}
     },
     "status": {
      "type": [
       "object",
       "null"
      ],
      "description": "{ id, name }: the one status the student holds; null with none",
      "readOnly": true
     },
     "familyId": {
      "type": [
       "integer",
       "null"
      ],
      "readOnly": true
     },
     "familyName": {
      "type": [
       "string",
       "null"
      ],
      "readOnly": true
     },
     "photoUrl": {
      "type": [
       "string",
       "null"
      ],
      "description": "A signed link to the photo; null without one",
      "readOnly": true
     },
     "photoStorageKey": {
      "type": [
       "string",
       "null"
      ],
      "description": "The stored photo's key; photoUrl is the link to use",
      "readOnly": true
     },
     "signupFormName": {
      "type": [
       "string",
       "null"
      ],
      "description": "The sign-up form the student came through",
      "readOnly": true
     },
     "contractExpiresOn": {
      "type": [
       "string",
       "null"
      ],
      "description": "YYYY-MM-DD",
      "format": "date"
     },
     "venueIds": {
      "type": "array",
      "description": "The venues the student trains at",
      "readOnly": true,
      "items": {
       "type": "integer"
      }
     },
     "deletedOn": {
      "type": [
       "integer",
       "null"
      ],
      "description": "When archived; null on a live student",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "archivedOn": {
      "type": "integer",
      "description": "On the archived list only: the same moment as deletedOn",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "students.StudentDetail": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "memberNumber": {
      "type": [
       "string",
       "null"
      ]
     },
     "firstName": {
      "type": "string"
     },
     "lastName": {
      "type": "string"
     },
     "address": {
      "type": [
       "string",
       "null"
      ]
     },
     "suburb": {
      "type": [
       "string",
       "null"
      ]
     },
     "postcode": {
      "type": [
       "string",
       "null"
      ]
     },
     "emailAddress": {
      "type": "string",
      "format": "email"
     },
     "emailAddressAlt": {
      "type": [
       "string",
       "null"
      ]
     },
     "phoneNumber": {
      "type": [
       "string",
       "null"
      ]
     },
     "mobileNumber": {
      "type": [
       "string",
       "null"
      ]
     },
     "emergencyInfo": {
      "type": [
       "string",
       "null"
      ],
      "description": "Medical and other notes for an emergency"
     },
     "gender": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "male",
       "female",
       "other",
       "prefer_not_to_say"
      ]
     },
     "birthday": {
      "type": [
       "string",
       "null"
      ],
      "description": "YYYY-MM-DD",
      "format": "date"
     },
     "isActive": {
      "type": "integer",
      "readOnly": true,
      "enum": [
       0,
       1
      ]
     },
     "isLead": {
      "type": "integer",
      "readOnly": true,
      "enum": [
       0,
       1
      ]
     },
     "isTrial": {
      "type": "integer",
      "readOnly": true,
      "enum": [
       0,
       1
      ]
     },
     "trialStartedOn": {
      "type": [
       "string",
       "null"
      ],
      "format": "date"
     },
     "trialExpiresOn": {
      "type": [
       "string",
       "null"
      ],
      "format": "date"
     },
     "trialClassesLimit": {
      "type": [
       "integer",
       "null"
      ]
     },
     "trialClassesUsed": {
      "type": "integer"
     },
     "joinedOn": {
      "type": [
       "string",
       "null"
      ],
      "description": "YYYY-MM-DD",
      "format": "date"
     },
     "contractExpiresOn": {
      "type": [
       "string",
       "null"
      ],
      "format": "date"
     },
     "lastSeenOn": {
      "type": [
       "integer",
       "null"
      ],
      "format": "unix-seconds"
     },
     "notes": {
      "type": [
       "string",
       "null"
      ]
     },
     "beltSize": {
      "type": [
       "string",
       "null"
      ]
     },
     "uniformSize": {
      "type": [
       "string",
       "null"
      ]
     },
     "receiveEmail": {
      "type": "boolean"
     },
     "receiveSms": {
      "type": "boolean"
     },
     "receiveChat": {
      "type": "boolean"
     },
     "referralSource": {
      "type": [
       "string",
       "null"
      ]
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "updatedOn": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Echo it on PATCH to refuse a stale edit",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "deactivatedOn": {
      "type": [
       "integer",
       "null"
      ],
      "readOnly": true,
      "format": "unix-seconds"
     },
     "deletedOn": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Always null here: an archived student is not returned",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "onetouchId": {
      "type": [
       "integer",
       "null"
      ],
      "description": "The sign-up form the student came through, by id",
      "readOnly": true
     },
     "onetouchFormId": {
      "type": [
       "integer",
       "null"
      ],
      "readOnly": true
     },
     "portalStatus": {
      "type": [
       "string",
       "null"
      ],
      "description": "The student app invitation: null, invited or active",
      "readOnly": true
     },
     "appVersion": {
      "type": [
       "string",
       "null"
      ],
      "description": "The student app version last seen",
      "readOnly": true
     },
     "wasActiveThisMonth": {
      "type": "integer",
      "readOnly": true,
      "enum": [
       0,
       1
      ]
     },
     "paymentMethod": {
      "type": [
       "string",
       "null"
      ],
      "description": "A note of how they pay, free text"
     },
     "paymentFrequency": {
      "type": [
       "string",
       "null"
      ],
      "description": "A note of how often, free text"
     },
     "photoStorageKey": {
      "type": [
       "string",
       "null"
      ],
      "description": "The stored photo's key; photoUrl is the link to use",
      "readOnly": true
     },
     "referredOn": {
      "type": [
       "string",
       "null"
      ],
      "description": "YYYY-MM-DD, for a record that began as a lead",
      "format": "date"
     },
     "convertedOn": {
      "type": [
       "string",
       "null"
      ],
      "description": "When a lead became a member",
      "format": "date"
     },
     "leadStageId": {
      "type": [
       "integer",
       "null"
      ],
      "description": "The pipeline stage, while a lead",
      "readOnly": true
     },
     "leadStageChangedOn": {
      "type": [
       "integer",
       "null"
      ],
      "readOnly": true,
      "format": "unix-seconds"
     },
     "leadDormantOn": {
      "type": [
       "integer",
       "null"
      ],
      "readOnly": true,
      "format": "unix-seconds"
     },
     "leadTemperatureOverride": {
      "type": [
       "integer",
       "null"
      ],
      "readOnly": true
     },
     "lossReason": {
      "type": [
       "string",
       "null"
      ],
      "description": "Why a lead was lost",
      "readOnly": true
     },
     "emailSuppression": {
      "type": [
       "object",
       "null"
      ],
      "description": "{ id, reason, createdOn } while the email address is suppressed (bounced or complained); null otherwise",
      "readOnly": true
     },
     "archivedStyleCount": {
      "type": "integer",
      "description": "Styles the student has rank history in but no longer holds a rank in. Read them via GET /v1/grading/students/:studentId/archived.",
      "readOnly": true
     },
     "signupFormName": {
      "type": [
       "string",
       "null"
      ],
      "readOnly": true
     },
     "ranks": {
      "type": "array",
      "description": "{ id, name, color, colorAlt, styleId, styleName, stripes, stripeColor, order, awardedOn, gradingEligibility, nextRank }",
      "readOnly": true,
      "items": {}
     },
     "tags": {
      "type": "array",
      "description": "{ id, name, colour }",
      "readOnly": true,
      "items": {}
     },
     "status": {
      "type": [
       "object",
       "null"
      ],
      "description": "{ id, name }: the one status the student holds; null with none",
      "readOnly": true
     },
     "venues": {
      "type": "array",
      "description": "{ id, name }",
      "readOnly": true,
      "items": {}
     },
     "emergencyContacts": {
      "type": "array",
      "description": "{ id, firstName, lastName, relationship, mobile, phone, email, receiveEmails, receiveSms }",
      "readOnly": true,
      "items": {}
     },
     "family": {
      "type": [
       "object",
       "null"
      ],
      "description": "{ id, name,... } when the student is in a family",
      "readOnly": true
     },
     "clubs": {
      "type": "array",
      "readOnly": true,
      "items": {}
     },
     "photoUrl": {
      "type": [
       "string",
       "null"
      ],
      "description": "A signed link to the photo",
      "readOnly": true
     }
    }
   },
   "students.StudentCheckInCode": {
    "type": "object",
    "properties": {
     "code": {
      "type": "string",
      "description": "20 uppercase hex characters; the exact text to encode in the QR.",
      "readOnly": true
     }
    }
   },
   "students.StudentCounts": {
    "type": "object",
    "properties": {
     "active": {
      "type": "integer",
      "description": "Members: is_active=1, is_lead=0, is_trial=0.",
      "readOnly": true
     },
     "inactive": {
      "type": "integer",
      "description": "Former members: is_active is neither 1 nor 2, not a lead or trial.",
      "readOnly": true
     },
     "leads": {
      "type": "integer",
      "description": "Leads: is_lead=1, is_trial=0. Shape-agnostic on is_active.",
      "readOnly": true
     },
     "trials": {
      "type": "integer",
      "description": "is_trial=1.",
      "readOnly": true
     },
     "archived": {
      "type": "integer",
      "description": "Archived records, outside the four live buckets.",
      "readOnly": true
     }
    }
   },
   "students.PendingStudent": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Request id, NOT a student id",
      "readOnly": true
     },
     "firstName": {
      "type": "string",
      "readOnly": true
     },
     "lastName": {
      "type": "string",
      "readOnly": true
     },
     "emailAddress": {
      "type": "string",
      "readOnly": true
     },
     "mobileNumber": {
      "type": "string",
      "readOnly": true
     },
     "phoneNumber": {
      "type": "string",
      "readOnly": true
     },
     "gender": {
      "type": "string",
      "readOnly": true
     },
     "birthday": {
      "type": "string",
      "description": "YYYY-MM-DD",
      "readOnly": true,
      "format": "date"
     },
     "address": {
      "type": "string",
      "readOnly": true
     },
     "suburb": {
      "type": "string",
      "readOnly": true
     },
     "postcode": {
      "type": "string",
      "readOnly": true
     },
     "medical": {
      "type": "string",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "Non-null when this is an info update for an existing student; approval edits that student instead of creating one.",
      "readOnly": true
     },
     "submittedOn": {
      "type": "integer",
      "description": "Unix seconds",
      "readOnly": true
     },
     "updatedOn": {
      "type": "integer",
      "description": "Unix seconds",
      "readOnly": true
     },
     "emailSuppression": {
      "type": "object",
      "description": "Live Send suppression on the primary email address: {id, reason (hard_bounce | spam_complaint | opt_out | manual), createdOn}. null when mail is not blocked. DELETE /v1/send/suppression/:id lifts it (never for spam_complaint).",
      "readOnly": true
     }
    }
   },
   "students.FilterOptions": {
    "type": "object",
    "properties": {
     "tags": {
      "type": "array",
      "description": "Available tags with counts",
      "readOnly": true,
      "items": {}
     },
     "styles": {
      "type": "array",
      "description": "Available styles",
      "readOnly": true,
      "items": {}
     },
     "ranks": {
      "type": "array",
      "description": "Available ranks (grouped by style)",
      "readOnly": true,
      "items": {}
     },
     "statuses": {
      "type": "array",
      "description": "Valid status values",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "students.StudentNote": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "readOnly": true
     },
     "content": {
      "type": "string"
     },
     "type": {
      "type": "string",
      "enum": [
       "general",
       "medical",
       "billing",
       "behavioral"
      ]
     },
     "createdBy": {
      "type": "string",
      "readOnly": true
     },
     "createdAt": {
      "type": "string",
      "readOnly": true,
      "format": "date-time"
     }
    }
   },
   "students.StudentFile": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "File name"
     },
     "size": {
      "type": "integer",
      "description": "File size in bytes",
      "readOnly": true
     },
     "mimeType": {
      "type": "string",
      "readOnly": true
     },
     "url": {
      "type": "string",
      "description": "Download URL",
      "readOnly": true,
      "format": "url"
     },
     "createdAt": {
      "type": "string",
      "readOnly": true,
      "format": "date-time"
     }
    }
   },
   "students.AssignPlanResult": {
    "type": "object",
    "properties": {
     "subscriptionId": {
      "type": "integer",
      "description": "ID of the created subscription",
      "readOnly": true
     },
     "transactionId": {
      "type": "integer",
      "description": "ID of the initial payment transaction (null if no one-off amount)",
      "readOnly": true
     }
    }
   },
   "attendance.AttendanceRecord": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Attendance record ID",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Student full name",
      "readOnly": true
     },
     "classId": {
      "type": "integer",
      "description": "Class ID",
      "readOnly": true
     },
     "className": {
      "type": "string",
      "description": "Class name",
      "readOnly": true
     },
     "date": {
      "type": "string",
      "description": "Attendance date",
      "readOnly": true,
      "format": "date"
     },
     "checkInTime": {
      "type": "string",
      "description": "Check-in time",
      "readOnly": true,
      "format": "time"
     }
    }
   },
   "attendance.AttendanceStudent": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "readOnly": true
     },
     "checkedIn": {
      "type": "boolean",
      "description": "Whether student is checked in for the given date/class",
      "readOnly": true
     },
     "attendanceId": {
      "type": "integer",
      "description": "Attendance record ID if checked in",
      "readOnly": true
     }
    }
   },
   "attendance.TodaySummary": {
    "type": "object",
    "properties": {
     "total": {
      "type": "integer",
      "description": "Total check-ins today",
      "readOnly": true
     },
     "byClass": {
      "type": "array",
      "description": "Breakdown by class",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "attendance.ActiveEvent": {
    "type": "object",
    "properties": {
     "eventId": {
      "type": "integer",
      "description": "Event ID",
      "readOnly": true
     },
     "eventName": {
      "type": "string",
      "description": "Event name",
      "readOnly": true
     },
     "startTime": {
      "type": "integer",
      "description": "Start time (HHMM format)",
      "readOnly": true
     },
     "endTime": {
      "type": "integer",
      "description": "End time (HHMM format)",
      "readOnly": true
     },
     "venueId": {
      "type": "integer",
      "description": "Venue ID",
      "readOnly": true
     },
     "venueName": {
      "type": "string",
      "description": "Venue name",
      "readOnly": true
     }
    }
   },
   "attendance.CurrentlyAttending": {
    "type": "object",
    "properties": {
     "total": {
      "type": "integer",
      "description": "Total students currently checked in across the school",
      "readOnly": true
     },
     "since": {
      "type": "integer",
      "description": "Start of the lookback window (unix seconds)",
      "readOnly": true
     },
     "byVenue": {
      "type": "array",
      "description": "Per-venue breakdown [{ venueId, venueName, count }]",
      "readOnly": true,
      "items": {}
     },
     "windowMinutes": {
      "type": "integer",
      "description": "Lookback window used (resolved from query or school setting 22)",
      "readOnly": true
     }
    }
   },
   "attendance.AtRiskStudent": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Student full name",
      "readOnly": true
     },
     "recentCount": {
      "type": "integer",
      "description": "Attendance count in recent window",
      "readOnly": true
     },
     "baselineAvg": {
      "type": "number",
      "description": "Average attendance in baseline window",
      "readOnly": true
     },
     "dropPercentage": {
      "type": "number",
      "description": "Percentage drop in attendance",
      "readOnly": true
     }
    }
   },
   "grading.StudentRank": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Student rank record ID",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "rankId": {
      "type": "integer",
      "description": "Rank ID",
      "readOnly": true
     },
     "rankName": {
      "type": "string",
      "description": "Rank display name",
      "readOnly": true
     },
     "styleName": {
      "type": "string",
      "description": "Style/art name",
      "readOnly": true
     },
     "gradingDate": {
      "type": "string",
      "description": "Date of grading",
      "readOnly": true,
      "format": "date"
     },
     "notes": {
      "type": "string",
      "description": "Notes",
      "readOnly": true
     }
    }
   },
   "grading.GradingHistory": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer",
      "readOnly": true
     },
     "styleId": {
      "type": "integer",
      "readOnly": true
     },
     "ranks": {
      "type": "array",
      "description": "Rank progression history",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/grading.StudentRank"
      }
     },
     "eligibility": {
      "type": "object",
      "description": "Eligibility for next grading",
      "readOnly": true
     }
    }
   },
   "grading.ArchivedGradingHistory": {
    "type": "object",
    "properties": {
     "styles": {
      "type": "array",
      "description": "One entry per archived style, most recently trained first",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/grading.ArchivedStyle"
      }
     }
    }
   },
   "grading.ArchivedStyle": {
    "type": "object",
    "properties": {
     "styleId": {
      "type": "integer",
      "readOnly": true
     },
     "styleName": {
      "type": "string",
      "readOnly": true
     },
     "firstGradedOn": {
      "type": "string",
      "description": "Earliest grading in the style (YYYY-MM-DD)",
      "readOnly": true,
      "format": "date"
     },
     "lastGradedOn": {
      "type": "string",
      "description": "Latest grading in the style (YYYY-MM-DD)",
      "readOnly": true,
      "format": "date"
     },
     "records": {
      "type": "array",
      "description": "Ranks held, newest first",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/grading.ArchivedRankRecord"
      }
     }
    }
   },
   "grading.ArchivedRankRecord": {
    "type": "object",
    "properties": {
     "studentRankId": {
      "type": "integer",
      "readOnly": true
     },
     "rankId": {
      "type": "integer",
      "readOnly": true
     },
     "rankName": {
      "type": "string",
      "readOnly": true
     },
     "rankColor": {
      "type": "string",
      "readOnly": true
     },
     "rankColorAlt": {
      "type": "string",
      "readOnly": true
     },
     "stripes": {
      "type": "integer",
      "readOnly": true
     },
     "stripeColor": {
      "type": "string",
      "readOnly": true
     },
     "gradedOn": {
      "type": "string",
      "description": "Grading date, or the day the rank was recorded when no grading date was set",
      "readOnly": true,
      "format": "date"
     },
     "notes": {
      "type": "string",
      "description": "Grading notes",
      "readOnly": true
     }
    }
   },
   "grading.SkillScore": {
    "type": "object",
    "properties": {
     "studentRankId": {
      "type": "integer",
      "readOnly": true
     },
     "skillId": {
      "type": "integer",
      "readOnly": true
     },
     "score": {
      "type": "string",
      "description": "Score (pass/fail)",
      "readOnly": true,
      "enum": [
       "pass",
       "fail"
      ]
     },
     "notes": {
      "type": "string",
      "description": "Skill notes",
      "readOnly": true
     }
    }
   },
   "grading.GradingRoster": {
    "type": "object",
    "properties": {
     "styleId": {
      "type": "integer",
      "readOnly": true
     },
     "styleName": {
      "type": "string",
      "readOnly": true
     },
     "rankNoun": {
      "type": "string",
      "description": "Style-specific noun for rank (e.g. 'belt')",
      "readOnly": true
     },
     "counts": {
      "type": "object",
      "description": "{ green, yellow, red, na, total }",
      "readOnly": true
     },
     "green": {
      "type": "array",
      "description": "Ready to grade (eScore >= 80)",
      "readOnly": true,
      "items": {}
     },
     "yellow": {
      "type": "array",
      "description": "Almost ready (50 <= eScore < 80)",
      "readOnly": true,
      "items": {}
     },
     "red": {
      "type": "array",
      "description": "Not ready (eScore < 50)",
      "readOnly": true,
      "items": {}
     },
     "na": {
      "type": "array",
      "description": "Style has no requirements set",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "grading.BulkPromoteResult": {
    "type": "object",
    "properties": {
     "groupHash": {
      "type": "string",
      "description": "Shared MD5 hash for this batch (used in /promotions/:groupHash/report)",
      "readOnly": true
     },
     "promotedCount": {
      "type": "integer",
      "readOnly": true
     },
     "skippedCount": {
      "type": "integer",
      "description": "Students skipped due to no_current_rank/no_next_rank/student_not_found/target_rank_not_advance",
      "readOnly": true
     },
     "results": {
      "type": "array",
      "description": "Per-student outcome rows",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "grading.BulkPromoteUndoResult": {
    "type": "object",
    "properties": {
     "undoneCount": {
      "type": "integer",
      "description": "Number of students reverted to their prior rank",
      "readOnly": true
     },
     "results": {
      "type": "array",
      "description": "Per-student demotion rows ({ studentId, fromRankId, toRankId })",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "workflows.WorkflowResult": {
    "type": "object",
    "properties": {
     "mode": {
      "type": "string",
      "description": "Which mode ran.",
      "enum": [
       "preview",
       "execute"
      ]
     },
     "summary": {
      "type": "string",
      "description": "Prose description of what happened (execute) or would happen (preview)."
     },
     "data": {
      "type": "object",
      "description": "Structured result: shape varies per workflow."
     },
     "warnings": {
      "type": "array",
      "description": "Partial-failure reports on execute; empty when everything succeeded.",
      "items": {}
     }
    }
   },
   "families.Family": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Family ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Family name"
     },
     "email": {
      "type": "string",
      "description": "Contact email"
     },
     "phone": {
      "type": "string",
      "description": "Contact phone"
     },
     "address": {
      "type": "string",
      "description": "Address"
     },
     "memberCount": {
      "type": "integer",
      "description": "Number of members",
      "readOnly": true
     }
    }
   },
   "families.FamilyDetail": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "name": {
      "type": "string"
     },
     "email": {
      "type": "string"
     },
     "phone": {
      "type": "string"
     },
     "address": {
      "type": "string"
     },
     "members": {
      "type": "array",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/families.FamilyMember"
      }
     }
    }
   },
   "families.FamilyMember": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Member record ID",
      "readOnly": true
     },
     "familyId": {
      "type": "integer",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "Linked student ID (null for non-student contacts)",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Member name"
     },
     "relationship": {
      "type": "string",
      "description": "Relationship to family"
     },
     "email": {
      "type": "string"
     },
     "phone": {
      "type": "string"
     }
    }
   },
   "families.FamilyBilling": {
    "type": "object",
    "properties": {
     "familyId": {
      "type": "integer",
      "readOnly": true
     },
     "members": {
      "type": "array",
      "description": "Billing info per member",
      "readOnly": true,
      "items": {}
     },
     "totalMonthly": {
      "type": "number",
      "description": "Total monthly billing",
      "readOnly": true
     }
    }
   },
   "families.FamilyNote": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Note ID",
      "readOnly": true
     },
     "familyId": {
      "type": "integer",
      "readOnly": true
     },
     "content": {
      "type": "string",
      "description": "Note content"
     },
     "createdBy": {
      "type": "string",
      "description": "Author name",
      "readOnly": true
     },
     "createdAt": {
      "type": "string",
      "readOnly": true,
      "format": "date-time"
     }
    }
   },
   "families.FamilyTransaction": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Transaction ID",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "Member student ID",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Member name",
      "readOnly": true
     },
     "amount": {
      "type": "integer",
      "description": "Amount in cents",
      "readOnly": true
     },
     "type": {
      "type": "string",
      "description": "Transaction type",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "description": "Transaction status, read as on the member's ledger (cancelled = written off; disputed = charged back, never retried)",
      "readOnly": true,
      "enum": [
       "successful",
       "failed",
       "retrying",
       "pending",
       "submitted",
       "disputed",
       "cancelled",
       "credit"
      ]
     },
     "failureReason": {
      "type": "string",
      "description": "The gateway's reason for a failed charge",
      "readOnly": true
     },
     "failedOn": {
      "type": "integer",
      "description": "When it failed (Unix seconds)",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "description": "Creation timestamp",
      "readOnly": true
     }
    }
   },
   "families.BillingValidation": {
    "type": "object",
    "properties": {
     "ready": {
      "type": "boolean",
      "description": "Whether the family is billing-ready",
      "readOnly": true
     },
     "hasBillingMember": {
      "type": "boolean",
      "description": "Has a billing-responsible member",
      "readOnly": true
     },
     "billingMember": {
      "type": "object",
      "description": "Billing member details (studentId, name, hasPaymentMethod)",
      "readOnly": true
     },
     "issues": {
      "type": "array",
      "description": "List of issues preventing billing readiness",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "tags.Tag": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Tag ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Tag name"
     },
     "colour": {
      "type": "string",
      "description": "Hex colour (without #), or null",
      "format": "hex-color"
     },
     "type": {
      "type": "string",
      "description": "Tag type",
      "readOnly": true,
      "enum": [
       "manual",
       "automatic"
      ]
     },
     "studentCount": {
      "type": "integer",
      "description": "Number of students with this tag",
      "readOnly": true
     },
     "categoryId": {
      "type": "integer",
      "description": "Category ID (future)",
      "readOnly": true
     },
     "rules": {
      "type": "object",
      "description": "Automatic tag rules (future)",
      "readOnly": true
     }
    }
   },
   "operations.Operation": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Operation id"
     },
     "type": {
      "type": "string",
      "description": "bulk_assign, bulk_booking, bulk_chat, bulk_checkin, cert_batch, export_photos, export_waivers, plan_migration, price_change, tax_change, billing_sync_import, or an older bulk_* type"
     },
     "label": {
      "type": "string",
      "description": "The title the tray shows, e.g. \"Assigning Adults Unlimited\""
     },
     "status": {
      "type": "string",
      "description": "A stopped run reads failed with stopped = true",
      "enum": [
       "pending",
       "in_progress",
       "completed",
       "failed"
      ]
     },
     "stopped": {
      "type": "boolean",
      "description": "An admin's Stop ended it"
     },
     "stoppable": {
      "type": "boolean",
      "description": "False when Stop cannot end it: a certificate batch has no runner and finishes as its renders land"
     },
     "startedBy": {
      "type": "integer",
      "description": "User id of who started it; null for a scheduled run"
     },
     "startedByName": {
      "type": "string",
      "description": "Their name; null when unknown"
     },
     "createdAt": {
      "type": "integer",
      "description": "Unix seconds when queued"
     },
     "completedAt": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Unix seconds when finished; null while running"
     },
     "lastProgressAt": {
      "type": "integer",
      "description": "Unix seconds of the last row it processed"
     },
     "failedReason": {
      "type": [
       "string",
       "null"
      ],
      "description": "Why it failed, when it did"
     },
     "progress": {
      "type": "object",
      "description": "total, processed, succeeded, failed, skipped, notFinished (a price change or plan move that reached Stripe or GoCardless but not our own record: not a failure)"
     },
     "inFlight": {
      "type": "object",
      "description": "The student the run is on now: studentId, studentName; null when between students or finished"
     },
     "counts": {
      "type": "object",
      "description": "Per-outcome counts for a bulk assign: assigned, requested, skipped, failed"
     },
     "results": {
      "type": "array",
      "description": "One row per student: studentId, studentName, outcome, detail, error, at (unix seconds); a certificate row adds downloadUrl. The outcome not_finished is a member moved at their gateway whose record here was not saved; detail says what is left",
      "items": {}
     },
     "file": {
      "type": [
       "object",
       "null"
      ],
      "description": "An export's zip: name, bytes, entries, expiresAt, expired, downloadUrl (a signed link good for 15 minutes; null once expired). Null for every other type"
     },
     "promote": {
      "type": [
       "object",
       "null"
      ],
      "description": "A bulk promote's batch: groupHash, styleId, styleName, promotions [{ studentId, studentRankId, studentName }], undoneOn. Null for every other type"
     }
    }
   },
   "statuses.Status": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Status ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Status name"
     },
     "order": {
      "type": "integer",
      "description": "Display order",
      "readOnly": true
     },
     "studentCount": {
      "type": "integer",
      "description": "Number of students with this status",
      "readOnly": true
     }
    }
   },
   "clubs.Club": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Club ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Club name"
     },
     "studentCount": {
      "type": "integer",
      "description": "Number of students in this club",
      "readOnly": true
     }
    }
   },
   "locations.Location": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Location ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Location name"
     },
     "address": {
      "type": "string",
      "description": "Street address (optional)"
     },
     "suburb": {
      "type": "string",
      "description": "Suburb or city (optional)"
     },
     "state": {
      "type": "string",
      "description": "State or region (optional)"
     },
     "country": {
      "type": "string",
      "description": "Country (optional)"
     },
     "postcode": {
      "type": "string",
      "description": "Postal code (optional)"
     },
     "contactNumber": {
      "type": "string",
      "description": "Contact phone number (optional)"
     },
     "capacity": {
      "type": "integer",
      "description": "Maximum venue capacity (optional)"
     },
     "latitude": {
      "type": "number",
      "description": "GPS latitude coordinate (optional)"
     },
     "longitude": {
      "type": "number",
      "description": "GPS longitude coordinate (optional)"
     },
     "createdOn": {
      "type": "integer",
      "description": "Creation timestamp (Unix seconds)",
      "readOnly": true
     }
    }
   },
   "skills.Skill": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Skill ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Skill name"
     },
     "order": {
      "type": "integer",
      "description": "Display order within the school",
      "readOnly": true
     },
     "rankCount": {
      "type": "integer",
      "description": "Number of ranks this skill is assigned to",
      "readOnly": true
     }
    }
   },
   "styles.Style": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Style ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Style name"
     },
     "rankNoun": {
      "type": "string",
      "description": "Custom noun for ranks (can be null)"
     },
     "rankCount": {
      "type": "integer",
      "description": "Number of ranks in this style",
      "readOnly": true
     },
     "studentCount": {
      "type": "integer",
      "description": "Number of students with ranks in this style",
      "readOnly": true
     }
    }
   },
   "styles.StyleWithRanks": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "name": {
      "type": "string"
     },
     "rankNoun": {
      "type": "string",
      "description": "Can be null"
     },
     "rankCount": {
      "type": "integer",
      "readOnly": true
     },
     "studentCount": {
      "type": "integer",
      "readOnly": true
     },
     "ranks": {
      "type": "array",
      "description": "Ordered list of ranks",
      "items": {
       "$ref": "#/components/schemas/styles.Rank"
      }
     }
    }
   },
   "styles.Rank": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Rank ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Rank name"
     },
     "color": {
      "type": "string",
      "description": "Primary color (hex without #)"
     },
     "colorAlt": {
      "type": "string",
      "description": "Secondary color for gradient (can be null)"
     },
     "stripes": {
      "type": "integer",
      "description": "Number of stripes (0-9)"
     },
     "stripeColor": {
      "type": "string",
      "description": "Stripe color (hex without #, can be null)"
     },
     "numCheckins": {
      "type": "integer",
      "description": "Required attendance for grading (can be null)"
     },
     "numDays": {
      "type": "integer",
      "description": "Required days at rank for grading (can be null)"
     },
     "operator": {
      "type": "string",
      "description": "How to combine grading requirements",
      "enum": [
       "OR",
       "AND"
      ]
     },
     "order": {
      "type": "integer",
      "description": "Display order",
      "readOnly": true
     },
     "studentCount": {
      "type": "integer",
      "description": "Students at this rank",
      "readOnly": true
     },
     "skills": {
      "type": "array",
      "description": "Skills required for this rank",
      "items": {
       "$ref": "#/components/schemas/styles.SkillRef"
      }
     }
    }
   },
   "styles.RankInput": {
    "type": "object",
    "properties": {
     "name": {
      "type": "string"
     },
     "color": {
      "type": "string"
     },
     "colorAlt": {
      "type": "string",
      "description": "Can be null"
     },
     "stripes": {
      "type": "integer",
      "default": 0
     },
     "stripeColor": {
      "type": "string",
      "description": "Can be null"
     },
     "numCheckins": {
      "type": "integer",
      "description": "Can be null"
     },
     "numDays": {
      "type": "integer",
      "description": "Can be null"
     },
     "operator": {
      "type": "string",
      "enum": [
       "OR",
       "AND"
      ],
      "default": "OR"
     },
     "skillIds": {
      "type": "array",
      "default": [],
      "items": {
       "type": "integer"
      }
     }
    },
    "required": [
     "name",
     "color"
    ]
   },
   "styles.SkillRef": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Skill ID"
     },
     "name": {
      "type": "string",
      "description": "Skill name"
     }
    }
   },
   "styles.TemplatesResponse": {
    "type": "object",
    "properties": {
     "templates": {
      "type": "array",
      "description": "Available style templates",
      "items": {
       "$ref": "#/components/schemas/styles.TemplatePreview"
      }
     },
     "categories": {
      "type": "array",
      "description": "Unique category names for filtering",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "styles.TemplatePreview": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Template ID for use in create"
     },
     "name": {
      "type": "string",
      "description": "Template display name"
     },
     "category": {
      "type": "string",
      "description": "Category (e.g., 'striking', 'grappling')"
     },
     "origin": {
      "type": "string",
      "description": "Origin country/region (e.g., 'japanese', 'korean')"
     },
     "rankCount": {
      "type": "integer",
      "description": "Number of ranks in template"
     },
     "rankPreview": {
      "type": "array",
      "description": "First 3 rank names for preview",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "waivers.Waiver": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "name": {
      "type": "string"
     },
     "description": {
      "type": "string"
     },
     "category": {
      "type": "string",
      "enum": [
       "waiver",
       "medical",
       "photo_release",
       "membership",
       "behavior",
       "custom"
      ]
     },
     "sourceType": {
      "type": "string",
      "enum": [
       "native",
       "uploaded_pdf"
      ]
     },
     "signingMode": {
      "type": "string",
      "enum": [
       "sequential",
       "parallel"
      ]
     },
     "countersignerRequired": {
      "type": "boolean"
     },
     "required": {
      "type": "boolean"
     },
     "expiryDays": {
      "type": "integer"
     },
     "autoRenew": {
      "type": "boolean"
     },
     "renewalReminderDays": {
      "type": "integer"
     },
     "reminderSchedule": {
      "type": "array",
      "items": {
       "type": "integer"
      }
     },
     "archivedOn": {
      "type": "integer",
      "description": "Unix seconds when archived, or null.",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     },
     "currentVersion": {
      "$ref": "#/components/schemas/waivers.WaiverVersion",
      "description": "Inlined current published version (null if never published)."
     },
     "signatureCounts": {
      "$ref": "#/components/schemas/waivers.SignatureCounts",
      "description": "Only present when ?expand=signatureCounts."
     }
    }
   },
   "waivers.WaiverVersion": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "waiverId": {
      "type": "integer",
      "readOnly": true
     },
     "versionNumber": {
      "type": "integer",
      "readOnly": true
     },
     "bodyHtml": {
      "type": "string",
      "readOnly": true
     },
     "fields": {
      "type": "array",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/waivers.Field"
      }
     },
     "sourcePdfKey": {
      "type": "string",
      "readOnly": true
     },
     "sourcePdfPages": {
      "type": "integer",
      "readOnly": true
     },
     "effectiveFrom": {
      "type": "integer",
      "readOnly": true
     },
     "createdBy": {
      "type": "integer",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     }
    }
   },
   "waivers.WaiverTemplate": {
    "type": "object",
    "properties": {
     "slug": {
      "type": "string",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "readOnly": true
     },
     "category": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "waiver",
       "medical",
       "photo_release",
       "membership",
       "behavior",
       "custom"
      ]
     },
     "description": {
      "type": "string",
      "readOnly": true
     },
     "locale": {
      "type": "string",
      "readOnly": true
     },
     "bodyHtml": {
      "type": "string",
      "readOnly": true
     },
     "fields": {
      "type": "array",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/waivers.Field"
      }
     }
    }
   },
   "waivers.Field": {
    "type": "object",
    "properties": {
     "key": {
      "type": "string",
      "description": "snake_case identifier, unique within the waiver.",
      "pattern": "^[a-z][a-z0-9_]{0,49}$"
     },
     "type": {
      "type": "string",
      "enum": [
       "short_text",
       "long_text",
       "email",
       "phone",
       "date",
       "number",
       "checkbox",
       "checkbox_group",
       "radio",
       "dropdown",
       "signature",
       "initials",
       "file_upload",
       "heading",
       "paragraph",
       "divider"
      ]
     },
     "label": {
      "type": "string"
     },
     "helpText": {
      "type": "string"
     },
     "required": {
      "type": "boolean"
     },
     "signerRole": {
      "type": "string",
      "enum": [
       "student",
       "guardian",
       "witness",
       "countersigner"
      ]
     },
     "prefillFrom": {
      "type": "string",
      "enum": [
       "student.firstname",
       "student.surname",
       "student.fullname",
       "student.dob",
       "student.age",
       "student.email",
       "student.phone",
       "student.address",
       "student.emergency_contact",
       "school.name",
       "school.address",
       "school.phone",
       "school.city",
       "school.state",
       "school.country",
       "school.postcode",
       "today.date"
      ]
     },
     "validation": {
      "type": "object",
      "description": "Per-type validation rules (regex, min/max, length, date bounds)."
     },
     "conditional": {
      "type": "object",
      "description": "Show-if rule referencing another field by key."
     },
     "options": {
      "type": "array",
      "description": "Required for radio/dropdown/checkbox_group.",
      "items": {
       "$ref": "#/components/schemas/waivers.FieldOption"
      }
     },
     "position": {
      "type": "object",
      "description": "Native section/order layout (native sourceType only)."
     },
     "placement": {
      "type": "object",
      "description": "PDF page + normalised [0,1] coords (uploaded_pdf only)."
     }
    }
   },
   "waivers.FieldOption": {
    "type": "object",
    "properties": {
     "value": {
      "type": "string"
     },
     "label": {
      "type": "string"
     }
    }
   },
   "waivers.SignatureCounts": {
    "type": "object",
    "properties": {
     "signed": {
      "type": "integer",
      "readOnly": true
     },
     "pending": {
      "type": "integer",
      "readOnly": true
     },
     "declined": {
      "type": "integer",
      "readOnly": true
     },
     "expired": {
      "type": "integer",
      "readOnly": true
     },
     "voided": {
      "type": "integer",
      "readOnly": true
     }
    }
   },
   "waivers.VoidBulkResult": {
    "type": "object",
    "properties": {
     "resolved": {
      "type": "integer",
      "description": "Candidates matched by the selector, before skip rules.",
      "readOnly": true
     },
     "voided": {
      "type": "integer",
      "description": "How many rows the operation voids. Identical in preview and execute: preview is a promise about the execute, not a report of work already done, so it is safe to show the user as 'this many will be voided'.",
      "readOnly": true
     },
     "skipped": {
      "type": "integer",
      "description": "Candidates skipped as already voided. Equals resolved - voided.",
      "readOnly": true
     },
     "signatures": {
      "type": "array",
      "description": "Per-signature outcome. `voided` marks the rows this operation affects and is the same in both modes; `status` reports actual current state, so it only reads 'voided' after execute. `skipReason` is 'already_voided' or null.",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "waivers.Signature": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "waiverId": {
      "type": "integer",
      "readOnly": true
     },
     "waiverVersionId": {
      "type": "integer",
      "description": "Version the signer saw. Null on legacy rows that pre-date versioning.",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "readOnly": true
     },
     "signerRole": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "student",
       "guardian",
       "witness",
       "countersigner"
      ]
     },
     "signerName": {
      "type": "string",
      "readOnly": true
     },
     "signerEmail": {
      "type": "string",
      "readOnly": true
     },
     "signerRelationship": {
      "type": "string",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "description": "Derived for legacy rows from signedOn/deletedOn/expiresOn; explicit for new rows.",
      "readOnly": true,
      "enum": [
       "pending",
       "viewed",
       "signed",
       "declined",
       "expired",
       "cancelled",
       "voided"
      ]
     },
     "signatureImageKey": {
      "type": "string",
      "description": "Storage key for the rendered signature image.",
      "readOnly": true
     },
     "fieldResponses": {
      "type": "object",
      "description": "Submitted field values keyed by field key.",
      "readOnly": true
     },
     "requestedOn": {
      "type": "integer",
      "readOnly": true
     },
     "viewedOn": {
      "type": "integer",
      "readOnly": true
     },
     "signedOn": {
      "type": "integer",
      "readOnly": true
     },
     "declinedOn": {
      "type": "integer",
      "readOnly": true
     },
     "expiresOn": {
      "type": "integer",
      "readOnly": true
     },
     "declineReason": {
      "type": "string",
      "readOnly": true
     },
     "voidReason": {
      "type": "string",
      "description": "Reason given when the signature was voided. Null on rows voided before this was stored.",
      "readOnly": true
     },
     "voidedBy": {
      "type": "integer",
      "description": "User id of the admin who voided the signature.",
      "readOnly": true
     },
     "ipAddress": {
      "type": "string",
      "readOnly": true
     },
     "userAgent": {
      "type": "string",
      "readOnly": true
     },
     "geoCountry": {
      "type": "string",
      "readOnly": true
     },
     "requestTokenJti": {
      "type": "string",
      "description": "JWT id of the signing-link token. Bound to this row.",
      "readOnly": true
     },
     "auditHash": {
      "type": "string",
      "description": "SHA-256 over canonicalised audit payload.",
      "readOnly": true
     },
     "parentSignatureId": {
      "type": "integer",
      "description": "Countersigner link to the primary signature row.",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     },
     "deletedOn": {
      "type": "integer",
      "readOnly": true
     }
    }
   },
   "waivers.SourcePdfPresignResult": {
    "type": "object",
    "properties": {
     "uploadUrl": {
      "type": "string",
      "description": "Short-lived presigned PUT URL. Send the PDF body to this URL with Content-Type: application/pdf.",
      "readOnly": true
     },
     "storageKey": {
      "type": "string",
      "description": "Opaque server-allocated storage key. Pass to /confirm, then use as `sourcePdfKey` on the publish-version call.",
      "readOnly": true
     }
    }
   },
   "waivers.SourcePdfConfirmResult": {
    "type": "object",
    "properties": {
     "storageKey": {
      "type": "string",
      "readOnly": true
     },
     "downloadUrl": {
      "type": "string",
      "description": "Short-lived presigned GET URL. Used by the authoring UI's preview pane.",
      "readOnly": true
     },
     "pageCount": {
      "type": "number",
      "description": "Page count derived server-side from the uploaded PDF. Present on /confirm responses only: the /download re-issue path omits it.",
      "readOnly": true
     }
    }
   },
   "waivers.ResponseSearchHit": {
    "type": "object",
    "properties": {
     "signatureId": {
      "type": "integer",
      "readOnly": true
     },
     "waiverId": {
      "type": "integer",
      "readOnly": true
     },
     "waiverName": {
      "type": "string",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "first + surname concatenation; may be null on detached rows.",
      "readOnly": true
     },
     "signerName": {
      "type": "string",
      "description": "Signer-supplied name; may differ from student name.",
      "readOnly": true
     },
     "signedOn": {
      "type": "integer",
      "readOnly": true
     },
     "fieldKey": {
      "type": "string",
      "readOnly": true
     },
     "fieldLabel": {
      "type": "string",
      "readOnly": true
     },
     "fieldType": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "short_text",
       "long_text",
       "email",
       "phone",
       "date",
       "number",
       "checkbox",
       "checkbox_group",
       "radio",
       "dropdown",
       "signature",
       "initials",
       "file_upload",
       "heading",
       "paragraph",
       "divider"
      ]
     },
     "valueText": {
      "type": "string",
      "description": "Populated for text-shaped fields (also carries the ISO date string for date fields).",
      "readOnly": true
     },
     "valueDate": {
      "type": "string",
      "description": "YYYY-MM-DD, populated for date fields.",
      "readOnly": true,
      "format": "date"
     },
     "valueNumber": {
      "type": "string",
      "description": "Stringified DECIMAL(20,4), populated for number fields.",
      "readOnly": true
     }
    }
   },
   "certificates.CertTemplate": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "schoolId": {
      "type": "number"
     },
     "name": {
      "type": "string"
     },
     "baseTemplateId": {
      "type": "string"
     },
     "primaryColor": {
      "type": "string",
      "format": "hex"
     },
     "secondaryColor": {
      "type": "string",
      "format": "hex"
     },
     "citationText": {
      "type": "string"
     },
     "instructor1UserId": {
      "type": "number"
     },
     "instructor2UserId": {
      "type": "number"
     },
     "showSecondSig": {
      "type": "boolean"
     },
     "segmentFilterId": {
      "type": "number"
     },
     "isDefault": {
      "type": "boolean"
     }
    }
   },
   "certificates.CertRenderResponse": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "enum": [
       "success",
       "cached",
       "error",
       "pending"
      ]
     },
     "storageKey": {
      "type": "string"
     },
     "downloadUrl": {
      "type": "string"
     }
    }
   },
   "study.CurriculumItem": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer"
     },
     "schoolId": {
      "type": "integer"
     },
     "rankId": {
      "type": "integer"
     },
     "title": {
      "type": "string"
     },
     "url": {
      "type": "string",
      "description": "External link (null when item is a file)."
     },
     "mimeType": {
      "type": "string",
      "description": "Set when item is a file."
     },
     "hasFile": {
      "type": "boolean"
     },
     "thumbnailUrl": {
      "type": "string",
      "description": "Short-lived signed URL for an image preview (image MIMEs only; null for PDFs / links / empty). ~15min TTL."
     },
     "order": {
      "type": "integer"
     },
     "clicks": {
      "type": "integer"
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix seconds."
     }
    }
   },
   "study.RankGroup": {
    "type": "object",
    "properties": {
     "rankId": {
      "type": "integer"
     },
     "rankName": {
      "type": "string"
     },
     "color": {
      "type": "string"
     },
     "colorAlt": {
      "type": "string"
     },
     "stripes": {
      "type": "integer"
     },
     "stripeColor": {
      "type": "string"
     },
     "items": {
      "type": "array",
      "description": "CurriculumItem[]",
      "items": {}
     }
    }
   },
   "events.PlaceOpen": {
    "type": "object",
    "properties": {
     "eventId": {
      "type": "integer"
     },
     "eventName": {
      "type": "string"
     },
     "date": {
      "type": "string",
      "format": "date"
     },
     "startTime": {
      "type": "string",
      "description": "HH:MM, or null"
     },
     "capacity": {
      "type": "integer"
     },
     "placesFree": {
      "type": "integer",
      "description": "Places free now; 0 when the class is full"
     },
     "waiver": {
      "type": "object",
      "description": "{ id, name } of the class's waiver, or null"
     },
     "queue": {
      "type": "array",
      "description": "In queue order: { waitlistId, studentId, name, email, position, blocked: 'waiver' | 'rostered' | null }",
      "items": {}
     }
    }
   },
   "events.EventWaiverCheck": {
    "type": "object",
    "properties": {
     "waiver": {
      "type": "object",
      "description": "{ id, name } of the event's waiver, or null when it needs none"
     },
     "missing": {
      "type": "array",
      "description": "Student ids without a current signature for it",
      "items": {
       "description": "integer"
      }
     }
    }
   },
   "events.InviteCandidate": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer",
      "description": "Student ID"
     },
     "firstName": {
      "type": "string",
      "description": "First name"
     },
     "lastName": {
      "type": "string",
      "description": "Last name"
     },
     "rank": {
      "type": "object",
      "description": "Rank in the class's style (name, colour, belt tip, stripes), or null"
     },
     "state": {
      "type": "string",
      "description": "Where the student stands for this occurrence",
      "enum": [
       "open",
       "booked",
       "rostered",
       "invited",
       "declined",
       "no_email"
      ]
     },
     "invitedOn": {
      "type": "integer",
      "description": "Unix seconds the invitation was sent, or null"
     },
     "declinedOn": {
      "type": "integer",
      "description": "Unix seconds they said no, or null"
     }
    }
   },
   "events.InviteResult": {
    "type": "object",
    "properties": {
     "invited": {
      "type": "array",
      "description": "{ studentId, bookingId } for each invitation written",
      "items": {}
     },
     "skipped": {
      "type": "array",
      "description": "{ studentId, reason } for each student not invited, or invited but not emailed (email_not_sent)",
      "items": {}
     }
    }
   },
   "events.EventSummary": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Event ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Event name"
     },
     "type": {
      "type": "string",
      "enum": [
       "single",
       "recurring"
      ]
     },
     "venueId": {
      "type": "integer",
      "description": "Venue ID"
     },
     "venueOverride": {
      "type": "string",
      "description": "Off-site venue label, when the class is not at a school venue; venueAddress to venueLng carry its address and position"
     },
     "venueName": {
      "type": "string",
      "description": "Venue name"
     },
     "startTime": {
      "type": [
       "string",
       "null"
      ],
      "description": "Start time, HH:MM",
      "format": "time"
     },
     "endTime": {
      "type": [
       "string",
       "null"
      ],
      "description": "End time, HH:MM",
      "format": "time"
     },
     "startDate": {
      "type": [
       "string",
       "null"
      ],
      "description": "First date, YYYY-MM-DD (a one-off event's date)",
      "format": "date"
     },
     "endDate": {
      "type": [
       "string",
       "null"
      ],
      "description": "Last date of a recurring class, YYYY-MM-DD; null while open-ended",
      "format": "date"
     },
     "isGrading": {
      "type": "boolean",
      "description": "A grading day"
     },
     "days": {
      "type": "integer",
      "description": "Days bitmask for recurring"
     },
     "capacity": {
      "type": "integer",
      "description": "Maximum capacity"
     },
     "price": {
      "type": "integer",
      "description": "Price in cents"
     },
     "visibility": {
      "type": "integer",
      "description": "Visibility bitmask"
     },
     "allowDropins": {
      "type": "boolean",
      "description": "Allows drop-in bookings"
     }
    }
   },
   "events.ClassNeedingStyle": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Event ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Event name"
     },
     "type": {
      "type": "string",
      "enum": [
       "single",
       "recurring"
      ]
     },
     "days": {
      "type": "integer",
      "description": "Days bitmask for a recurring class"
     },
     "startDate": {
      "type": [
       "string",
       "null"
      ],
      "description": "First date, YYYY-MM-DD (a one-off event's date)",
      "format": "date"
     },
     "startTime": {
      "type": [
       "string",
       "null"
      ],
      "description": "Start time, HH:MM",
      "format": "time"
     },
     "endTime": {
      "type": [
       "string",
       "null"
      ],
      "description": "End time, HH:MM",
      "format": "time"
     }
    }
   },
   "events.EventDetail": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Event ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Event name"
     },
     "description": {
      "type": "string",
      "description": "Event description"
     },
     "type": {
      "type": "string",
      "enum": [
       "single",
       "recurring"
      ]
     },
     "days": {
      "type": "integer",
      "description": "Days bitmask"
     },
     "startTime": {
      "type": [
       "string",
       "null"
      ],
      "description": "Start time, HH:MM",
      "format": "time"
     },
     "endTime": {
      "type": [
       "string",
       "null"
      ],
      "description": "End time, HH:MM",
      "format": "time"
     },
     "startDate": {
      "type": [
       "string",
       "null"
      ],
      "description": "First date, YYYY-MM-DD (a one-off event's date)",
      "format": "date"
     },
     "endDate": {
      "type": [
       "string",
       "null"
      ],
      "description": "Last date of a recurring class, YYYY-MM-DD; null while open-ended",
      "format": "date"
     },
     "venueId": {
      "type": "integer",
      "description": "Venue ID"
     },
     "venueOverride": {
      "type": [
       "string",
       "null"
      ],
      "description": "Off-site venue label, when the class is not at a school venue; venueAddress to venueLng carry its address and position"
     },
     "venueAddress": {
      "type": [
       "string",
       "null"
      ],
      "description": "Off-site street address"
     },
     "venueSuburb": {
      "type": [
       "string",
       "null"
      ]
     },
     "venueState": {
      "type": [
       "string",
       "null"
      ]
     },
     "venuePostcode": {
      "type": [
       "string",
       "null"
      ]
     },
     "venueCountry": {
      "type": [
       "string",
       "null"
      ]
     },
     "venueLat": {
      "type": [
       "number",
       "null"
      ]
     },
     "venueLng": {
      "type": [
       "number",
       "null"
      ]
     },
     "venueName": {
      "type": [
       "string",
       "null"
      ],
      "description": "Venue name"
     },
     "meetingUrl": {
      "type": [
       "string",
       "null"
      ],
      "description": "Virtual meeting link"
     },
     "capacity": {
      "type": "integer",
      "description": "Maximum capacity"
     },
     "minAge": {
      "type": "integer",
      "description": "Age range on the class's day, inclusive; null = open"
     },
     "maxAge": {
      "type": "integer",
      "description": "Age range on the class's day, inclusive; null = open"
     },
     "openToAllStudents": {
      "type": "boolean",
      "description": "Every Active Student and Trial is on its check-in roster"
     },
     "price": {
      "type": "integer",
      "description": "Price in cents"
     },
     "allowDropins": {
      "type": "boolean",
      "description": "Allows drop-in bookings"
     },
     "selfEnrollable": {
      "type": "boolean",
      "description": "Stored flag with no effect: students do not enrol themselves"
     },
     "visibility": {
      "type": "integer",
      "description": "Visibility bitmask"
     },
     "noShowFee": {
      "type": "integer",
      "description": "No-show fee in cents"
     },
     "noShowConsumesPass": {
      "type": "boolean",
      "description": "No-show uses pass"
     },
     "notifications": {
      "type": "boolean",
      "description": "Notifications enabled"
     },
     "waiverId": {
      "type": "integer",
      "description": "Required waiver ID"
     },
     "createdOn": {
      "type": "integer",
      "description": "Creation timestamp",
      "readOnly": true
     },
     "enrollmentCount": {
      "type": "integer",
      "description": "Students enrolled in roster",
      "readOnly": true
     },
     "bookingCount": {
      "type": "integer",
      "description": "Upcoming drop-in bookings",
      "readOnly": true
     },
     "isGrading": {
      "type": "boolean",
      "description": "A grading day"
     },
     "trialEligible": {
      "type": "boolean",
      "description": "Leads and students on trial are offered this class"
     },
     "allStyles": {
      "type": "boolean",
      "description": "A whole-school class, for every style"
     },
     "styles": {
      "type": "array",
      "description": "The styles the class is for: { styleId, styleName }",
      "readOnly": true,
      "items": {}
     },
     "needsStyle": {
      "type": "boolean",
      "description": "True for a class saved before every class had a style, until its owner picks one",
      "readOnly": true
     },
     "ranks": {
      "type": "array",
      "description": "The ranks the event is open to: { rankId, rankName, color, styleId, styleName }",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "events.Booking": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Booking ID",
      "readOnly": true
     },
     "eventId": {
      "type": "integer",
      "description": "Event ID"
     },
     "eventName": {
      "type": "string",
      "description": "Event name"
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID"
     },
     "studentName": {
      "type": "string",
      "description": "Student full name"
     },
     "eventDate": {
      "type": "string",
      "description": "Occurrence date, YYYY-MM-DD",
      "format": "date"
     },
     "status": {
      "type": "string",
      "description": "reserved = live unconfirmed seat hold from the student app or widget; expired = that hold lapsed unconfirmed",
      "enum": [
       "pending",
       "reserved",
       "expired",
       "confirmed",
       "attended",
       "cancelled",
       "no_show"
      ]
     },
     "paidOn": {
      "type": "integer",
      "description": "Payment timestamp"
     },
     "transactionId": {
      "type": "integer",
      "description": "Associated transaction ID"
     }
    }
   },
   "events.BookingResult": {
    "type": "object",
    "properties": {
     "booking": {
      "type": "object",
      "description": "Created booking object"
     }
    }
   },
   "events.Enrollment": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Enrollment ID",
      "readOnly": true
     },
     "eventId": {
      "type": "integer",
      "description": "Event ID"
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID"
     },
     "studentName": {
      "type": "string",
      "description": "Student full name"
     },
     "enrolledOn": {
      "type": "integer",
      "description": "Enrollment timestamp",
      "readOnly": true
     },
     "enrolledByName": {
      "type": "string",
      "description": "Staff who enrolled the student",
      "readOnly": true
     }
    }
   },
   "events.Exception": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Exception ID",
      "readOnly": true
     },
     "eventId": {
      "type": "integer",
      "description": "Event ID"
     },
     "exceptionDate": {
      "type": "string",
      "description": "Occurrence date, YYYY-MM-DD",
      "format": "date"
     },
     "cancelled": {
      "type": "boolean",
      "description": "Whether this occurrence is cancelled"
     },
     "startTime": {
      "type": [
       "string",
       "null"
      ],
      "description": "Override start time, HH:MM",
      "format": "time"
     },
     "endTime": {
      "type": [
       "string",
       "null"
      ],
      "description": "Override end time, HH:MM",
      "format": "time"
     },
     "venueId": {
      "type": "integer",
      "description": "Override venue ID"
     },
     "venueOverride": {
      "type": "string",
      "description": "This date's off-site venue label"
     },
     "notes": {
      "type": "string",
      "description": "Notes for this occurrence"
     },
     "notifySent": {
      "type": "boolean",
      "description": "Whether notification was sent",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "description": "Creation timestamp",
      "readOnly": true
     },
     "createdBy": {
      "type": "integer",
      "description": "User who created the exception",
      "readOnly": true
     },
     "cancelledBookings": {
      "type": "array",
      "description": "While cancelled: the bookings this date's cancellation cancelled, which un-cancelling can put back",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/events.RestorableBooking"
      }
     },
     "reinstated": {
      "type": [
       "object",
       "null"
      ],
      "description": "On an un-cancel's answer: how many bookings were put back (restored) and how many members were emailed (notified)",
      "readOnly": true
     }
    }
   },
   "events.RestorableBooking": {
    "type": "object",
    "properties": {
     "bookingId": {
      "type": "integer",
      "description": "Booking ID"
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID"
     },
     "studentName": {
      "type": "string",
      "description": "Student full name"
     }
    }
   },
   "events.WaitlistEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Waitlist entry ID",
      "readOnly": true
     },
     "eventId": {
      "type": "integer",
      "description": "Event ID"
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID"
     },
     "studentName": {
      "type": "string",
      "description": "Student full name"
     },
     "eventDate": {
      "type": "string",
      "description": "Occurrence date, YYYY-MM-DD",
      "format": "date"
     },
     "addedOn": {
      "type": "integer",
      "description": "When added to waitlist",
      "readOnly": true
     },
     "position": {
      "type": "integer",
      "description": "Position in queue (1 = first)"
     },
     "promotedOn": {
      "type": "integer",
      "description": "When promoted to booking",
      "readOnly": true
     },
     "promotedToBookingId": {
      "type": "integer",
      "description": "Booking ID if promoted",
      "readOnly": true
     },
     "removedOn": {
      "type": "integer",
      "description": "When removed from waitlist",
      "readOnly": true
     }
    }
   },
   "events.PromoteResult": {
    "type": "object",
    "properties": {
     "promoted": {
      "type": "boolean",
      "description": "Whether promotion succeeded"
     },
     "booking": {
      "type": "object",
      "description": "The created booking (BookingSummary)"
     }
    }
   },
   "events.Occurrence": {
    "type": "object",
    "properties": {
     "date": {
      "type": "string",
      "description": "Occurrence date, YYYY-MM-DD",
      "format": "date"
     },
     "startTime": {
      "type": "string",
      "description": "Start time, HH:MM (an exception may override it)",
      "format": "time"
     },
     "endTime": {
      "type": "string",
      "description": "End time, HH:MM",
      "format": "time"
     },
     "cancelled": {
      "type": "boolean",
      "description": "Whether this occurrence is cancelled"
     },
     "hasException": {
      "type": "boolean",
      "description": "Whether an exception overrides this occurrence"
     },
     "venueId": {
      "type": "integer",
      "description": "Venue ID (may be overridden)"
     }
    }
   },
   "events.Attendee": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Student full name",
      "readOnly": true
     },
     "source": {
      "type": "string",
      "description": "How student is attending",
      "readOnly": true,
      "enum": [
       "enrollment",
       "booking"
      ]
     },
     "attendanceStatus": {
      "type": "string",
      "description": "Current attendance status",
      "readOnly": true,
      "enum": [
       "attended",
       "no_show",
       "excused",
       "pending"
      ]
     },
     "rankName": {
      "type": "string",
      "description": "Student's current rank",
      "readOnly": true
     },
     "email": {
      "type": "string",
      "description": "Student email",
      "readOnly": true
     }
    }
   },
   "events.AttendanceMarkResult": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "action": {
      "type": "string",
      "description": "The action recorded",
      "readOnly": true,
      "enum": [
       "attended",
       "no_show",
       "excused",
       "clear"
      ]
     },
     "bookingId": {
      "type": "integer",
      "description": "The booking the mark landed on (made for a rostered member when none stood)",
      "readOnly": true
     },
     "attendanceId": {
      "type": "integer",
      "description": "The attendance row a mark attended wrote",
      "readOnly": true
     },
     "passDeducted": {
      "type": "boolean",
      "description": "A pass was taken from a pass pack",
      "readOnly": true
     },
     "passesRemaining": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Passes left on that pack after this mark",
      "readOnly": true
     },
     "classHasNoStyle": {
      "type": "boolean",
      "description": "The class names no style, so only an unrestricted plan's pass could pay",
      "readOnly": true
     },
     "feeCharged": {
      "type": "boolean",
      "description": "A no-show fee was charged",
      "readOnly": true
     },
     "feeAmount": {
      "type": "number",
      "description": "The no-show fee, in the school's currency units",
      "readOnly": true
     },
     "payg": {
      "type": [
       "object",
       "null"
      ],
      "description": "The pay-as-you-go session this mark charged, if any: { charged, amount, pendingPayment, transactionId, planName, amountOwed?, checking? }",
      "readOnly": true
     },
     "classPriceOwedCents": {
      "type": [
       "integer",
       "null"
      ],
      "description": "The class's own price this mark recorded as owed on the booking it made (or the declined invitation it accepted), in cents, when the member had no live booking for a priced class and their plan does not stand in for it. No session is charged with it. Null otherwise.",
      "readOnly": true
     }
    }
   },
   "events.NoShowCandidate": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Student full name",
      "readOnly": true
     },
     "source": {
      "type": "string",
      "description": "How student was expected",
      "readOnly": true,
      "enum": [
       "enrollment",
       "booking"
      ]
     }
    }
   },
   "events.RepeatNoShow": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Student full name",
      "readOnly": true
     },
     "noShowCount": {
      "type": "integer",
      "description": "Total no-shows in the period",
      "readOnly": true
     },
     "events": {
      "type": "array",
      "description": "Event names where no-shows occurred",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "events.UpcomingEntry": {
    "type": "object",
    "properties": {
     "eventId": {
      "type": "integer",
      "description": "Event ID",
      "readOnly": true
     },
     "eventName": {
      "type": "string",
      "description": "Event name",
      "readOnly": true
     },
     "date": {
      "type": "string",
      "description": "Occurrence date, YYYY-MM-DD",
      "readOnly": true,
      "format": "date"
     },
     "startTime": {
      "type": "string",
      "description": "Start time, HH:MM",
      "readOnly": true,
      "format": "time"
     },
     "endTime": {
      "type": "string",
      "description": "End time, HH:MM",
      "readOnly": true,
      "format": "time"
     },
     "source": {
      "type": "string",
      "description": "Whether from roster or drop-in booking",
      "readOnly": true,
      "enum": [
       "enrollment",
       "booking"
      ]
     },
     "venueName": {
      "type": "string",
      "description": "Venue name",
      "readOnly": true
     }
    }
   },
   "calendar.CalendarView": {
    "type": "object",
    "properties": {
     "view": {
      "type": "string",
      "enum": [
       "day",
       "week",
       "month",
       "agenda"
      ]
     },
     "rangeStart": {
      "type": "integer",
      "description": "Unix timestamp"
     },
     "rangeEnd": {
      "type": "integer",
      "description": "Unix timestamp"
     },
     "occurrences": {
      "type": "array",
      "description": "Expanded event occurrences",
      "items": {
       "$ref": "#/components/schemas/calendar.CalendarOccurrence"
      }
     }
    }
   },
   "calendar.CalendarOccurrence": {
    "type": "object",
    "properties": {
     "eventId": {
      "type": "integer",
      "description": "Source event ID"
     },
     "eventName": {
      "type": "string"
     },
     "eventType": {
      "type": "string",
      "enum": [
       "single",
       "recurring"
      ]
     },
     "date": {
      "type": "integer",
      "description": "Occurrence date (midnight timestamp)"
     },
     "startTime": {
      "type": "integer",
      "description": "Full start timestamp"
     },
     "endTime": {
      "type": "integer",
      "description": "Full end timestamp"
     },
     "venueId": {
      "type": "integer",
      "description": "Venue ID (may differ from event if overridden)"
     },
     "venueName": {
      "type": "string"
     },
     "meetingUrl": {
      "type": "string",
      "description": "Virtual class link"
     },
     "capacity": {
      "type": "integer",
      "description": "Max capacity"
     },
     "price": {
      "type": "integer",
      "description": "The class's own price in cents, as the bookings widget quotes it (null or 0 = free)"
     },
     "enrolledCount": {
      "type": "integer",
      "description": "Students in roster"
     },
     "bookedCount": {
      "type": "integer",
      "description": "Drop-in bookings for this occurrence"
     },
     "availableSpots": {
      "type": "integer",
      "description": "Remaining capacity (null = unlimited)"
     },
     "isCancelled": {
      "type": "boolean",
      "description": "True if this occurrence is cancelled"
     },
     "needsStyle": {
      "type": "boolean",
      "description": "True while the class has no style and is not a whole-school class: its owner has not said who it is for"
     },
     "exception": {
      "type": "object",
      "description": "Exception details if this occurrence has overrides"
     }
    }
   },
   "billing.SubscriptionPaymentMethod": {
    "type": "object",
    "properties": {
     "subscriptionId": {
      "type": "integer"
     },
     "paymentMethodId": {
      "type": "string",
      "description": "The subscription's own card (pm_...) when one was picked or pinned; null means the customer's default card is charged"
     },
     "pinned": {
      "type": "boolean",
      "description": "True when a later change of the customer's default leaves this subscription on its card"
     }
    }
   },
   "billing.AssignmentAuthentication": {
    "type": "object",
    "properties": {
     "publishableKey": {
      "type": "string",
      "description": "Stripe.js key for the school's connected account"
     },
     "stripeAccountId": {
      "type": "string",
      "description": "The connected account (acct_...) Stripe.js must be loaded with"
     },
     "resume": {
      "type": "boolean",
      "description": "True when the assignment stopped before the subscription (a pro-rata first period must land first): confirm the intents, then POST the same body again with completedPaymentIntents naming them. False: the webhooks settle everything once the intents are confirmed."
     },
     "actions": {
      "type": "array",
      "description": "Each charge the member must authenticate, in order: { purpose (first_period | subscription | setup_fee | plan), paymentIntentId, clientSecret, paymentMethodId (confirm with this card: Stripe detaches it from an intent refused off-session), amountCents, description }",
      "items": {}
     }
    }
   },
   "billing.PlanFilterOptions": {
    "type": "object",
    "properties": {
     "types": {
      "type": "array",
      "description": "Available plan types: recurring, passes, one_time",
      "items": {}
     },
     "billingPeriods": {
      "type": "array",
      "description": "Available billing periods: week, month, year",
      "items": {}
     },
     "styles": {
      "type": "array",
      "description": "School's martial arts styles ({ id, name }) for the styleId filter",
      "items": {}
     }
    }
   },
   "billing.BillingPlan": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Plan ID",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "description": "School ID (from JWT)",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Plan name"
     },
     "type": {
      "type": "string",
      "description": "Plan type",
      "enum": [
       "recurring",
       "passes",
       "one_time",
       "payg"
      ]
     },
     "amount": {
      "type": "integer",
      "description": "Amount in cents"
     },
     "billingPeriod": {
      "type": "string",
      "description": "Billing period (recurring only)",
      "enum": [
       "week",
       "month",
       "year"
      ]
     },
     "billingInterval": {
      "type": "integer",
      "description": "Billing interval multiplier"
     },
     "attendanceFrequency": {
      "type": "integer",
      "description": "Max attendance per period (null = unlimited)"
     },
     "attendancePeriod": {
      "type": "string",
      "description": "Attendance period unit"
     },
     "quantity": {
      "type": "integer",
      "description": "Total passes (passes plans only)"
     },
     "expiryDuration": {
      "type": "integer",
      "description": "Expiry duration"
     },
     "expiryPeriod": {
      "type": "string",
      "description": "Expiry period unit"
     },
     "paygAmountPerSession": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Price per class in cents (payg plans only)"
     },
     "chargeTrigger": {
      "type": [
       "string",
       "null"
      ],
      "description": "When a payg plan charges a class: always attendance (check-in). Null on other plan types.",
      "enum": [
       "attendance"
      ]
     },
     "styleIds": {
      "type": "array",
      "description": "Associated style IDs",
      "readOnly": true,
      "items": {
       "type": "integer"
      }
     },
     "subscriberCount": {
      "type": "integer",
      "description": "Number of active subscribers",
      "readOnly": true
     },
     "gatewayLinked": {
      "type": "boolean",
      "description": "Whether plan type routes to a payment gateway (Stripe/GoCardless)",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "description": "Creation date (Unix seconds)",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "deletedOn": {
      "type": "integer",
      "description": "Archive date (null if active)",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "billing.Subscription": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Subscription ID",
      "readOnly": true
     },
     "planId": {
      "type": "integer",
      "description": "Associated billing plan ID"
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID"
     },
     "familyId": {
      "type": "integer",
      "description": "Family ID if billing through a family member (null for direct)"
     },
     "shopOrderId": {
      "type": "integer",
      "description": "Shop order this transaction settled (GET /v1/shop/orders/:id). Null when not a shop payment."
     },
     "externalId": {
      "type": "string",
      "description": "Gateway subscription ID (Stripe sub_xxx, GoCardless SB_xxx). Null for local/draft.",
      "readOnly": true
     },
     "type": {
      "type": "string",
      "description": "Subscription type: Stripe, GoCardless, Local, or an offline method (Cash, Cheque, Credit Card, Direct Debit, Standing Order)"
     },
     "status": {
      "type": "string",
      "description": "Computed status: the billing card's rule. confirming_payment = the gateway did not answer for the plan's charge at assignment, so the plan waits and nothing can be used on it until a check hears what happened (checkPlanPayment). A GoCardless plan's comes from GoCardless (mandate, subscription, each debit), never a period count; syncing = facts not fetched yet.",
      "readOnly": true,
      "enum": [
       "draft",
       "active",
       "paused",
       "overdue",
       "cancelled",
       "expired",
       "upcoming",
       "0-passes",
       "trial",
       "syncing",
       "awaiting_authentication",
       "confirming_payment"
      ]
     },
     "gatewayStatus": {
      "type": "string",
      "description": "the gateway subscription's own state (Stripe status, or the GoCardless subscription's). Null until fetched.",
      "readOnly": true
     },
     "mandateStatus": {
      "type": "string",
      "description": "GoCardless only, the mandate's state (failed/cancelled/expired/suspended_by_payer/blocked read overdue). Null until fetched.",
      "readOnly": true
     },
     "nextPaymentOn": {
      "type": "integer",
      "description": "unix seconds of the next charge day the gateway reported. Null until fetched.",
      "readOnly": true
     },
     "overdueAmountCents": {
      "type": "integer",
      "description": "what the status rule says is owed, in cents; 0 unless overdue.",
      "readOnly": true
     },
     "discount": {
      "type": "number",
      "description": "Discount value (percentage 0-100 or fixed amount in cents)"
     },
     "discountType": {
      "type": "integer",
      "description": "0 = percentage (10 = 10% off), 1 = fixed amount in cents (1500 = $15.00 off; 15 is fifteen cents).",
      "enum": [
       0,
       1
      ]
     },
     "automaticTxns": {
      "type": "boolean",
      "description": "Whether payments are recorded without anyone entering them: always true for a Stripe or GoCardless plan (the gateway's renewals), and for an offline recurring plan only when Automatic Transaction Recording is on. Set it with automaticRecording on assign or update."
     },
     "emailReceipt": {
      "type": "boolean",
      "description": "Whether a receipt is emailed when a payment on this plan is collected by card or Direct Debit. Set it with emailReceipt on assign or update."
     },
     "passesRemaining": {
      "type": "integer",
      "description": "Remaining passes (passes plans only)"
     },
     "startOn": {
      "type": "integer",
      "description": "Subscription start date",
      "format": "unix-seconds"
     },
     "endOn": {
      "type": "integer",
      "description": "Subscription end date (null = no end)",
      "format": "unix-seconds"
     },
     "pausedOn": {
      "type": "integer",
      "description": "When the subscription was paused (null if not paused)",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "cancelledOn": {
      "type": "integer",
      "description": "When the subscription was cancelled (null if active)",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "cancelAtPeriodEnd": {
      "type": "boolean",
      "description": "Whether the subscription has a pending deferred cancellation (atPeriodEnd or cancelAt)",
      "readOnly": true
     },
     "scheduledCancelDate": {
      "type": "integer",
      "description": "The scheduled cancellation date (null if no pending cancel). Present for both atPeriodEnd and cancelAt.",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "plan": {
      "type": "object",
      "description": "Associated plan details (BillingPlan model, included in detail view)",
      "readOnly": true
     }
    }
   },
   "billing.StudentBillingData": {
    "type": "object",
    "properties": {
     "currency": {
      "type": "object",
      "description": "School currency info (code and symbol)",
      "readOnly": true
     },
     "plans": {
      "type": "array",
      "description": "Student's active subscriptions/plans",
      "readOnly": true,
      "items": {
       "description": "StudentPlan"
      }
     },
     "transactions": {
      "type": "array",
      "description": "Recent transactions",
      "readOnly": true,
      "items": {
       "description": "StudentTransaction"
      }
     }
    }
   },
   "billing.Transaction": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Transaction ID",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID (nullable)"
     },
     "subscriptionId": {
      "type": "integer",
      "description": "Subscription ID (nullable)"
     },
     "paymentMethod": {
      "type": "string",
      "description": "Payment method (Stripe, GoCardless, Cash, Cheque, Credit Card, Direct Debit, Standing Order)"
     },
     "amount": {
      "type": "integer",
      "description": "Amount in cents (negative for refunds)"
     },
     "description": {
      "type": "string"
     },
     "taxAmount": {
      "type": "integer",
      "description": "Tax amount in cents"
     },
     "status": {
      "type": "string",
      "description": "Semantic transaction status",
      "enum": [
       "pending",
       "submitted",
       "successful",
       "failed",
       "retrying",
       "cancelled"
      ]
     },
     "automatic": {
      "type": "boolean",
      "description": "Whether this was an automatic charge"
     },
     "gateway": {
      "type": "string",
      "description": "Detected gateway from metadata",
      "enum": [
       "stripe",
       "gocardless",
       "local"
      ]
     },
     "createdOn": {
      "type": "integer",
      "format": "unix-seconds"
     },
     "failedOn": {
      "type": "integer",
      "format": "unix-seconds"
     },
     "retriedOn": {
      "type": "integer",
      "format": "unix-seconds"
     },
     "refundedOn": {
      "type": "integer",
      "format": "unix-seconds"
     }
    }
   },
   "billing.Invoice": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Stripe invoice ID (in_...)",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "description": "Invoice lifecycle state. Actions depend on state: a draft can be finalized or voided, an open invoice sent or voided; a paid invoice is refunded through its payment",
      "enum": [
       "draft",
       "open",
       "paid",
       "void",
       "uncollectible"
      ]
     },
     "amountDue": {
      "type": "integer",
      "description": "Total amount due in cents"
     },
     "amountPaid": {
      "type": "integer",
      "description": "Amount already paid in cents"
     },
     "hostedInvoiceUrl": {
      "type": "string",
      "description": "Stripe-hosted payment page URL"
     },
     "invoicePdf": {
      "type": "string",
      "description": "PDF download URL"
     },
     "dueDate": {
      "type": "integer",
      "description": "Due date (null for draft)",
      "format": "unix-seconds"
     },
     "createdAt": {
      "type": "integer",
      "format": "unix-seconds"
     }
    }
   },
   "billing.ManualPayment": {
    "type": "object",
    "properties": {
     "transactionId": {
      "type": "integer",
      "description": "Created transaction ID",
      "readOnly": true
     }
    }
   },
   "billing.PaymentRequest": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "gateway": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "stripe",
       "gocardless"
      ]
     },
     "channel": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "email",
       "sms",
       "link"
      ]
     },
     "sentOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "openedOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "completedOn": {
      "type": "integer",
      "description": "When a usable card or mandate was first seen after the member used the link",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "expiresOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "status": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "sent",
       "opened",
       "completed",
       "expired"
      ]
     }
    }
   },
   "billing.PaymentRequestLink": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "gateway": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "stripe",
       "gocardless"
      ]
     },
     "channel": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "link"
      ]
     },
     "sentOn": {
      "type": "integer",
      "description": "When the link was first made",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "openedOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "completedOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "expiresOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "status": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "sent",
       "opened",
       "completed",
       "expired"
      ]
     },
     "url": {
      "type": "string",
      "description": "The member's public payment-details page",
      "readOnly": true
     }
    }
   },
   "billing.SetupSession": {
    "type": "object",
    "properties": {
     "url": {
      "type": "string",
      "description": "Redirect URL for the student to enter payment details",
      "readOnly": true
     },
     "gateway": {
      "type": "string",
      "description": "Which gateway the setup session was created on",
      "readOnly": true,
      "enum": [
       "stripe",
       "gocardless"
      ]
     }
    }
   },
   "billing.PortalSession": {
    "type": "object",
    "properties": {
     "url": {
      "type": "string",
      "description": "Stripe Billing Portal session URL",
      "readOnly": true
     }
    }
   },
   "billing.PlanPriceVersion": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Version record ID",
      "readOnly": true
     },
     "planId": {
      "type": "integer",
      "description": "Billing plan ID",
      "readOnly": true
     },
     "previousAmount": {
      "type": "integer",
      "description": "Previous price in cents",
      "readOnly": true
     },
     "newAmount": {
      "type": "integer",
      "description": "New price in cents",
      "readOnly": true
     },
     "cascadeStrategy": {
      "type": "string",
      "description": "Strategy used for existing subscribers",
      "readOnly": true,
      "enum": [
       "grandfather",
       "migrate_now",
       "migrate_at_renewal"
      ]
     },
     "status": {
      "type": "string",
      "description": "Migration status. 'migrating' = migration in progress, 'completed' = done",
      "readOnly": true,
      "enum": [
       "migrating",
       "completed"
      ]
     },
     "migratedCount": {
      "type": "integer",
      "description": "Number of subscriptions successfully migrated",
      "readOnly": true
     },
     "totalToMigrate": {
      "type": "integer",
      "description": "Total subscriptions to migrate",
      "readOnly": true
     },
     "version": {
      "type": "integer",
      "description": "Sequential version number for this plan",
      "readOnly": true
     },
     "createdAt": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "completedAt": {
      "type": "integer",
      "description": "When migration finished (null if pending)",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "billing.PriceUpdateResult": {
    "type": "object",
    "properties": {
     "currentAmount": {
      "type": "integer",
      "description": "Current price in cents"
     },
     "newAmount": {
      "type": "integer",
      "description": "New price in cents"
     },
     "cascade": {
      "type": "string",
      "description": "Cascade strategy applied"
     },
     "affectedSubscriptions": {
      "type": "object",
      "description": "Breakdown of affected subscriptions by gateway: { stripe, gocardless, local }"
     },
     "version": {
      "type": "object",
      "description": "Created version record (on confirm): see PlanPriceVersion model"
     }
    }
   },
   "billing.OverdueResult": {
    "type": "object",
    "properties": {
     "buckets": {
      "type": "array",
      "description": "Overdue subscriptions grouped by aging tier",
      "items": {
       "type": "object",
       "properties": {
        "tier": {
         "type": "string",
         "enum": [
          "7d",
          "14d",
          "30d",
          "60d",
          "90d+"
         ]
        },
        "count": {
         "type": "integer"
        },
        "totalOwedCents": {
         "type": "integer"
        },
        "subscriptions": {
         "type": "array",
         "items": {
          "$ref": "#/components/schemas/billing.OverdueSubscription"
         }
        }
       }
      }
     },
     "totalOverdue": {
      "type": "integer",
      "description": "Total count of overdue subscriptions"
     },
     "totalOwedCents": {
      "type": "integer",
      "description": "Total amount owed across all overdue subscriptions"
     }
    }
   },
   "billing.OverdueSubscription": {
    "type": "object",
    "properties": {
     "subscriptionId": {
      "type": "integer",
      "description": "Subscription ID"
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID"
     },
     "studentName": {
      "type": "string",
      "description": "Student full name"
     },
     "planId": {
      "type": "integer",
      "description": "Billing plan ID"
     },
     "planName": {
      "type": "string",
      "description": "Plan name"
     },
     "gateway": {
      "type": "string",
      "description": "Subscription gateway",
      "enum": [
       "stripe",
       "gocardless",
       "local"
      ]
     },
     "amountOwedCents": {
      "type": "integer",
      "description": "Total overdue amount in cents"
     },
     "daysPastDue": {
      "type": "integer",
      "description": "Days since the oldest missed payment was expected"
     },
     "lastPaymentDate": {
      "type": "integer",
      "description": "Date of last successful payment (null if never paid)",
      "format": "unix-seconds"
     },
     "gatewayFlagged": {
      "type": "boolean",
      "description": "True if the gateway flagged this as failed (gateway subs only)"
     },
     "lastFailure": {
      "type": "object",
      "description": "The latest failed charge on the plan, when there is one newer than the last money in: { transactionId, on (unix seconds), reason (the gateway's words, or null), retrying }. Null when nothing has failed."
     }
    }
   },
   "billing.QueuedOperation": {
    "type": "object",
    "properties": {
     "operationId": {
      "type": "integer",
      "description": "The operation the run became. Follow it through GET /v1/operations/:id: progress, the student being processed, and one result per item as the run goes."
     },
     "label": {
      "type": "string",
      "description": "The run's title, e.g. \"Pausing 3 plans\""
     }
    }
   },
   "billing.BillingCounts": {
    "type": "object",
    "properties": {
     "activeSubscriptions": {
      "type": "integer",
      "description": "Count of active (not paused, not cancelled) subscriptions"
     },
     "pausedSubscriptions": {
      "type": "integer",
      "description": "Count of paused subscriptions"
     },
     "overdueSubscriptions": {
      "type": "integer",
      "description": "Count of overdue subscriptions (local subs with missed payments)"
     },
     "totalMonthlyRevenue": {
      "type": "integer",
      "description": "Monthly Recurring Revenue in cents (normalized from all billing periods)"
     },
     "totalOutstanding": {
      "type": "integer",
      "description": "Total overdue amount in cents"
     },
     "studentsByPlanType": {
      "type": "object",
      "description": "Subscription counts by plan type: { recurring, passes, one_time }"
     },
     "gatewayBreakdown": {
      "type": "object",
      "description": "Subscription counts by gateway: { stripe, gocardless, local }"
     }
    }
   },
   "billing.PaymentMethod": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Payment method ID (Stripe pm_xxx or GoCardless MD_xxx)",
      "readOnly": true
     },
     "gateway": {
      "type": "string",
      "description": "Which payment gateway this method belongs to",
      "readOnly": true,
      "enum": [
       "stripe",
       "gocardless"
      ]
     },
     "type": {
      "type": "string",
      "description": "Payment method type: card (Stripe), bank_debit (GoCardless/SEPA), bank_transfer",
      "readOnly": true,
      "enum": [
       "card",
       "bank_debit",
       "bank_transfer"
      ]
     },
     "isDefault": {
      "type": "boolean",
      "description": "Whether this is the customer's default payment method. GoCardless mandates are always default (one per student).",
      "readOnly": true
     },
     "details": {
      "type": "object",
      "description": "Type-specific details. Cards: brand, last4, expMonth, expYear. Bank: bankName, accountNumberEnding, scheme.",
      "readOnly": true,
      "properties": {
       "brand": {
        "type": "string",
        "description": "Card brand (visa, mastercard, etc.)"
       },
       "last4": {
        "type": "string",
        "description": "Last 4 digits of card number"
       },
       "expMonth": {
        "type": "integer",
        "description": "Card expiry month (1-12)"
       },
       "expYear": {
        "type": "integer",
        "description": "Card expiry year (4-digit)"
       },
       "bankName": {
        "type": "string",
        "description": "Bank name (GoCardless)"
       },
       "accountNumberEnding": {
        "type": "string",
        "description": "Last digits of account number (GoCardless)"
       },
       "scheme": {
        "type": "string",
        "description": "Direct Debit scheme: bacs, sepa_core, autogiro, etc."
       }
      }
     },
     "status": {
      "type": "string",
      "description": "Health status. Cards: expired/expiring_soon (30 days) detected from exp date. GoCardless: mapped from mandate status.",
      "readOnly": true,
      "enum": [
       "active",
       "expiring_soon",
       "expired",
       "cancelled",
       "suspended"
      ]
     },
     "mandateState": {
      "type": "string",
      "description": "Raw GoCardless mandate lifecycle state (e.g. active, pending_submission, suspended_by_payer). Only present for GoCardless mandates.",
      "readOnly": true
     },
     "nextPossibleChargeDate": {
      "type": "string",
      "description": "Earliest date the GoCardless mandate can be charged (ISO date string). Only present for GoCardless mandates.",
      "readOnly": true
     },
     "createdAt": {
      "type": "integer",
      "description": "When the payment method was created (Unix seconds)",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "billing.AnalyticsDashboard": {
    "type": "object",
    "properties": {
     "mrr": {
      "type": "integer",
      "description": "Monthly Recurring Revenue in cents",
      "readOnly": true
     },
     "arr": {
      "type": "integer",
      "description": "Annual Recurring Revenue in cents (MRR × 12)",
      "readOnly": true
     },
     "activeSubscriptions": {
      "type": "integer",
      "readOnly": true
     },
     "newSubscriptionsThisMonth": {
      "type": "integer",
      "readOnly": true
     },
     "churnRate": {
      "type": "number",
      "description": "Churn rate as percentage 0 to 100",
      "readOnly": true
     },
     "churnedThisMonth": {
      "type": "integer",
      "readOnly": true
     },
     "revenueThisMonth": {
      "type": "integer",
      "description": "Actual collected revenue this month in cents",
      "readOnly": true
     },
     "outstandingAmount": {
      "type": "integer",
      "description": "Total overdue amount in cents",
      "readOnly": true
     },
     "averageRevenuePerStudent": {
      "type": "integer",
      "description": "ARPU in cents",
      "readOnly": true
     },
     "paymentMethodBreakdown": {
      "type": "object",
      "description": "Per-gateway breakdown: { stripe: { active, revenue }, gocardless: { active, revenue }, local: { active, revenue } }",
      "readOnly": true
     },
     "revenueByPlanType": {
      "type": "object",
      "description": "Revenue by plan type: { recurring, passes, one_time } in cents",
      "readOnly": true
     }
    }
   },
   "billing.MrrDataPoint": {
    "type": "object",
    "properties": {
     "month": {
      "type": "string",
      "description": "Month in YYYY-MM format",
      "readOnly": true
     },
     "mrr": {
      "type": "integer",
      "description": "MRR at month-end in cents",
      "readOnly": true
     },
     "activeSubscriptions": {
      "type": "integer",
      "description": "Active recurring subscriptions at month-end",
      "readOnly": true
     }
    }
   },
   "billing.ChurnAnalysis": {
    "type": "object",
    "properties": {
     "churnRate": {
      "type": "number",
      "description": "Churn rate as percentage 0 to 100",
      "readOnly": true
     },
     "totalChurned": {
      "type": "integer",
      "readOnly": true
     },
     "voluntary": {
      "type": "integer",
      "description": "User-initiated cancellations with no preceding payment failure",
      "readOnly": true
     },
     "involuntary": {
      "type": "integer",
      "description": "Cancellations preceded by a failed transaction",
      "readOnly": true
     },
     "byPlan": {
      "type": "array",
      "description": "Per-plan churn: { planId, planName, churned, churnRate }",
      "readOnly": true,
      "items": {}
     },
     "byGateway": {
      "type": "object",
      "description": "Churn count by gateway: { stripe, gocardless, local }",
      "readOnly": true
     }
    }
   },
   "billing.RevenueBreakdown": {
    "type": "object",
    "properties": {
     "total": {
      "type": "integer",
      "description": "Total revenue in cents",
      "readOnly": true
     },
     "byPlan": {
      "type": "array",
      "description": "Per-plan revenue: { planId, planName, revenue, transactionCount }",
      "readOnly": true,
      "items": {}
     },
     "byGateway": {
      "type": "object",
      "description": "Revenue by gateway: { stripe, gocardless, local } in cents",
      "readOnly": true
     },
     "byPaymentMethod": {
      "type": "object",
      "description": "Revenue by payment method string (Cash, Stripe, GoCardless, etc.) in cents",
      "readOnly": true
     }
    }
   },
   "billing.Payout": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Gateway payout ID",
      "readOnly": true
     },
     "gateway": {
      "type": "string",
      "description": "Source gateway",
      "readOnly": true,
      "enum": [
       "stripe",
       "gocardless"
      ]
     },
     "amount": {
      "type": "integer",
      "description": "Payout amount in cents",
      "readOnly": true
     },
     "currency": {
      "type": "string",
      "description": "Currency code (e.g. usd, gbp)",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "description": "Payout status (paid, pending, in_transit, failed, bounced)",
      "readOnly": true
     },
     "arrivalDate": {
      "type": "integer",
      "description": "Expected/actual arrival date",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "createdAt": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "description": {
      "type": "string",
      "readOnly": true
     },
     "transactionCount": {
      "type": "integer",
      "description": "Number of matched local transactions",
      "readOnly": true
     }
    }
   },
   "billing.PayoutDetail": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Gateway payout ID",
      "readOnly": true
     },
     "gateway": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "stripe",
       "gocardless"
      ]
     },
     "amount": {
      "type": "integer",
      "description": "Payout amount in cents",
      "readOnly": true
     },
     "currency": {
      "type": "string",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "readOnly": true
     },
     "arrivalDate": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "createdAt": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "transactionCount": {
      "type": "integer",
      "readOnly": true
     },
     "transactions": {
      "type": "array",
      "description": "Individual payout items: { gatewayId, localTransactionId, amount, fee, net, status, createdAt }",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "billing.ReconciliationReport": {
    "type": "object",
    "properties": {
     "period": {
      "type": "object",
      "description": "Date range: { from, to } as Unix timestamps",
      "readOnly": true
     },
     "stripe": {
      "type": "object",
      "description": "Stripe summary: { totalPayouts, totalAmount, totalFees, totalNet, matchedTransactions, unmatchedPayoutItems }. Null if Stripe not connected.",
      "readOnly": true
     },
     "gocardless": {
      "type": "object",
      "description": "GoCardless summary (same shape as stripe). Null if GoCardless not connected.",
      "readOnly": true
     },
     "unmatchedLocal": {
      "type": "integer",
      "description": "Local gateway transactions not matched to any payout item",
      "readOnly": true
     }
    }
   },
   "billing.DisputeSummary": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Stripe dispute ID (dp_...)",
      "readOnly": true
     },
     "amount": {
      "type": "integer",
      "description": "Disputed amount in cents",
      "readOnly": true
     },
     "currency": {
      "type": "string",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "warning_needs_response",
       "warning_under_review",
       "warning_closed",
       "needs_response",
       "under_review",
       "won",
       "lost"
      ]
     },
     "actionability": {
      "type": "string",
      "description": "Whether the school can still take action on this dispute",
      "readOnly": true,
      "enum": [
       "actionable",
       "awaiting_outcome",
       "resolved"
      ]
     },
     "reason": {
      "type": "string",
      "description": "Dispute reason (e.g., fraudulent, product_not_received)",
      "readOnly": true
     },
     "hasEvidence": {
      "type": "boolean",
      "description": "Whether evidence has been submitted",
      "readOnly": true
     },
     "evidenceDueBy": {
      "type": "integer",
      "description": "Deadline for evidence submission",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "chargeId": {
      "type": "string",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "Matched local student ID from charge metadata",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "readOnly": true
     },
     "createdAt": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "billing.DisputeDetail": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "readOnly": true
     },
     "amount": {
      "type": "integer",
      "readOnly": true
     },
     "currency": {
      "type": "string",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "readOnly": true
     },
     "actionability": {
      "type": "string",
      "readOnly": true
     },
     "reason": {
      "type": "string",
      "readOnly": true
     },
     "hasEvidence": {
      "type": "boolean",
      "readOnly": true
     },
     "evidenceDueBy": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "chargeId": {
      "type": "string",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "readOnly": true
     },
     "createdAt": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "paymentIntentId": {
      "type": "string",
      "readOnly": true
     },
     "networkReasonCode": {
      "type": "string",
      "description": "Card network reason code",
      "readOnly": true
     },
     "evidenceDetails": {
      "type": "object",
      "description": "Evidence status: { submissionCount, hasEvidence, pastDue, dueBy }",
      "readOnly": true
     },
     "_actions": {
      "type": "array",
      "description": "Available actions based on current status (e.g., submit_evidence, accept)",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "billing.DisputeEvidenceBundle": {
    "type": "object",
    "properties": {
     "productDescription": {
      "type": "string",
      "readOnly": true
     },
     "customerName": {
      "type": "string",
      "readOnly": true
     },
     "customerEmailAddress": {
      "type": "string",
      "readOnly": true
     },
     "customerPurchaseIp": {
      "type": "string",
      "readOnly": true
     },
     "serviceDate": {
      "type": "string",
      "description": "ISO date string",
      "readOnly": true
     },
     "serviceDocumentation": {
      "type": "string",
      "description": "Pre-built text summary of attendance records",
      "readOnly": true
     },
     "attendanceRecords": {
      "type": "array",
      "description": "Array of { date, venueName, styleName } from last 90 days",
      "readOnly": true,
      "items": {}
     },
     "attendanceSummary": {
      "type": "object",
      "description": "Summary: { totalClasses, dateRange: { from, to }, venues[], styles[] }",
      "readOnly": true
     }
    }
   },
   "billing.PortalConfig": {
    "type": "object",
    "properties": {
     "paymentMethodUpdate": {
      "type": "boolean",
      "description": "Allow payment method updates in portal"
     },
     "invoiceHistory": {
      "type": "boolean",
      "description": "Show invoice history in portal"
     },
     "subscriptionCancel": {
      "type": "object",
      "description": "Cancellation settings: { enabled, mode ('at_period_end'|'immediately'), cancellationReasons[] }"
     },
     "subscriptionPause": {
      "type": "object",
      "description": "App-level pause toggle (stored in Redis, not Stripe): { enabled }"
     },
     "updatedAt": {
      "type": "integer",
      "description": "Last update timestamp, null if using defaults",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "billing.TransactionReceipt": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Transaction ID",
      "readOnly": true
     },
     "date": {
      "type": "integer",
      "description": "Payment date (Unix timestamp)",
      "readOnly": true
     },
     "amount": {
      "type": "integer",
      "description": "Amount in cents",
      "readOnly": true
     },
     "currency": {
      "type": "string",
      "description": "Currency code",
      "readOnly": true
     },
     "description": {
      "type": "string",
      "description": "Payment description",
      "readOnly": true
     },
     "paymentMethod": {
      "type": "string",
      "description": "Payment method label",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Student full name",
      "readOnly": true
     },
     "studentEmail": {
      "type": "string",
      "description": "Student email",
      "readOnly": true
     },
     "receiptName": {
      "type": [
       "string",
       "null"
      ],
      "description": "Who paid: the family's billing member for a payment a family pays, else the student. An emailed receipt greets this person",
      "readOnly": true
     },
     "receiptEmail": {
      "type": [
       "string",
       "null"
      ],
      "description": "The address an emailed receipt goes to when none is given: the address of the person who paid. Null when they have none, and then nothing is sent",
      "readOnly": true
     },
     "receiptPaidFor": {
      "type": [
       "string",
       "null"
      ],
      "description": "The member the payment was for, when someone else paid (a family's billing member paying for another member). An emailed receipt names them in its opening line. Null when the member paid for themselves",
      "readOnly": true
     },
     "schoolName": {
      "type": "string",
      "description": "School name",
      "readOnly": true
     },
     "receiptUrl": {
      "type": "string",
      "description": "Gateway receipt URL (Stripe)",
      "readOnly": true
     },
     "planName": {
      "type": "string",
      "description": "Associated plan name",
      "readOnly": true
     },
     "cardBrand": {
      "type": "string",
      "description": "Card brand (visa, mastercard, etc.)",
      "readOnly": true
     },
     "cardLast4": {
      "type": "string",
      "description": "Last 4 digits of card",
      "readOnly": true
     },
     "lineItems": {
      "type": "array",
      "description": "Array of { description, amount, quantity }",
      "readOnly": true,
      "items": {}
     },
     "familyName": {
      "type": "string",
      "description": "Family name if family billing",
      "readOnly": true
     }
    }
   },
   "billing.SetupIntent": {
    "type": "object",
    "properties": {
     "clientSecret": {
      "type": "string",
      "description": "Stripe SetupIntent client secret for Stripe.js",
      "readOnly": true
     },
     "publishableKey": {
      "type": "string",
      "description": "Stripe publishable key",
      "readOnly": true
     },
     "stripeAccountId": {
      "type": "string",
      "description": "Stripe connected account ID",
      "readOnly": true
     }
    }
   },
   "billing.BillingProfile": {
    "type": "object",
    "properties": {
     "stripe": {
      "type": "object",
      "description": "Stripe connection: { connected, customerId, balance (cents), paymentMethods[] }",
      "readOnly": true
     },
     "gocardless": {
      "type": "object",
      "description": "GoCardless connection: { connected, customerId, mandates[], plansToEnd[] }. plansToEnd: the plans a direct debit GoCardless shows cancelled still has to end here, while it is still on the member (a cancel that stopped part-way, or one the bank made) ({ subscriptionId, name, amount (cents), nextDebitOn }); cancelling the direct debit again ends them. Empty otherwise.",
      "readOnly": true
     }
    }
   },
   "billing.SmartInvoice": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Invoice ID",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Student name",
      "readOnly": true
     },
     "planId": {
      "type": "integer",
      "description": "Plan ID",
      "readOnly": true
     },
     "planName": {
      "type": "string",
      "description": "Plan name",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "description": "Invoice status",
      "readOnly": true,
      "enum": [
       "pending",
       "processing",
       "completed",
       "cancelled",
       "expired"
      ]
     },
     "totalAmountCents": {
      "type": "integer",
      "description": "Total amount in cents",
      "readOnly": true
     },
     "currency": {
      "type": "string",
      "description": "Currency code",
      "readOnly": true
     },
     "discount": {
      "type": "integer",
      "description": "Discount amount",
      "readOnly": true
     },
     "discountType": {
      "type": "integer",
      "description": "0 = percentage, 1 = fixed",
      "readOnly": true
     },
     "oneOffPayment": {
      "type": "integer",
      "description": "Enrollment fee in cents",
      "readOnly": true
     },
     "startOn": {
      "type": "integer",
      "description": "Subscription start date (Unix timestamp)",
      "readOnly": true
     },
     "endOn": {
      "type": "integer",
      "description": "Subscription end date (Unix timestamp)",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "description": "Creation date (Unix timestamp)",
      "readOnly": true
     },
     "convertedOn": {
      "type": "integer",
      "description": "When payment was completed (Unix timestamp)",
      "readOnly": true
     }
    }
   },
   "billing.DeferredProcessResult": {
    "type": "object",
    "properties": {
     "processed": {
      "type": "integer",
      "description": "Total actions processed",
      "readOnly": true
     },
     "succeeded": {
      "type": "integer",
      "description": "Successfully executed",
      "readOnly": true
     },
     "failed": {
      "type": "integer",
      "description": "Failed to execute",
      "readOnly": true
     },
     "errors": {
      "type": "array",
      "description": "Array of { actionId, error } for failures",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "billing.CustomerLookupResult": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "description": "Current linkage status",
      "readOnly": true,
      "enum": [
       "linked",
       "stale",
       "unlinked"
      ]
     },
     "linkedCustomer": {
      "type": "object",
      "description": "Currently linked customer: { id, email, name }",
      "readOnly": true
     },
     "matches": {
      "type": "array",
      "description": "Candidate matches: [{ id, email, name, confidence ('high'|'medium'), subscriptions[] }]",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "billing.LinkCustomerResult": {
    "type": "object",
    "properties": {
     "linkedCustomerId": {
      "type": "string",
      "description": "The linked gateway customer ID",
      "readOnly": true
     }
    }
   },
   "billing.AuditEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "userId": {
      "type": "integer",
      "description": "The school admin who acted; null for API keys, MCP, staff, franchise and system",
      "readOnly": true
     },
     "source": {
      "type": "string",
      "description": "How the action arrived",
      "readOnly": true,
      "enum": [
       "admin",
       "api_key",
       "mcp",
       "staff",
       "franchise",
       "system"
      ]
     },
     "apiKeyId": {
      "type": "integer",
      "description": "The API key, for api_key and mcp actions",
      "readOnly": true
     },
     "impersonatorId": {
      "type": "integer",
      "description": "The staff or franchise user behind a log-in-as-school session",
      "readOnly": true
     },
     "actorName": {
      "type": "string",
      "description": "Who, in words; null for the system",
      "readOnly": true
     },
     "action": {
      "type": "string",
      "description": "Dotted action, e.g. billing.subscription.cancel",
      "readOnly": true
     },
     "subjectType": {
      "type": "string",
      "description": "subscription, transaction, plan, student or family",
      "readOnly": true
     },
     "subjectId": {
      "type": "string",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "The member the action concerns",
      "readOnly": true
     },
     "before": {
      "type": "object",
      "description": "The changed fields before (small; large snapshots are noted, not stored)",
      "readOnly": true
     },
     "after": {
      "type": "object",
      "description": "The changed fields after",
      "readOnly": true
     },
     "reason": {
      "type": "string",
      "description": "The admin's own words, when the action asked for them",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix seconds",
      "readOnly": true
     }
    }
   },
   "billing.PlanSubscriber": {
    "type": "object",
    "properties": {
     "subscriptionId": {
      "type": "integer",
      "description": "Subscription row ID",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "Student ID",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Student display name (first + last)",
      "readOnly": true
     },
     "email": {
      "type": "string",
      "description": "Student email address",
      "readOnly": true
     },
     "gateway": {
      "type": "string",
      "description": "Payment gateway",
      "readOnly": true,
      "enum": [
       "stripe",
       "gocardless",
       "local"
      ]
     },
     "type": {
      "type": "string",
      "description": "Raw subscription type from the DB (e.g. 'Stripe', 'GoCardless', 'Cash')",
      "readOnly": true
     },
     "externalId": {
      "type": "string",
      "description": "Gateway-side ID (Stripe/GoCardless subscription ID); null for local subs",
      "readOnly": true
     },
     "discount": {
      "type": "number",
      "description": "Raw discount value (percent, or cents when discountType is 1)",
      "readOnly": true
     },
     "discountType": {
      "type": "integer",
      "description": "0 = percentage, 1 = fixed cents",
      "readOnly": true
     },
     "discountedAmountCents": {
      "type": "integer",
      "description": "Effective per-period amount after discount (cents)",
      "readOnly": true
     },
     "hasFixedDiscount": {
      "type": "boolean",
      "description": "True if discountType=1 and discount>0 (used by the 'Exclude fixed discounts' migration toggle)",
      "readOnly": true
     },
     "startOn": {
      "type": "integer",
      "description": "Subscription start timestamp (Unix seconds)",
      "readOnly": true
     },
     "gatewayStatus": {
      "type": "string",
      "description": "Stripe subscription.status synced via webhook (active, past_due, etc.)",
      "readOnly": true
     },
     "styleIds": {
      "type": "array",
      "description": "Style IDs this plan is restricted to (empty = unrestricted)",
      "readOnly": true,
      "items": {}
     },
     "totalPaidCents": {
      "type": "integer",
      "description": "Lifetime successful payments on this subscription",
      "readOnly": true
     },
     "lastPaymentOn": {
      "type": "integer",
      "description": "Timestamp of the most recent transaction (any status)",
      "readOnly": true
     },
     "lastPaymentStatus": {
      "type": "string",
      "description": "Semantic status of the most recent transaction",
      "readOnly": true,
      "enum": [
       "successful",
       "failed",
       "pending",
       "retrying",
       "submitted",
       "disputed",
       "cancelled"
      ]
     },
     "isOverdue": {
      "type": "boolean",
      "description": "True if computeSubscriptionStatus classifies this sub as overdue",
      "readOnly": true
     }
    }
   },
   "billing.BillingJob": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Job ID",
      "readOnly": true
     },
     "type": {
      "type": "string",
      "description": "Job type (e.g. 'migration')",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "description": "Current job status",
      "readOnly": true,
      "enum": [
       "pending",
       "in_progress",
       "completed",
       "failed"
      ]
     },
     "progress": {
      "type": "object",
      "description": "{ total, processed, succeeded, failed, skipped, notFinished } counts. `notFinished` counts members moved at Stripe or GoCardless whose record here was not saved: they are not failures, and are not in `failed`.",
      "readOnly": true
     },
     "createdAt": {
      "type": "integer",
      "description": "Job creation timestamp (Unix seconds)",
      "readOnly": true
     },
     "completedAt": {
      "type": "integer",
      "description": "Job completion timestamp (Unix seconds), null while running",
      "readOnly": true
     },
     "sourcePlanId": {
      "type": "integer",
      "description": "Source plan ID (for migration jobs)",
      "readOnly": true
     },
     "targetPlanId": {
      "type": "integer",
      "description": "Target plan ID (for migration jobs)",
      "readOnly": true
     },
     "sourcePlanName": {
      "type": "string",
      "description": "Source plan name at job creation time",
      "readOnly": true
     },
     "targetPlanName": {
      "type": "string",
      "description": "Target plan name at job creation time",
      "readOnly": true
     },
     "timing": {
      "type": "string",
      "description": "Migration timing mode",
      "readOnly": true,
      "enum": [
       "immediate",
       "next_billing_cycle",
       "on_date"
      ]
     },
     "effectiveDate": {
      "type": [
       "string",
       "null"
      ],
      "description": "the day of an on_date move (YYYY-MM-DD, the school's calendar); null otherwise",
      "readOnly": true,
      "format": "date"
     },
     "migrationBatchId": {
      "type": "string",
      "description": "UUID identifying the batch (for idempotency and audit)",
      "readOnly": true
     },
     "failedReason": {
      "type": "string",
      "description": "set when status is failed as a whole: the last retry's error, or that it was stopped from the admin after it stalled. Null otherwise.",
      "readOnly": true
     },
     "results": {
      "type": "array",
      "description": "Per-subscription results: [{ id, studentId, studentName, success, error, skipped, gatewayMoved, note }]. Populated incrementally as the job runs. A row with `success: false` and `gatewayMoved: true` is not a failure: the member was moved at their gateway and only our own record is still to be saved; `note` says so, and the job's try-again finishes it.",
      "readOnly": true,
      "items": {}
     },
     "triedAgainAt": {
      "type": [
       "integer",
       "null"
      ],
      "description": "When the job was last started again with try-again (Unix seconds); null if it never was",
      "readOnly": true
     }
    }
   },
   "billing.BillingJobTryAgain": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Job ID",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "description": "The job's status now",
      "readOnly": true,
      "enum": [
       "pending",
       "in_progress",
       "completed",
       "failed"
      ]
     },
     "started": {
      "type": "boolean",
      "description": "True when this call started the run; false when the job was already running",
      "readOnly": true
     },
     "members": {
      "type": "integer",
      "description": "Members the run is for: everyone the job has not finished",
      "readOnly": true
     }
    }
   },
   "invoices.InvoiceListRow": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "collecting": {
      "type": "boolean",
      "description": "A GoCardless direct debit for it is in flight: the pay page refuses a card and the admin cannot collect again until it resolves"
     },
     "invoiceNumber": {
      "type": "number",
      "description": "Per-school sequence; null while draft."
     },
     "invoiceLabel": {
      "type": "string",
      "description": "Rendered number, e.g. INV-0042 (or 'Draft')."
     },
     "status": {
      "type": "string",
      "enum": [
       "draft",
       "sent",
       "paid",
       "overdue",
       "cancelled"
      ]
     },
     "studentId": {
      "type": "number"
     },
     "studentName": {
      "type": "string"
     },
     "totalCents": {
      "type": "number"
     },
     "currency": {
      "type": "string"
     },
     "issuedOn": {
      "type": "number",
      "format": "unix-seconds"
     },
     "dueOn": {
      "type": "number",
      "format": "unix-seconds"
     },
     "paidOn": {
      "type": "number",
      "format": "unix-seconds"
     },
     "createdOn": {
      "type": "number",
      "format": "unix-seconds"
     }
    }
   },
   "invoices.InvoiceDetail": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number",
      "readOnly": true
     },
     "invoiceNumber": {
      "type": [
       "number",
       "null"
      ]
     },
     "invoiceLabel": {
      "type": "string"
     },
     "status": {
      "type": "string",
      "enum": [
       "draft",
       "sent",
       "paid",
       "overdue",
       "cancelled"
      ]
     },
     "collecting": {
      "type": "boolean",
      "description": "A GoCardless direct debit for it is in flight"
     },
     "studentId": {
      "type": "number"
     },
     "studentName": {
      "type": "string"
     },
     "totalCents": {
      "type": "number"
     },
     "currency": {
      "type": "string"
     },
     "issuedOn": {
      "type": [
       "number",
       "null"
      ],
      "format": "unix-seconds"
     },
     "dueOn": {
      "type": [
       "number",
       "null"
      ],
      "format": "unix-seconds"
     },
     "paidOn": {
      "type": [
       "number",
       "null"
      ],
      "format": "unix-seconds"
     },
     "createdOn": {
      "type": "number",
      "format": "unix-seconds"
     },
     "cancelledOn": {
      "type": [
       "number",
       "null"
      ],
      "format": "unix-seconds"
     },
     "taxRate": {
      "type": [
       "string",
       "null"
      ]
     },
     "taxMode": {
      "type": [
       "string",
       "null"
      ]
     },
     "subtotalCents": {
      "type": "number"
     },
     "taxAmountCents": {
      "type": "number"
     },
     "taxName": {
      "type": "string"
     },
     "notes": {
      "type": "string"
     },
     "transactionId": {
      "type": "number",
      "description": "The settling billing transaction, once paid."
     },
     "items": {
      "type": "array",
      "description": "Line items: { id, position, description, quantity, unitAmountCents, lineTotalCents }.",
      "items": {}
     },
     "payUrl": {
      "type": "string",
      "description": "Public pay link (null until sent)."
     },
     "emailStatus": {
      "type": "string",
      "description": "How the last send went; absent until one is attempted",
      "readOnly": true,
      "enum": [
       "sent",
       "failed",
       "skipped"
      ]
     }
    }
   },
   "invoices.RecipientPreview": {
    "type": "object",
    "properties": {
     "recipient": {
      "type": "object",
      "description": "{ email, source: 'student' | 'emergencyInfo' | 'altEmail' } or null when unreachable."
     }
    }
   },
   "shop.Category": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Category ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Category name"
     },
     "colour": {
      "type": "string",
      "description": "Colour swatch (hex or CSS name)"
     },
     "position": {
      "type": "integer",
      "description": "Sort order (ascending)"
     },
     "productCount": {
      "type": "integer",
      "description": "Number of live (non-soft-deleted) products in the category",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix timestamp",
      "readOnly": true
     }
    }
   },
   "shop.ProductSummary": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "categoryId": {
      "type": "integer"
     },
     "name": {
      "type": "string"
     },
     "variantMode": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "flat",
       "matrix"
      ]
     },
     "visibility": {
      "type": "string",
      "enum": [
       "draft",
       "published",
       "archived"
      ]
     },
     "taxExempt": {
      "type": "boolean"
     },
     "position": {
      "type": "integer"
     },
     "optionCount": {
      "type": "integer",
      "description": "Number of live options",
      "readOnly": true
     },
     "minPriceCents": {
      "type": "integer",
      "description": "Cheapest option price",
      "readOnly": true
     },
     "maxPriceCents": {
      "type": "integer",
      "description": "Most expensive option price",
      "readOnly": true
     },
     "totalStock": {
      "type": "integer",
      "description": "Summed stock across options; null if any option is unlimited",
      "readOnly": true
     },
     "primaryImageKey": {
      "type": "string",
      "description": "Storage key of the lowest-position image; null when the product has none."
     },
     "primaryImageUrl": {
      "type": "string",
      "description": "Signed URL for the primary image (the card thumbnail); null when none or signing failed."
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     },
     "updatedOn": {
      "type": "integer",
      "readOnly": true
     }
    }
   },
   "shop.Product": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "categoryId": {
      "type": "integer"
     },
     "name": {
      "type": "string"
     },
     "description": {
      "type": "string"
     },
     "variantMode": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "flat",
       "matrix"
      ]
     },
     "attributeAxes": {
      "type": "array",
      "description": "Matrix mode only; null for flat products",
      "readOnly": true,
      "items": {
       "type": "object",
       "properties": {
        "name": {
         "type": "string"
        },
        "values": {
         "type": "array",
         "items": {
          "type": "string"
         }
        }
       }
      }
     },
     "visibility": {
      "type": "string",
      "enum": [
       "draft",
       "published",
       "archived"
      ]
     },
     "taxExempt": {
      "type": "boolean"
     },
     "costCents": {
      "type": "integer",
      "description": "Wholesale cost (future margin reports)"
     },
     "position": {
      "type": "integer"
     },
     "sourceMasterId": {
      "type": "integer",
      "description": "Links to the master catalog row (wholesale future)",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     },
     "updatedOn": {
      "type": "integer",
      "readOnly": true
     },
     "options": {
      "type": "array",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/shop.ProductOption"
      }
     },
     "images": {
      "type": "array",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/shop.ProductImage"
      }
     }
    }
   },
   "shop.ProductOption": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "productId": {
      "type": "integer",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Display name (auto-derived in matrix mode)"
     },
     "sku": {
      "type": "string"
     },
     "priceCents": {
      "type": "integer"
     },
     "quantity": {
      "type": "integer",
      "description": "Stock count; null = unlimited"
     },
     "position": {
      "type": "integer"
     },
     "attributes": {
      "type": "object",
      "description": "Matrix mode: { axisName: value }. Flat mode: null.",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     },
     "updatedOn": {
      "type": "integer",
      "readOnly": true
     }
    }
   },
   "shop.ProductImage": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "productId": {
      "type": "integer",
      "readOnly": true
     },
     "storageKey": {
      "type": "string",
      "description": "Railway bucket key"
     },
     "position": {
      "type": "integer",
      "description": "0 = primary"
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     }
    }
   },
   "shop.OrderCustomer": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "firstName": {
      "type": "string",
      "readOnly": true
     },
     "lastName": {
      "type": "string",
      "readOnly": true
     },
     "email": {
      "type": "string",
      "readOnly": true
     }
    }
   },
   "shop.OrderSummary": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "enum": [
       "pending_payment",
       "paid",
       "ready_for_pickup",
       "shipped",
       "completed",
       "cancelled",
       "refunded"
      ]
     },
     "fulfillmentType": {
      "type": "string",
      "enum": [
       "pos",
       "pickup",
       "ship"
      ]
     },
     "fulfilledBy": {
      "type": "string",
      "description": "'school' | 'martialytics' (wholesale)"
     },
     "customer": {
      "$ref": "#/components/schemas/shop.OrderCustomer",
      "description": "null for walk-in POS orders"
     },
     "subtotalCents": {
      "type": "integer",
      "readOnly": true
     },
     "discountCents": {
      "type": "integer",
      "readOnly": true
     },
     "taxCents": {
      "type": "integer",
      "readOnly": true
     },
     "shippingCents": {
      "type": "integer",
      "description": "Flat shipping fee charged on a shipped storefront order, included in totalCents (0 otherwise)",
      "readOnly": true
     },
     "totalCents": {
      "type": "integer",
      "readOnly": true
     },
     "totalRefundedCents": {
      "type": "integer",
      "description": "Sum of all refunds against this order",
      "readOnly": true
     },
     "placedByUserId": {
      "type": "integer",
      "description": "Staff user who rang up the order at POS",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     },
     "updatedOn": {
      "type": "integer",
      "readOnly": true
     },
     "itemCount": {
      "type": "integer",
      "description": "Number of distinct line items",
      "readOnly": true
     },
     "backorderedCount": {
      "type": "integer",
      "description": "Lines sold with their size already out of stock (a sign-up can still take one); handed over when stock arrives",
      "readOnly": true
     }
    }
   },
   "shop.OrderLineItem": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "optionId": {
      "type": "integer",
      "description": "Live option reference (may be soft-deleted)",
      "readOnly": true
     },
     "quantity": {
      "type": "integer",
      "readOnly": true
     },
     "priceCents": {
      "type": "integer",
      "description": "Per-unit price at sale time",
      "readOnly": true
     },
     "productName": {
      "type": "string",
      "description": "Frozen at sale",
      "readOnly": true
     },
     "optionName": {
      "type": "string",
      "description": "Frozen at sale",
      "readOnly": true
     },
     "attributes": {
      "type": "object",
      "description": "Matrix attributes frozen at sale, e.g. {Size:'M'}",
      "readOnly": true
     },
     "taxExemptAtSale": {
      "type": "boolean",
      "readOnly": true
     },
     "refundedQuantity": {
      "type": "integer",
      "description": "Units already refunded against this line",
      "readOnly": true
     },
     "backordered": {
      "type": "boolean",
      "description": "The size was already out of stock when it sold (stock went below zero); hand it over when stock arrives",
      "readOnly": true
     }
    }
   },
   "shop.OrderRefund": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "type": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "full",
       "partial"
      ]
     },
     "method": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "original",
       "store_credit"
      ]
     },
     "amountCents": {
      "type": "integer",
      "readOnly": true
     },
     "reason": {
      "type": "string",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     },
     "createdByUserId": {
      "type": "integer",
      "readOnly": true
     }
    }
   },
   "shop.StoreCreditEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "amountCents": {
      "type": "integer",
      "description": "Signed: positive = credit issued, negative = credit redeemed",
      "readOnly": true
     },
     "source": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "manual",
       "stripe_import",
       "consumption",
       "adjustment",
       "reversal",
       "refund"
      ]
     },
     "reason": {
      "type": "string",
      "description": "Shop entries name the order, e.g. Shop order",
      "readOnly": true
     },
     "transactionId": {
      "type": "integer",
      "description": "Linked billing transaction (if any)",
      "readOnly": true
     },
     "createdByUserId": {
      "type": "integer",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     }
    }
   },
   "shop.RefundCreateResult": {
    "type": "object",
    "properties": {
     "refundId": {
      "type": "integer",
      "readOnly": true
     },
     "amountCents": {
      "type": "integer",
      "description": "Total refund amount (sum of all refund items)",
      "readOnly": true
     },
     "fullyRefunded": {
      "type": "boolean",
      "description": "True when cumulative refunds on this order ≥ order total. Order status flips to 'refunded' in this case.",
      "readOnly": true
     }
    }
   },
   "shop.StoreCreditView": {
    "type": "object",
    "properties": {
     "balanceCents": {
      "type": "integer",
      "description": "Current Account Credit balance",
      "readOnly": true
     },
     "entries": {
      "type": "array",
      "description": "Most recent 50 entries, newest first",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/shop.StoreCreditEntry"
      }
     }
    }
   },
   "shop.StoreCreditAdjustResult": {
    "type": "object",
    "properties": {
     "entryId": {
      "type": "integer",
      "description": "ID of the new ledger entry",
      "readOnly": true
     },
     "newBalanceCents": {
      "type": "integer",
      "description": "Balance after this adjustment",
      "readOnly": true
     }
    }
   },
   "shop.Order": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "enum": [
       "pending_payment",
       "paid",
       "ready_for_pickup",
       "shipped",
       "completed",
       "cancelled",
       "refunded"
      ]
     },
     "fulfillmentType": {
      "type": "string",
      "enum": [
       "pos",
       "pickup",
       "ship"
      ]
     },
     "fulfilledBy": {
      "type": "string"
     },
     "customer": {
      "$ref": "#/components/schemas/shop.OrderCustomer"
     },
     "subtotalCents": {
      "type": "integer",
      "readOnly": true
     },
     "discountCents": {
      "type": "integer",
      "readOnly": true
     },
     "taxCents": {
      "type": "integer",
      "readOnly": true
     },
     "shippingCents": {
      "type": "integer",
      "description": "Flat shipping fee charged on a shipped storefront order, included in totalCents (0 otherwise)",
      "readOnly": true
     },
     "totalCents": {
      "type": "integer",
      "readOnly": true
     },
     "totalRefundedCents": {
      "type": "integer",
      "readOnly": true
     },
     "notes": {
      "type": "string",
      "readOnly": true
     },
     "payer": {
      "$ref": "#/components/schemas/shop.OrderCustomer",
      "description": "Who was charged when it is not the customer (a parent paying for a child). Null when the customer paid."
     },
     "externalReference": {
      "type": "string",
      "description": "Caller-supplied order reference (school website order id)",
      "readOnly": true
     },
     "shippingAddress": {
      "type": "object",
      "description": "Ship-to address for fulfillmentType='ship'",
      "readOnly": true
     },
     "placedByUserId": {
      "type": "integer",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     },
     "updatedOn": {
      "type": "integer",
      "readOnly": true
     },
     "itemCount": {
      "type": "integer",
      "readOnly": true
     },
     "backorderedCount": {
      "type": "integer",
      "readOnly": true
     },
     "items": {
      "type": "array",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/shop.OrderLineItem"
      }
     },
     "refunds": {
      "type": "array",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/shop.OrderRefund"
      }
     }
    }
   },
   "leads.LeadBoard": {
    "type": "object",
    "properties": {
     "stages": {
      "type": "array",
      "description": "All pipeline stages with their leads grouped inside, ordered by position",
      "items": {}
     },
     "sources": {
      "type": "array",
      "description": "Unique referral sources across all leads (for filter dropdown)",
      "items": {}
     }
    }
   },
   "leads.LeadBoardItem": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Student ID"
     },
     "firstName": {
      "type": "string",
      "description": "First name"
     },
     "lastName": {
      "type": "string",
      "description": "Last name"
     },
     "emailAddress": {
      "type": "string",
      "description": "Email address"
     },
     "phoneNumber": {
      "type": "string",
      "description": "Phone number or null"
     },
     "mobileNumber": {
      "type": "string",
      "description": "Mobile number or null"
     },
     "referralSource": {
      "type": "string",
      "description": "How they found you, or null"
     },
     "referredOn": {
      "type": "integer",
      "description": "Unix timestamp when referred, or null"
     },
     "stageId": {
      "type": "integer",
      "description": "Current stage ID"
     },
     "temperature": {
      "type": "string",
      "description": "Computed or overridden temperature",
      "enum": [
       "hot",
       "warm",
       "cold"
      ]
     },
     "temperatureOverride": {
      "type": "integer",
      "description": "Manual override: 1=hot, 2=warm, 3=cold, or null for auto"
     },
     "daysInStage": {
      "type": "integer",
      "description": "Number of days the lead has been in the current stage"
     },
     "lastContactDate": {
      "type": "integer",
      "description": "Unix timestamp of most recent contact note, or null"
     },
     "lastContactMethod": {
      "type": "string",
      "description": "Method of last contact (phone, email, etc.), or null"
     },
     "reminderDate": {
      "type": "string",
      "description": "Next reminder day (YYYY-MM-DD), or null",
      "format": "date"
     },
     "reminderOverdue": {
      "type": "boolean",
      "description": "True if reminder date has passed"
     },
     "isTrial": {
      "type": "boolean",
      "description": "Whether the lead is currently on trial"
     },
     "trialExpiresOn": {
      "type": "string",
      "description": "Trial expiry day (YYYY-MM-DD), or null",
      "format": "date"
     },
     "notes": {
      "type": "string",
      "description": "Free-text notes, or null"
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix timestamp when created"
     }
    }
   },
   "leads.LeadDetail": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Student ID"
     },
     "firstName": {
      "type": "string",
      "description": "First name"
     },
     "lastName": {
      "type": "string",
      "description": "Last name"
     },
     "emailAddress": {
      "type": "string",
      "description": "Email; empty when none"
     },
     "phoneNumber": {
      "type": [
       "string",
       "null"
      ]
     },
     "mobileNumber": {
      "type": [
       "string",
       "null"
      ]
     },
     "referralSource": {
      "type": [
       "string",
       "null"
      ],
      "description": "How they found you"
     },
     "referredOn": {
      "type": [
       "string",
       "null"
      ],
      "description": "YYYY-MM-DD",
      "format": "date"
     },
     "stageId": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Current stage ID (null if converted)"
     },
     "temperature": {
      "type": "string",
      "enum": [
       "hot",
       "warm",
       "cold"
      ]
     },
     "temperatureOverride": {
      "type": [
       "integer",
       "null"
      ],
      "description": "A temperature set by hand, over the computed one"
     },
     "daysInStage": {
      "type": "integer"
     },
     "lastContactDate": {
      "type": [
       "integer",
       "null"
      ],
      "format": "unix-seconds"
     },
     "lastContactMethod": {
      "type": [
       "string",
       "null"
      ]
     },
     "reminderDate": {
      "type": [
       "string",
       "null"
      ],
      "description": "YYYY-MM-DD",
      "format": "date"
     },
     "reminderOverdue": {
      "type": "boolean"
     },
     "isTrial": {
      "type": "boolean",
      "description": "Whether on trial"
     },
     "trialExpiresOn": {
      "type": [
       "string",
       "null"
      ],
      "format": "date"
     },
     "trialClassesUsed": {
      "type": "integer"
     },
     "trialClassesLimit": {
      "type": [
       "integer",
       "null"
      ]
     },
     "notes": {
      "type": [
       "string",
       "null"
      ]
     },
     "createdOn": {
      "type": "integer",
      "format": "unix-seconds"
     },
     "lossReason": {
      "type": [
       "string",
       "null"
      ],
      "description": "Reason for loss (if in Lost stage)"
     },
     "isLead": {
      "type": "boolean",
      "description": "Whether the student is a lead"
     },
     "isActive": {
      "type": "boolean",
      "description": "Whether the student is active"
     },
     "photoStorageKey": {
      "type": [
       "string",
       "null"
      ],
      "description": "The stored photo's key; null without one"
     },
     "joinedOn": {
      "type": [
       "string",
       "null"
      ],
      "format": "date"
     },
     "convertedOn": {
      "type": [
       "string",
       "null"
      ],
      "description": "When the lead became a member",
      "format": "date"
     },
     "birthday": {
      "type": [
       "string",
       "null"
      ],
      "format": "date"
     },
     "gender": {
      "type": [
       "string",
       "null"
      ],
      "enum": [
       "male",
       "female",
       "other",
       "prefer_not_to_say"
      ]
     },
     "address": {
      "type": [
       "string",
       "null"
      ]
     },
     "suburb": {
      "type": [
       "string",
       "null"
      ]
     },
     "postcode": {
      "type": [
       "string",
       "null"
      ]
     }
    }
   },
   "leads.LeadActivity": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Activity ID"
     },
     "studentId": {
      "type": "integer",
      "description": "Student/lead ID"
     },
     "type": {
      "type": "string",
      "description": "Activity type",
      "enum": [
       "note",
       "stage_change",
       "reminder_set",
       "reminder_cleared",
       "trial_started",
       "trial_expired",
       "converted",
       "lost",
       "created",
       "reopened"
      ]
     },
     "method": {
      "type": "string",
      "description": "Contact method (for note type), or null",
      "enum": [
       "phone",
       "email",
       "in_person",
       "sms",
       "other"
      ]
     },
     "contactDate": {
      "type": "integer",
      "description": "When contact occurred, or null"
     },
     "fromStageId": {
      "type": "integer",
      "description": "Previous stage ID (for moves), or null"
     },
     "toStageId": {
      "type": "integer",
      "description": "New stage ID (for moves), or null"
     },
     "fromStageName": {
      "type": "string",
      "description": "Previous stage name, or null"
     },
     "toStageName": {
      "type": "string",
      "description": "New stage name, or null"
     },
     "notes": {
      "type": "string",
      "description": "Note content or context, or null"
     },
     "createdBy": {
      "type": "integer",
      "description": "User ID who created (null for system)"
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix timestamp"
     }
    }
   },
   "leads.Reminder": {
    "type": "object",
    "properties": {
     "date": {
      "type": "string",
      "description": "Follow-up day (YYYY-MM-DD)",
      "format": "date"
     },
     "overdue": {
      "type": "boolean",
      "description": "True if the reminder day is before today in the school's timezone"
     }
    }
   },
   "onetouch.OtsuForm": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Form ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Form name"
     },
     "headline": {
      "type": "string",
      "description": "Headline text"
     },
     "intro": {
      "type": "string",
      "description": "Introduction text"
     },
     "colour": {
      "type": "string",
      "description": "Brand colour hex code"
     },
     "fee": {
      "type": "integer",
      "description": "Registration fee in cents"
     },
     "notifications": {
      "type": "boolean",
      "description": "Email notifications enabled"
     },
     "studentType": {
      "type": "string",
      "description": "Student type created on signup",
      "enum": [
       "student",
       "lead",
       "trial"
      ]
     },
     "hash": {
      "type": "string",
      "description": "Unique hash for public URL",
      "readOnly": true
     },
     "publicUrl": {
      "type": "string",
      "description": "Public-facing form URL",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "description": "Creation timestamp",
      "readOnly": true
     },
     "styles": {
      "type": "array",
      "description": "Linked styles [{id, name}]",
      "readOnly": true,
      "items": {}
     },
     "venues": {
      "type": "array",
      "description": "Linked venues [{id, name}]",
      "readOnly": true,
      "items": {}
     },
     "plans": {
      "type": "array",
      "description": "Linked billing plans [{id, name}]",
      "readOnly": true,
      "items": {}
     },
     "waivers": {
      "type": "array",
      "description": "Linked waivers [{id, name}]",
      "readOnly": true,
      "items": {}
     },
     "items": {
      "type": "array",
      "description": "Shop items offered with sign-up [{productId, productName, included, required, taxExempt, options: [{optionId, name, priceCents, quantity}]}]. taxExempt is the shop product's own setting: a charged item is taxed only when it is false. quantity is the shop's stock (null = unlimited; may be negative when sizes are back-ordered).",
      "readOnly": true,
      "items": {}
     },
     "registrationCount": {
      "type": "integer",
      "description": "Number of signups through this form",
      "readOnly": true
     }
    }
   },
   "onetouch.OtcoCheckout": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Checkout ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Checkout name"
     },
     "copy": {
      "type": "string",
      "description": "Description/copy text"
     },
     "hero": {
      "type": "string",
      "description": "Hero image URL"
     },
     "studentType": {
      "type": "string",
      "description": "What a NEW buyer becomes",
      "enum": [
       "student",
       "lead",
       "trial"
      ]
     },
     "notifications": {
      "type": "boolean",
      "description": "Email notifications enabled"
     },
     "hash": {
      "type": "string",
      "description": "Unique hash for public URL",
      "readOnly": true
     },
     "publicUrl": {
      "type": "string",
      "description": "Public-facing checkout URL",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "description": "Creation timestamp",
      "readOnly": true
     },
     "event": {
      "type": "object",
      "description": "Linked event {id, name, startDate, endDate}",
      "readOnly": true
     },
     "products": {
      "type": "array",
      "description": "Linked products [{optionId, productId, productName, optionName, priceCents}]",
      "readOnly": true,
      "items": {}
     },
     "orderCount": {
      "type": "integer",
      "description": "Number of orders through this checkout",
      "readOnly": true
     }
    }
   },
   "onetouch.OtsuReport": {
    "type": "object",
    "properties": {
     "periods": {
      "type": "array",
      "description": "Time-bucketed signup counts",
      "readOnly": true,
      "items": {}
     },
     "total": {
      "type": "integer",
      "description": "Total signups in range",
      "readOnly": true
     }
    }
   },
   "onetouch.OtcoReport": {
    "type": "object",
    "properties": {
     "periods": {
      "type": "array",
      "description": "Time-bucketed order counts",
      "readOnly": true,
      "items": {}
     },
     "total": {
      "type": "integer",
      "description": "Total orders in range",
      "readOnly": true
     }
    }
   },
   "onetouch.ShopProductCategory": {
    "type": "object",
    "properties": {
     "categoryId": {
      "type": "integer",
      "description": "Product category ID",
      "readOnly": true
     },
     "categoryName": {
      "type": "string",
      "description": "Category name",
      "readOnly": true
     },
     "products": {
      "type": "array",
      "description": "Products with options [{id, name, options: [{id, name, priceCents}]}]",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "widgets.WidgetsPayload": {
    "type": "object",
    "properties": {
     "settings": {
      "$ref": "#/components/schemas/widgets.WidgetSettings",
      "description": "Current widget settings for the school"
     },
     "embeds": {
      "$ref": "#/components/schemas/widgets.WidgetEmbeds",
      "description": "Pre-built embed code for both widgets"
     }
    }
   },
   "widgets.WidgetSettings": {
    "type": "object",
    "properties": {
     "leadRecipientEmail": {
      "type": "string",
      "description": "Lead notification recipient (or null)",
      "format": "email"
     },
     "bookingRecipientEmail": {
      "type": "string",
      "description": "Booking emails recipient (or null = the primary account)",
      "format": "email"
     },
     "leadRedirectUrl": {
      "type": "string",
      "description": "Post-submit redirect URL (or null)",
      "format": "url"
     },
     "accentColor": {
      "type": "string",
      "description": "Widget accent override (or null)",
      "format": "hex-color"
     },
     "darkThemeDefault": {
      "type": "boolean"
     },
     "allowedOrigins": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "shopEnabled": {
      "type": "boolean",
      "description": "Public shop widget master switch"
     },
     "shopMemberDirectDebit": {
      "type": "boolean",
      "description": "Members can pay a storefront order by one-off Direct Debit against the family payer's existing GoCardless mandate. Forces email verification at checkout."
     },
     "shopFulfillment": {
      "type": "string",
      "description": "Fulfillment mode for shop orders",
      "enum": [
       "pickup_only",
       "shipping_pickup"
      ]
     },
     "shopShippingFeeCents": {
      "type": "number",
      "description": "Flat shipping fee in cents (only when fulfillment === 'shipping_pickup')"
     },
     "shopLowStockThreshold": {
      "type": "number",
      "description": "Stock level at or below which 'Only N left' badge appears (0 disables)"
     }
    }
   },
   "widgets.WidgetEmbeds": {
    "type": "object",
    "properties": {
     "leads": {
      "$ref": "#/components/schemas/widgets.WidgetEmbed",
      "description": "Lead Capture form embed payload"
     },
     "bookings": {
      "$ref": "#/components/schemas/widgets.WidgetEmbed",
      "description": "Class Bookings calendar embed payload"
     },
     "shop": {
      "$ref": "#/components/schemas/widgets.WidgetEmbed",
      "description": "Online Shop storefront embed payload"
     }
    }
   },
   "widgets.WidgetEmbed": {
    "type": "object",
    "properties": {
     "kind": {
      "type": "string",
      "readOnly": true,
      "enum": [
       "leads",
       "bookings",
       "shop"
      ]
     },
     "url": {
      "type": "string",
      "description": "2.0 self-verifying widget URL (HMAC-signed)",
      "readOnly": true,
      "format": "url"
     },
     "iframe": {
      "type": "string",
      "description": "Recommended iframe snippet (works in any CMS)",
      "readOnly": true
     },
     "legacy": {
      "type": "object",
      "description": "Legacy MD5-hashed URL/iframe for install audits",
      "readOnly": true
     }
    }
   },
   "dashboard.NudgesResponse": {
    "type": "object",
    "properties": {
     "categories": {
      "type": "array",
      "description": "Nudge categories [{key, items, total, showing}]",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "dashboard.NudgeItem": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Unique nudge ID",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "description": "Related student ID: 0 for school-scoped nudges (e.g. storage_warning, storage_urgent)",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Student full name, or 'School Storage'/similar for school-scoped nudges",
      "readOnly": true
     },
     "type": {
      "type": "string",
      "description": "Nudge type identifier",
      "readOnly": true
     },
     "label": {
      "type": "string",
      "description": "Short label text",
      "readOnly": true
     },
     "detail": {
      "type": "string",
      "description": "Detailed description",
      "readOnly": true
     },
     "amount": {
      "type": "integer",
      "description": "Monetary amount in cents (if applicable)",
      "readOnly": true
     },
     "currency": {
      "type": "string",
      "description": "Currency code (if applicable)",
      "readOnly": true
     },
     "urgencyScore": {
      "type": "number",
      "description": "Urgency score 0.0-1.0 (higher = more urgent)",
      "readOnly": true
     },
     "status": {
      "type": "object",
      "description": "Status chip {label, variant, icon}",
      "readOnly": true
     },
     "actions": {
      "type": "array",
      "description": "Action identifiers",
      "readOnly": true,
      "items": {}
     },
     "meta": {
      "type": "object",
      "description": "Additional metadata (varies by nudge type)",
      "readOnly": true
     }
    }
   },
   "dashboard.NudgeCategory": {
    "type": "object",
    "properties": {
     "key": {
      "type": "string",
      "description": "Category identifier",
      "readOnly": true,
      "enum": [
       "payments",
       "retention",
       "leads",
       "milestones",
       "admin"
      ]
     },
     "items": {
      "type": "array",
      "description": "Nudge items in this category",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/dashboard.NudgeItem"
      }
     },
     "total": {
      "type": "integer",
      "description": "Total nudges in category (before pagination)",
      "readOnly": true
     },
     "showing": {
      "type": "integer",
      "description": "Number of nudges returned in this response",
      "readOnly": true
     }
    }
   },
   "dashboard.SnoozeResult": {
    "type": "object",
    "properties": {
     "nudgeId": {
      "type": "string",
      "description": "Snoozed nudge ID",
      "readOnly": true
     },
     "snoozed": {
      "type": "boolean",
      "description": "Always true on success",
      "readOnly": true
     },
     "duration": {
      "type": "string",
      "description": "Applied snooze duration",
      "readOnly": true,
      "enum": [
       "1d",
       "7d",
       "30d"
      ]
     }
    }
   },
   "dashboard.DismissResult": {
    "type": "object",
    "properties": {
     "nudgeId": {
      "type": "string",
      "description": "Dismissed nudge ID",
      "readOnly": true
     },
     "dismissed": {
      "type": "boolean",
      "description": "Always true on success",
      "readOnly": true
     }
    }
   },
   "dashboard.StudentStats": {
    "type": "object",
    "properties": {
     "activeStudents": {
      "type": "object",
      "description": "{ current, previous }: active student count",
      "readOnly": true
     },
     "currentTrials": {
      "type": "object",
      "description": "{ current, previous }: trial student count",
      "readOnly": true
     },
     "newStudents": {
      "type": "object",
      "description": "{ current, previous }: new students in period",
      "readOnly": true
     },
     "churnedStudents": {
      "type": "object",
      "description": "{ current, previous }: churned students in period",
      "readOnly": true
     },
     "netChange": {
      "type": "object",
      "description": "{ current, previous }: net change (new - churned)",
      "readOnly": true
     }
    }
   },
   "dashboard.StatCardStudents": {
    "type": "object",
    "properties": {
     "category": {
      "type": "string",
      "description": "Requested card category",
      "readOnly": true,
      "enum": [
       "trials",
       "new",
       "churned",
       "net"
      ]
     },
     "students": {
      "type": "array",
      "description": "[{ id, firstname, lastname, email, date, change? }] sorted newest first; change ('new'|'churned') is present only for the net category",
      "readOnly": true,
      "items": {}
     },
     "total": {
      "type": "integer",
      "description": "Row count: matches the card's number",
      "readOnly": true
     }
    }
   },
   "dashboard.CalendarHeatMap": {
    "type": "object",
    "properties": {
     "days": {
      "type": "array",
      "description": "[{ date, count, hasSingle }]: per-day attendee counts",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "dashboard.DayDetail": {
    "type": "object",
    "properties": {
     "occurrences": {
      "type": "array",
      "description": "Class occurrences for the day",
      "readOnly": true,
      "items": {
       "$ref": "#/components/schemas/dashboard.DayOccurrence"
      }
     }
    }
   },
   "dashboard.DayOccurrence": {
    "type": "object",
    "properties": {
     "eventId": {
      "type": "integer",
      "description": "Event ID",
      "readOnly": true
     },
     "eventName": {
      "type": "string",
      "description": "Event name",
      "readOnly": true
     },
     "eventType": {
      "type": "string",
      "description": "Event type",
      "readOnly": true,
      "enum": [
       "single",
       "recurring"
      ]
     },
     "startTime": {
      "type": "integer",
      "description": "Start time in HHMM format",
      "readOnly": true
     },
     "endTime": {
      "type": "integer",
      "description": "End time in HHMM format",
      "readOnly": true
     },
     "venueId": {
      "type": "integer",
      "description": "Venue ID (nullable)",
      "readOnly": true
     },
     "venueName": {
      "type": "string",
      "description": "Venue name (nullable)",
      "readOnly": true
     },
     "capacity": {
      "type": "integer",
      "description": "Max capacity (nullable)",
      "readOnly": true
     },
     "enrolledCount": {
      "type": "integer",
      "description": "Enrolled student count",
      "readOnly": true
     },
     "bookedCount": {
      "type": "integer",
      "description": "Drop-in booking count",
      "readOnly": true
     },
     "nearFull": {
      "type": "boolean",
      "description": "True when ≥85% capacity",
      "readOnly": true
     },
     "ranks": {
      "type": "array",
      "description": "Eligible rank badges [{rankId, rankName, color, styleId, styleName}]",
      "readOnly": true,
      "items": {}
     },
     "notableStudents": {
      "type": "array",
      "description": "Trial/lead students [{studentId, name, badge, trialClassNumber, source}]",
      "readOnly": true,
      "items": {}
     }
    }
   },
   "reports.BenchmarksSettings": {
    "type": "object",
    "properties": {
     "takePart": {
      "type": "boolean",
      "description": "Whether the school takes part in benchmarks."
     }
    }
   },
   "reports.BenchmarksView": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "description": "Discriminator. Every field below except `styleLabel` and `found` is present only when `ready`.",
      "enum": [
       "ready",
       "trial",
       "opted_out",
       "preparing",
       "no_roster",
       "not_enough_peers"
      ]
     },
     "headline": {
      "type": "object",
      "description": "(ready) `text` is the whole sentence. `segments` is the same sentence in parts; a part with `tone` `lead` or `grow` is a metric name."
     },
     "split": {
      "type": "object",
      "description": "(ready) How many compared metrics are `leading` (top quarter), `pace` (middle half) and `grow` (bottom quarter)."
     },
     "lanes": {
      "type": "array",
      "description": "(ready) One per metric, compared metrics first and strongest first. Each has key, label, note, format (percent, percent1, currencyCents, perYear, months), invert (true = lower is better), fix { label, path } (where in the admin to work on it), comparedWith (main or money), patterns (what schools in the top quarter of ALL schools do differently on this metric: label, topQuarter, you, match; empty unless at least 10 top-quarter schools have the habit measured and it sets them apart) and result. A ready result has value, percentile (0 to 100, higher is better), standing (leading, pace, grow), median, middleHalf [worse edge, better edge], topQuarter, peers (how many had a figure) and position (4 to 96: where the school sits on a lane whose middle half spans 30 to 70).",
      "items": {}
     },
     "peers": {
      "type": "object",
      "description": "(ready) The peer group, described and never listed: count, styleMatch (style or family), styleLabel, reach (country, region, world), sizeRange and under16Range (rounded outward), countries (names only) and widened { found, from, to } when geography had to widen."
     },
     "moneyPeers": {
      "type": [
       "object",
       "null"
      ],
      "description": "(ready) The same-currency group revenue per student is compared in: count, currency, styleMatch, styleLabel. Null when fewer than 10 schools bill in the currency."
     },
     "school": {
      "type": "object",
      "description": "(ready) The school's own matched traits: activeStudents, under16Percent, country, currency."
     },
     "settling": {
      "type": "boolean",
      "description": "(ready) True when the school is below the peer bar (under 20 active students or under six months of history): its own figures are still settling, and it is in nobody else's group."
     },
     "figuresMonth": {
      "type": "string",
      "description": "(ready) First day of the month the figures are for.",
      "format": "date"
     },
     "peersSetOn": {
      "type": "string",
      "description": "(ready) When the peer group was set.",
      "format": "date"
     },
     "peersReviewedOn": {
      "type": "string",
      "description": "(ready) When the peer group is next reviewed.",
      "format": "date"
     },
     "styleLabel": {
      "type": "string",
      "description": "(not_enough_peers) What the school was matched on."
     },
     "found": {
      "type": "integer",
      "description": "(not_enough_peers) How many schools like this one there are worldwide."
     }
    }
   },
   "reports.ChurnOverride": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "readOnly": true
     },
     "expiresOn": {
      "type": "integer",
      "description": "Unix seconds the override lapses; null = permanent",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true
     }
    }
   },
   "reports.OverviewResult": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "description": "Discriminator. `ready` carries the snapshot payload; `pending` carries a reason code.",
      "enum": [
       "ready",
       "pending"
      ]
     },
     "payload": {
      "type": "object",
      "description": "(ready only) Full snapshot payload. Section keys map to lens identifiers, with sub-objects of metric blocks and narration text."
     },
     "computedAt": {
      "type": "integer",
      "description": "(ready only) Unix seconds when the snapshot was generated."
     },
     "snapshotVersion": {
      "type": "string",
      "description": "(ready only) Version stamp used for AI insight cache dedup."
     },
     "reason": {
      "type": "string",
      "description": "(pending only) Why the snapshot isn't ready.",
      "enum": [
       "no_snapshot_yet",
       "stale_snapshot",
       "worker_unavailable"
      ]
     }
    }
   },
   "reports.IncomeDetail": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "description": "Always `ready`. No pending state. Runs live against `school_billing_transactions`.",
      "enum": [
       "ready"
      ]
     },
     "actualMonths": {
      "type": "array",
      "description": "Actual buckets, oldest first. Each entry: `{ month: <bucket key>, label: <short label>, amountCents: number }`. `amountCents` sums successful, non-refunded, non-deleted transactions. Length depends on granularity and ribbon `from`/`to`. At granularity=month: default 12 entries (driven by `from`/`to`, clamped to a defensive ceiling [1, 600]); `month` = \"YYYY-MM\", `label` = \"Jan\"-style. At granularity=week: default 13 entries (clamped [1, 2080]); `month` = week-start \"YYYY-MM-DD\" (Sunday), `label` = \"MMM D\". At granularity=day: default 30 entries (clamped [1, 3650]); `month` = \"YYYY-MM-DD\", `label` = \"MMM D\". The field name is preserved across grains for backward-compat; treat it as the bucket key, not a calendar month.",
      "items": {}
     },
     "actualMonthsBySource": {
      "type": "object",
      "description": "Same actuals broken out per revenue source (subscription / payg / shop / events / one_off / other). Each value is an array of `IncomeMonth` in the same order and length as `actualMonths`. Sum across sources reconstitutes the total."
     },
     "projectionMonths": {
      "type": "array",
      "description": "Next 4 calendar months at granularity=month. Empty array at granularity=week or day. Same shape as `actualMonths`. Produced by the two-tower model: deterministic subscription roll-forward (MRR × (1 - churn) + newPaying × ARPU) plus per-source flat extrapolation for shop / events / payg / one_off / other.",
      "items": {}
     },
     "projectionMonthsBySource": {
      "type": "object",
      "description": "Projection months broken out per source. Per-source arrays are empty at sub-monthly grain. Used by the detail-modal what-if panel to label which lever moves which slice of the projection."
     },
     "totalActualCents": {
      "type": "number",
      "description": "Sum of `actualMonths[].amountCents` (cents)."
     },
     "totalProjectionCents": {
      "type": "number",
      "description": "Sum of `projectionMonths[].amountCents` (cents). Zero at sub-monthly grain."
     },
     "priorYearActualCents": {
      "type": "number",
      "description": "Sum of the same-length window shifted back one year from `actualMonths` (cents). Zero at sub-monthly grain. Used to compute `yoyDeltaPct`."
     },
     "yoyDeltaPct": {
      "type": "number",
      "description": "Year-over-year change as a percent (e.g. `128` = +128%). `null` when (a) the prior-year total was zero, (b) the actuals window exceeds 12 months (year-shifted copy would overlap the actuals, making the comparison meaningless), or (c) granularity is sub-monthly."
     },
     "projectionInputs": {
      "type": "object",
      "description": "Default inputs the two-tower projection consumes. Fields: activeSubscriptions, monthlyRecurringRevenueCents, monthlyChurnRate (0..1), monthlyNewPayingCustomers, avgRevenuePerNewCustomerCents, lookbackMonths (window used to derive the Tower A rates above; equals the projection horizon), paygSmoothingWindow (window used for Tower B per-source flat extrapolation). The scenario endpoint accepts multipliers on these same values as what-if levers."
     },
     "generatedAt": {
      "type": "number",
      "description": "Unix seconds when the aggregation ran."
     }
    }
   },
   "reports.IncomeScenario": {
    "type": "object",
    "properties": {
     "scenarioProjectionMonths": {
      "type": "array",
      "description": "Lever-adjusted projection months (sum across sources).",
      "items": {}
     },
     "scenarioProjectionMonthsBySource": {
      "type": "object",
      "description": "Lever-adjusted projection broken out per source. Same keys as IncomeDetail.actualMonthsBySource."
     },
     "scenarioTotalCents": {
      "type": "number",
      "description": "Sum of `scenarioProjectionMonths[].amountCents` (cents)."
     },
     "baselineProjectionMonths": {
      "type": "array",
      "description": "No-lever baseline projection in the same horizon, for side-by-side rendering against the scenario line.",
      "items": {}
     },
     "baselineTotalCents": {
      "type": "number",
      "description": "Sum of `baselineProjectionMonths[].amountCents` (cents)."
     },
     "projectionInputs": {
      "type": "object",
      "description": "Default lever inputs: same shape as IncomeDetail.projectionInputs. Use to centre the sliders."
     },
     "appliedLevers": {
      "type": "object",
      "description": "Echo of the levers the server honoured (post-validation). Useful for client-side reconciliation when bounds clamp a slider."
     },
     "generatedAt": {
      "type": "number",
      "description": "Unix seconds when the scenario ran."
     }
    }
   },
   "reports.PendingDetail": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "description": "Always `pending` until the corresponding phase ships.",
      "enum": [
       "pending"
      ]
     },
     "availableInPhase": {
      "type": "string",
      "description": "Phase identifier (e.g. 'phase-2-retention-risk-model'). Maps to the Reports build plan in docs/REPORTS-BUILD-PLAN.md."
     },
     "message": {
      "type": "string",
      "description": "Human-readable explanation of what's required for this endpoint to return real data."
     }
    }
   },
   "reports.FirstLookEnqueueResult": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "description": "Discriminator. `enqueued` carries a `jobId` for the kicked-off BullMQ job. `skipped` carries a `reason` explaining why no run was queued.",
      "enum": [
       "enqueued",
       "skipped"
      ]
     },
     "jobId": {
      "type": "string",
      "description": "(enqueued only) Stable per-(school, snapshotVersion) job identifier; same value for duplicate clicks until the snapshot version changes."
     },
     "reason": {
      "type": "string",
      "description": "(skipped only) Why no job was queued. `no_snapshot` = nothing for the worker to patch. `already_has_ai` = current snapshot already has insights. `permanent_skip` = a policy gate (trial, inactive, below min); re-running won't help. `system_skip` = transient OpenAI/config failure; wait for the next nightly run.",
      "enum": [
       "no_snapshot",
       "already_has_ai",
       "permanent_skip",
       "system_skip"
      ]
     }
    }
   },
   "reports.LibraryEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Stable identifier for the legacy report."
     },
     "title": {
      "type": "string",
      "description": "Display title."
     },
     "description": {
      "type": "string",
      "description": "What the legacy report did and how 2.0 surfaces it."
     },
     "destination": {
      "type": "object",
      "description": "Where the user lands. Discriminated by `kind`: `lens-modal` (opens a lens detail modal), `export` (CSV/PDF download), or `external-route` (links into a non-Reports admin page)."
     },
     "availableInPhase": {
      "type": "string",
      "description": "Phase when this entry becomes clickable end-to-end."
     }
    }
   },
   "reports.MetricKey": {
    "type": "object",
    "properties": {
     "key": {
      "type": "string",
      "description": "Canonical metric keys used by the benchmarks endpoint and the AI insight tool-use. Closed enum; never accept arbitrary strings.",
      "enum": [
       "net_new_active_30d",
       "open_leads_aged_7d",
       "trial_to_active_30d",
       "predicted_new_starts_30d",
       "retention_90d",
       "risk_critical_count",
       "risk_deteriorating_7d",
       "first_30d_survival",
       "churn_rate_30d",
       "top_churn_reason",
       "median_lifespan_months",
       "winback_rate_90d",
       "mrr_current",
       "revenue_forecast_30d",
       "failed_payments_open",
       "expiring_subscriptions_30d",
       "avg_attendance_per_active_30d",
       "class_fill_rate",
       "send_response_rate",
       "kiosk_usage_rate",
       "rank_progression_90d",
       "grading_ready_count",
       "stalled_students_count",
       "skill_coverage_gap",
       "active_student_count",
       "median_tenure_days",
       "new_regions_90d",
       "family_group_ratio"
      ]
     }
    }
   },
   "reports.SubscribersResult": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "description": "Discriminator. `ready` ships rows and pagination meta. `unavailable` ships a `reason` the frontend uses to pick fallback copy.",
      "enum": [
       "ready",
       "unavailable"
      ]
     },
     "periodStartSec": {
      "type": "integer",
      "description": "(ready only) Window start, unix seconds. Mirrors the Revenue Movement card period."
     },
     "periodEndSec": {
      "type": "integer",
      "description": "(ready only) Window end, unix seconds."
     },
     "rows": {
      "type": "array",
      "description": "(ready only) Array of SubscriberRow.",
      "items": {}
     },
     "page": {
      "type": "integer",
      "description": "(ready only) Current page (1-indexed)."
     },
     "limit": {
      "type": "integer",
      "description": "(ready only) Page size."
     },
     "total": {
      "type": "integer",
      "description": "(ready only) Total matching rows."
     },
     "totalPages": {
      "type": "integer",
      "description": "(ready only) Pages at the current limit."
     },
     "reason": {
      "type": "string",
      "description": "(unavailable only) Why the roster couldn't be served. `no_subscribers_baked` / `older_payload_version` are transient: the next snapshot rebuild populates the roster.",
      "enum": [
       "no_snapshot",
       "no_revenue_section",
       "no_subscribers_baked",
       "older_payload_version"
      ]
     }
    }
   },
   "reports.SubscriberRow": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer",
      "description": "Student id."
     },
     "name": {
      "type": "string",
      "description": "Display name snapshotted at worker time."
     },
     "planId": {
      "type": "integer",
      "description": "Billing plan id at periodEnd (or the last-known plan if the sub cancelled in window)."
     },
     "planName": {
      "type": "string",
      "description": "Plan display name."
     },
     "mrrCents": {
      "type": "integer",
      "description": "Signed cents. Meaning depends on the query context: plan/anchor:end = end MRR; anchor:start = start MRR; step = signed step delta (negative for contraction/churn)."
     },
     "status": {
      "type": "string",
      "description": "Short status label (e.g. 'New sign-up', 'Reactivated', 'Cancelled'): driven by the snapshot's classification, never recomputed."
     }
    }
   },
   "reports.PaymentsLedgerRow": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Transaction id."
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix seconds when the transaction was created."
     },
     "amount": {
      "type": "integer",
      "description": "Amount in cents. Frontend divides by 100 for display."
     },
     "status": {
      "type": "string",
      "description": "Semantic status (refunded originals stay `successful`).",
      "enum": [
       "successful",
       "failed",
       "retrying",
       "pending",
       "submitted",
       "cancelled"
      ]
     },
     "paymentMethod": {
      "type": "string",
      "description": "Raw payment method string (e.g. 'Stripe', 'Cash')."
     },
     "gateway": {
      "type": "string",
      "description": "Inferred from the metadata blob, for the gateway badge.",
      "enum": [
       "stripe",
       "gocardless",
       "local"
      ]
     },
     "description": {
      "type": "string",
      "description": "Free-text description, nullable."
     },
     "studentId": {
      "type": "integer",
      "description": "Member who paid. Null for family-only or shop-only charges."
     },
     "studentName": {
      "type": "string",
      "description": "Computed `firstName lastName`. Null when studentId is null."
     },
     "familyId": {
      "type": "integer",
      "description": "Family who paid. Null when not a family charge."
     },
     "shopOrderId": {
      "type": "integer",
      "description": "Shop order this payment settled (GET /v1/shop/orders/:id). Null when not a shop payment."
     },
     "familyName": {
      "type": "string",
      "description": "Family display name. Surfaced when studentName is null."
     },
     "refundedOn": {
      "type": "integer",
      "description": "Unix seconds of the refund event. Null if not refunded."
     },
     "failedOn": {
      "type": "integer",
      "description": "Unix seconds of the failure event. Null if not failed."
     }
    }
   },
   "reports.AttendanceRosterRow": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "student_attendance.id: stable, school-unique."
     },
     "checkInSec": {
      "type": "integer",
      "description": "Unix seconds when the check-in was recorded."
     },
     "studentId": {
      "type": "integer",
      "description": "Member who checked in."
     },
     "studentName": {
      "type": "string",
      "description": "Computed `firstName lastName` (trimmed)."
     },
     "styleId": {
      "type": "integer",
      "description": "Style attributed via the rank held at check-in time (not the student's current rank)."
     },
     "styleName": {
      "type": "string",
      "description": "Display name of the attributed style."
     },
     "venueId": {
      "type": "integer",
      "description": "school_venues.id where the check-in happened."
     },
     "venueName": {
      "type": "string",
      "description": "Display name of the venue."
     },
     "photoUrl": {
      "type": "string",
      "description": "Signed URL of the student's photo, valid for an hour; null when there is none."
     },
     "emergencyNumber": {
      "type": "string",
      "description": "The student's first emergency contact's mobile, else phone; null when none is on file. Left out when the caller lacks the Medical & Emergency permission."
     }
    }
   },
   "reports.FrequencyResult": {
    "type": "object",
    "properties": {
     "weeks": {
      "type": "array",
      "description": "Oldest first. Each: `weekStart` (YYYY-MM-DD, Sunday), `label`, `startSec`, `endSec` (exclusive), `checkIns`, `students`, `average` (checkIns / students, two decimals, 0 when nobody had joined), `partial` (the week is still running).",
      "items": {}
     },
     "from": {
      "type": "integer",
      "description": "Unix seconds at the start of the first week."
     },
     "to": {
      "type": "integer",
      "description": "Unix seconds at the end of the last week (exclusive)."
     }
    }
   },
   "reports.FrequencyWeekResult": {
    "type": "object",
    "properties": {
     "weekStart": {
      "type": "string",
      "description": "YYYY-MM-DD of the week's Sunday."
     },
     "startSec": {
      "type": "integer",
      "description": "Unix seconds at the start of the week."
     },
     "endSec": {
      "type": "integer",
      "description": "Unix seconds at the end of the week (exclusive)."
     },
     "rows": {
      "type": "array",
      "description": "One per active student: `studentId`, `studentName`, `firstName`, `lastName`, `checkIns` (this week), `fourWeekAverage`.",
      "items": {}
     },
     "students": {
      "type": "integer",
      "description": "Rows."
     },
     "checkIns": {
      "type": "integer",
      "description": "Check-ins across the rows."
     },
     "average": {
      "type": "number",
      "description": "checkIns / students, two decimals."
     },
     "partial": {
      "type": "boolean",
      "description": "The week is still running."
     }
    }
   },
   "reports.LeaderboardResult": {
    "type": "object",
    "properties": {
     "rows": {
      "type": "array",
      "description": "Ranked rows. Each row carries `rank` (1..N, computed server-side), `studentId`, `studentName`, `checkIns`, `lastCheckInSec`.",
      "items": {}
     },
     "from": {
      "type": "integer",
      "description": "Echoed unix-seconds lower bound of the queried window."
     },
     "to": {
      "type": "integer",
      "description": "Echoed unix-seconds upper bound of the queried window."
     },
     "totalStudents": {
      "type": "integer",
      "description": "Distinct students with at least one check-in in the window. Stays honest when the projection is truncated to `limit`."
     },
     "totalCheckIns": {
      "type": "integer",
      "description": "Total check-ins across all students in the window."
     }
    }
   },
   "reports.ClassActivityResult": {
    "type": "object",
    "properties": {
     "rows": {
      "type": "array",
      "description": "Per-class activity rows. Each: `eventId`, `className`, `venueId`, `venueName`, `capacity` (nullable for uncapped classes), `occurrences` (distinct booking dates in window), `scheduledOccurrences` (canonical sessions in window from expanding days+start/end_date; null when indeterminable; the denominator for occupancy %), `checkIns`, `bookings`, `noShows`. Occupancy % is client-derived: checkIns / bookings ÷ (capacity × scheduledOccurrences). Sorted by checkIns DESC, ties broken by bookings DESC then noShows DESC.",
      "items": {}
     },
     "from": {
      "type": "integer",
      "description": "Echoed unix-seconds lower bound."
     },
     "to": {
      "type": "integer",
      "description": "Echoed unix-seconds upper bound."
     },
     "totalClasses": {
      "type": "integer",
      "description": "Distinct classes with any activity (≥1 check-in, ≥1 booking, or ≥1 no-show) in the window. Stays honest when the projection is truncated."
     }
    }
   },
   "reports.HeatmapResult": {
    "type": "object",
    "properties": {
     "matrix": {
      "type": "array",
      "description": "Counts indexed [dow][hour]. dow 0=Sunday … 6=Saturday. hour 0..23 in the school's wall clock. Always a full 7×24 array of integers; cells outside `[hourStart, hourEnd]` are zeros, not missing.",
      "items": {}
     },
     "total": {
      "type": "integer",
      "description": "Total check-ins across the matrix (== sum of all cells)."
     },
     "maxCell": {
      "type": "integer",
      "description": "Max single cell value, for tooltips; not used for colour scaling."
     },
     "hourStart": {
      "type": "integer",
      "description": "Inclusive lower bound of the visible hour band (0..23). Empty windows fall back to 6."
     },
     "hourEnd": {
      "type": "integer",
      "description": "Inclusive upper bound of the visible hour band (0..23). Empty windows fall back to 21."
     },
     "bins": {
      "type": "array",
      "description": "4 quantile boundaries (p20/p40/p60/p80 over non-zero cells) defining 5 buckets for the colour ramp. `[0,0,0,0]` when no cells are populated.",
      "items": {}
     },
     "from": {
      "type": "integer",
      "description": "Echoed unix-seconds lower bound."
     },
     "to": {
      "type": "integer",
      "description": "Echoed unix-seconds upper bound."
     }
    }
   },
   "reports.AttendanceTrendResult": {
    "type": "object",
    "properties": {
     "periods": {
      "type": "array",
      "description": "Ordered buckets. Each: `month` (bucket key: 'YYYY-MM' at month grain, 'YYYY-MM-DD' bucket-start at week/day), `label` (short axis label), `byStyle` ([{ styleId, styleName, count }], desc by count). Empty buckets are preserved (byStyle: []) so the timeline stays continuous.",
      "items": {}
     },
     "from": {
      "type": "integer",
      "description": "Echoed window start (unix seconds)."
     },
     "to": {
      "type": "integer",
      "description": "Echoed window end (unix seconds, exclusive)."
     },
     "granularity": {
      "type": "string",
      "description": "Bucket cadence the periods were computed at.",
      "enum": [
       "month",
       "week",
       "day"
      ]
     }
    }
   },
   "reports.GrowthCohortsResult": {
    "type": "object",
    "properties": {
     "cohorts": {
      "type": "array",
      "description": "Ordered buckets. Each: `month` (bucket key: 'YYYY-MM' at month grain, 'YYYY-MM-DD' bucket-start at week/day), `label`, `active`/`trials`/`leads` (new in period), `churned`, `leadsLost`, and `totalActive` (point-in-time active headcount at the bucket's end).",
      "items": {}
     },
     "totalActiveMomPct": {
      "type": "number",
      "description": "Period-over-period % change in totalActive (last vs prev bucket). Null when the prior bucket is zero."
     },
     "from": {
      "type": "integer",
      "description": "Echoed window start (unix seconds)."
     },
     "to": {
      "type": "integer",
      "description": "Echoed window end (unix seconds, exclusive)."
     },
     "granularity": {
      "type": "string",
      "description": "Bucket cadence the cohorts were computed at.",
      "enum": [
       "month",
       "week",
       "day"
      ]
     }
    }
   },
   "news.NewsArticle": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "title": {
      "type": "string"
     },
     "article": {
      "type": "string",
      "description": "HTML body content"
     },
     "excerpt": {
      "type": "string",
      "description": "Short summary, nullable on legacy rows"
     },
     "author": {
      "type": "string"
     },
     "isVisible": {
      "type": "boolean",
      "description": "True if published"
     },
     "showOnWebsite": {
      "type": "boolean",
      "description": "True if it is also on the school's public website (its Blog). Members see a published article either way."
     },
     "publishStart": {
      "type": "integer",
      "description": "Unix seconds; null = no lower bound"
     },
     "publishEnd": {
      "type": "integer",
      "description": "Unix seconds; null = no upper bound"
     },
     "views": {
      "type": "integer",
      "description": "Global view counter",
      "readOnly": true
     },
     "heroStorageKey": {
      "type": "string",
      "description": "Railway Bucket key for v2-uploaded hero images. Null on legacy articles: those resolve via legacy filesystem path.",
      "readOnly": true
     },
     "heroUrl": {
      "type": "string",
      "description": "Freshly presigned URL for the hero image, regenerated on every read. Short-lived (~1 hour). Null when no hero is set or storage is unavailable. Do not cache.",
      "readOnly": true
     },
     "pushSentAt": {
      "type": "integer",
      "description": "Unix seconds the publish-push notification fired. Null if never. Used for push idempotency so re-toggling visibility does not re-fire.",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix seconds",
      "readOnly": true
     },
     "deletedOn": {
      "type": "integer",
      "description": "Soft-delete marker. Read paths exclude rows with deletedOn != null.",
      "readOnly": true
     }
    }
   },
   "news.HeroUploadResult": {
    "type": "object",
    "properties": {
     "storageKey": {
      "type": "string",
      "description": "Bucket key the hero now points to.",
      "readOnly": true
     },
     "heroUrl": {
      "type": "string",
      "description": "Presigned URL for immediate preview (~1 hour).",
      "readOnly": true
     }
    }
   },
   "news.InlineUploadResult": {
    "type": "object",
    "properties": {
     "storageKey": {
      "type": "string",
      "description": "Bucket key for the uploaded inline image.",
      "readOnly": true
     },
     "url": {
      "type": "string",
      "description": "Permanent public URL the editor should embed in an <img> tag inside the article body: /v1/public/news-images/{schoolId}/{articleId}/{file}. It never expires; deleting the article deletes the image.",
      "readOnly": true
     }
    }
   },
   "send.DeliverResult": {
    "type": "object",
    "properties": {
     "sent": {
      "type": "array",
      "description": "Successfully sent deliveries",
      "items": {}
     },
     "skipped": {
      "type": "array",
      "description": "Skipped recipients with reasons (no_address, opted_out, anti_fatigue, invalid_address, provider_error, not_found)",
      "items": {}
     },
     "summary": {
      "type": "object",
      "description": "Counts: total, sent, skipped, failed. People in `held` are counted in skipped."
     },
     "held": {
      "type": "array",
      "description": "POST /send/email and /send/sms with holdLimited: true. Each entry is a scheduled send the per-person send limits queued: { scheduledSendId, rule, until (unix seconds, when it sends), recipientIds }. Push one through now with POST /v1/send/schedule/queue/:id/send-now.",
      "items": {}
     }
    }
   },
   "send.DeliverabilityPreview": {
    "type": "object",
    "properties": {
     "requested": {
      "type": "integer",
      "description": "Distinct recipients in the request (after de-duplication). May differ from the original recipientIds.length if duplicates were present."
     },
     "deliverable": {
      "type": "integer",
      "description": "Recipients that would actually receive the message: found, with a valid address/subscription, opted-in, and not on the suppression list. Anti-fatigue is NOT applied here (point-in-time, would change between preview and send)."
     },
     "skipped": {
      "type": "object",
      "description": "Per-reason counts. Email/SMS shape: { not_found, no_address, opted_out, suppressed }. Push shape: { no_subscription }. Sum of skipped values + deliverable always equals requested."
     },
     "held": {
      "type": "array",
      "description": "Audience check only: [{ studentId, name, rule, until, detail }] for deliverable people the per-person send limits would hold right now. rule is cooldown, daily_limit, weekly_marketing_cap or quiet_hours; until is unix seconds. They are still counted in deliverable: a send with holdLimited: true sends them at `until`.",
      "items": {}
     }
    }
   },
   "send.EmailPayload": {
    "type": "object",
    "properties": {
     "recipientIds": {
      "type": "array",
      "description": "Student IDs to send to (1 to 500)",
      "items": {
       "type": "integer"
      }
     },
     "subject": {
      "type": "string",
      "description": "Email subject line. Supports {{merge_tags}}.",
      "maxLength": 998
     },
     "htmlBody": {
      "type": "string",
      "description": "HTML email body. Supports {{merge_tags}}."
     },
     "textBody": {
      "type": "string",
      "description": "Plain text fallback body"
     },
     "fromName": {
      "type": "string",
      "description": "Sender display name (defaults to school name)",
      "maxLength": 255
     },
     "replyTo": {
      "type": "string",
      "description": "Reply-to email address",
      "format": "email"
     },
     "stream": {
      "type": "string",
      "description": "Transactional bypasses anti-fatigue rules. Broadcast triggers anti-fatigue + requires ?confirm=true. Default: broadcast.",
      "enum": [
       "transactional",
       "broadcast"
      ]
     },
     "trackOpens": {
      "type": "boolean",
      "description": "Track email opens. Default: true."
     },
     "trackClicks": {
      "type": "boolean",
      "description": "Track link clicks. Default: true."
     },
     "templateId": {
      "type": "integer",
      "description": "Template ID for delivery log tracking"
     },
     "metadata": {
      "type": "object",
      "description": "Custom key-value metadata"
     }
    },
    "required": [
     "recipientIds",
     "subject",
     "htmlBody"
    ]
   },
   "send.SmsPayload": {
    "type": "object",
    "properties": {
     "recipientIds": {
      "type": "array",
      "description": "Student IDs to send to (1 to 500)",
      "items": {
       "type": "integer"
      }
     },
     "message": {
      "type": "string",
      "description": "SMS message body. Supports {{merge_tags}}.",
      "maxLength": 1600
     },
     "mediaUrl": {
      "type": "string",
      "description": "MMS media URL",
      "format": "url"
     },
     "stream": {
      "type": "string",
      "description": "Transactional bypasses anti-fatigue rules. Broadcast triggers anti-fatigue + requires ?confirm=true. Default: broadcast.",
      "enum": [
       "transactional",
       "broadcast"
      ]
     },
     "templateId": {
      "type": "integer",
      "description": "Template ID for delivery log tracking"
     },
     "metadata": {
      "type": "object",
      "description": "Custom key-value metadata"
     }
    },
    "required": [
     "recipientIds",
     "message"
    ]
   },
   "send.PushPayload": {
    "type": "object",
    "properties": {
     "userIds": {
      "type": "array",
      "description": "Admin/staff user IDs to send to (1 to 500). NOTE: not students. These are the school's staff account IDs (an internal surface; there is no public endpoint to enumerate them).",
      "items": {
       "type": "integer"
      }
     },
     "title": {
      "type": "string",
      "description": "Push notification title",
      "maxLength": 120
     },
     "body": {
      "type": "string",
      "description": "Push notification body",
      "maxLength": 500
     },
     "actionUrl": {
      "type": "string",
      "description": "URL opened when the user clicks the push",
      "format": "url"
     },
     "icon": {
      "type": "string",
      "description": "Icon shown in the push card",
      "format": "url"
     },
     "stream": {
      "type": "string",
      "description": "Transactional bypasses confirm/preview. Default: transactional.",
      "enum": [
       "transactional",
       "broadcast"
      ]
     },
     "metadata": {
      "type": "object",
      "description": "Custom key-value metadata"
     }
    },
    "required": [
     "userIds",
     "title",
     "body"
    ]
   },
   "send.DeliveryLogEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "channel": {
      "type": "string",
      "enum": [
       "email",
       "sms",
       "chat",
       "push",
       "social",
       "webhook"
      ]
     },
     "recipientId": {
      "type": "integer"
     },
     "recipientAddress": {
      "type": "string"
     },
     "status": {
      "type": "string",
      "enum": [
       "queued",
       "sending",
       "delivered",
       "opened",
       "clicked",
       "bounced",
       "failed"
      ]
     },
     "externalId": {
      "type": "string",
      "description": "Provider message ID"
     },
     "templateId": {
      "type": "integer"
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix timestamp"
     }
    }
   },
   "send.StudentPreferences": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer"
     },
     "email": {
      "type": "object",
      "description": "{ preference, source }"
     },
     "sms": {
      "type": "object",
      "description": "{ preference, source }"
     },
     "chat": {
      "type": "object",
      "description": "{ preference, source }"
     },
     "push": {
      "type": "object",
      "description": "{ preference, source }"
     },
     "etag": {
      "type": "string",
      "description": "Composite optimistic-concurrency token (format \"v<timestamp>\") derived from max(updatedOn) across this student's explicit preference rows. \"v0\" when no explicit row exists yet. Send back as If-Match on PATCH to detect concurrent admin edits. Also returned in the standard ETag response header.",
      "readOnly": true
     }
    }
   },
   "send.PreviewResult": {
    "type": "object",
    "properties": {
     "html": {
      "type": "string",
      "description": "Complete email HTML document"
     },
     "text": {
      "type": "string",
      "description": "Plain text fallback"
     },
     "subject": {
      "type": "string",
      "description": "Resolved subject line (null if not provided)"
     },
     "blockCount": {
      "type": "integer",
      "description": "Number of blocks rendered"
     },
     "footerAutoAppended": {
      "type": "boolean",
      "description": "True if a footer was auto-added for compliance"
     },
     "mergeTagsResolved": {
      "type": "boolean",
      "description": "True if a recipientId was provided and tags were resolved"
     },
     "mergeTagsFound": {
      "type": "array",
      "description": "Tag names found in the document",
      "items": {
       "type": "string"
      }
     },
     "warnings": {
      "type": "array",
      "description": "Unknown tag warnings",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "send.ScheduledSend": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "channel": {
      "type": "string",
      "enum": [
       "email",
       "sms"
      ]
     },
     "status": {
      "type": "string",
      "description": "Always 'scheduled'"
     },
     "scheduledFor": {
      "type": "integer",
      "description": "Unix timestamp for delivery"
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix timestamp"
     }
    }
   },
   "send.ScheduledSendItem": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "schoolId": {
      "type": "integer",
      "readOnly": true
     },
     "channel": {
      "type": "string",
      "enum": [
       "email",
       "sms"
      ]
     },
     "status": {
      "type": "string",
      "description": "'scheduled' = waiting for its time. 'failed' = the worker refused it at fire time (see `failure`); listed for seven days or until dismissed.",
      "enum": [
       "scheduled",
       "failed"
      ]
     },
     "failure": {
      "type": "object",
      "description": "Null on 'scheduled' rows. Set on 'failed' rows: { reason, detail, at }. reason is a code such as insufficient_credits, content_blocked, send_blocked, attachment_unavailable, invalid_payload, delivery_error, interrupted (a send that stopped part way: some people may have received it); detail is plain text; at is unix seconds."
     },
     "held": {
      "type": "object",
      "description": "Set when the per-person send limits held these recipients back from an earlier send: { rule, fromScheduledSendId, fromBatchId }. The row sends at scheduledFor, when the limit clears, or now with POST /v1/send/schedule/queue/:id/send-now. Null otherwise."
     },
     "scheduledFor": {
      "type": "integer",
      "description": "When the worker will fire this send.",
      "format": "unix-seconds"
     },
     "recipientCount": {
      "type": "integer",
      "description": "Number of recipientIds in the stored payload. The actual delivered count may be lower after preference/anti-fatigue suppression."
     },
     "subject": {
      "type": "string",
      "description": "Email subject. Null for sms channel."
     },
     "messagePreview": {
      "type": "string",
      "description": "First 80 chars of the SMS body. Null for email channel."
     },
     "senderId": {
      "type": "integer",
      "description": "User ID that scheduled the send. Nullable for legacy rows."
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "send.DeliveryRecipient": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "recipientId": {
      "type": "integer",
      "description": "Student ID"
     },
     "recipientAddress": {
      "type": "string",
      "description": "Email or phone"
     },
     "status": {
      "type": "string",
      "enum": [
       "queued",
       "sending",
       "delivered",
       "opened",
       "clicked",
       "bounced",
       "failed"
      ]
     },
     "externalId": {
      "type": "string",
      "description": "Provider message ID"
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix timestamp"
     }
    }
   },
   "send.SendHistoryEntry": {
    "type": "object",
    "properties": {
     "channel": {
      "type": "string"
     },
     "contentHash": {
      "type": "string",
      "description": "Content hash grouping key (nullable)"
     },
     "templateId": {
      "type": "integer",
      "description": "Template ID grouping key (nullable)"
     },
     "stats": {
      "type": "object",
      "description": "{ total, skipped, delivered, opened, clicked, bounced, failed, outcomesKnown }. outcomesKnown is false for a send carried from v1 (source 'v1'): total is its recipient count and the outcome counts were not kept (they read 0, not measured)."
     },
     "firstSentOn": {
      "type": "integer",
      "description": "Earliest send timestamp"
     },
     "lastSentOn": {
      "type": "integer",
      "description": "Latest send timestamp"
     }
    }
   },
   "send.Draft": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "channel": {
      "type": "string",
      "enum": [
       "email",
       "sms",
       "social"
      ]
     },
     "subject": {
      "type": "string",
      "description": "Email subject (nullable)"
     },
     "content": {
      "type": "string",
      "description": "Draft content: block JSON or text (nullable)"
     },
     "recipients": {
      "type": "object",
      "description": "Recipient config: { studentIds?: number[], segmentId?: number }"
     },
     "scheduleOn": {
      "type": "integer",
      "description": "Scheduled send time (null = not scheduled)",
      "format": "unix-seconds"
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "updatedOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "send.UploadedAsset": {
    "type": "object",
    "properties": {
     "storageKey": {
      "type": "string",
      "description": "S3 storage key for the uploaded file"
     },
     "url": {
      "type": "string",
      "description": "Signed URL for embedding in templates (long-lived)"
     },
     "mimeType": {
      "type": "string",
      "description": "MIME type of the uploaded file"
     },
     "sizeBytes": {
      "type": "integer",
      "description": "File size in bytes"
     }
    }
   },
   "send.MergeTag": {
    "type": "object",
    "properties": {
     "name": {
      "type": "string",
      "description": "Tag name (e.g. firstname)"
     },
     "category": {
      "type": "string"
     },
     "description": {
      "type": "string"
     },
     "audience": {
      "type": "string",
      "enum": [
       "student",
       "admin",
       "instructor"
      ]
     }
    }
   },
   "send.MergeTagValidation": {
    "type": "object",
    "properties": {
     "template": {
      "type": "string",
      "description": "Echo of the input template"
     },
     "audience": {
      "type": "string",
      "description": "Audience scope used for validation. null if not provided.",
      "enum": [
       "student",
       "admin",
       "instructor"
      ]
     },
     "valid": {
      "type": "boolean",
      "description": "True iff every {{tag}} in the template is known AND audience-matched."
     },
     "foundTags": {
      "type": "array",
      "description": "Tag names that exist and match the audience. Deduped.",
      "items": {
       "description": "string"
      }
     },
     "unknownTags": {
      "type": "array",
      "description": "Tag names with no registry entry. Will be left as-is in any resolve. Deduped.",
      "items": {
       "description": "string"
      }
     },
     "audienceMismatches": {
      "type": "array",
      "description": "Tag names that exist but belong to a different audience. Will be left as-is. Deduped.",
      "items": {
       "description": "string"
      }
     },
     "totalOccurrences": {
      "type": "integer",
      "description": "Total {{tag}} occurrences in the template (counts duplicates)."
     }
    }
   },
   "send.MergeTagResolveResult": {
    "type": "object",
    "properties": {
     "template": {
      "type": "string",
      "description": "Echo of the input template"
     },
     "resolved": {
      "type": "string",
      "description": "Rendered output. Unknown tags are left as-is."
     },
     "studentId": {
      "type": "integer"
     },
     "audience": {
      "type": "string",
      "enum": [
       "student",
       "admin",
       "instructor"
      ]
     },
     "foundTags": {
      "type": "array",
      "items": {
       "description": "string"
      }
     },
     "unknownTags": {
      "type": "array",
      "items": {
       "description": "string"
      }
     },
     "audienceMismatches": {
      "type": "array",
      "items": {
       "description": "string"
      }
     },
     "totalOccurrences": {
      "type": "integer"
     }
    }
   },
   "send.MergeTagBatchResolveResult": {
    "type": "object",
    "properties": {
     "template": {
      "type": "string"
     },
     "audience": {
      "type": "string",
      "enum": [
       "student",
       "admin",
       "instructor"
      ]
     },
     "requested": {
      "type": "integer",
      "description": "Number of student IDs in the request."
     },
     "resolvedCount": {
      "type": "integer",
      "description": "Number of students that were found and resolved."
     },
     "missingCount": {
      "type": "integer",
      "description": "Number of student IDs that did not exist or were not in this school."
     },
     "foundTags": {
      "type": "array",
      "description": "Template-level inspection: same answer for every student in the batch.",
      "items": {
       "description": "string"
      }
     },
     "unknownTags": {
      "type": "array",
      "items": {
       "description": "string"
      }
     },
     "audienceMismatches": {
      "type": "array",
      "items": {
       "description": "string"
      }
     },
     "totalOccurrences": {
      "type": "integer"
     },
     "results": {
      "type": "array",
      "description": "Per-student results in the same order as the request.",
      "items": {
       "$ref": "#/components/schemas/send.MergeTagBatchResolveEntry"
      }
     }
    }
   },
   "send.MergeTagBatchResolveEntry": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "integer"
     },
     "found": {
      "type": "boolean",
      "description": "False if the student doesn't exist or isn't in this school."
     },
     "resolved": {
      "type": "string",
      "description": "Rendered output. null when found=false."
     }
    }
   },
   "send.EmailDocument": {
    "type": "object",
    "properties": {
     "version": {
      "type": "integer",
      "description": "Document schema version. Currently 1.",
      "enum": [
       1
      ]
     },
     "settings": {
      "$ref": "#/components/schemas/send.EmailDocumentSettings",
      "description": "Document-level rendering settings. Defaults applied if omitted."
     },
     "blocks": {
      "type": "array",
      "description": "Ordered list of content blocks (min 1). Rendered top-to-bottom into the email HTML.",
      "items": {
       "$ref": "#/components/schemas/send.EmailBlock"
      }
     }
    },
    "required": [
     "version",
     "blocks"
    ]
   },
   "send.EmailDocumentSettings": {
    "type": "object",
    "properties": {
     "backgroundColor": {
      "type": "string",
      "description": "Outer page background color. 6-digit hex. Default: #ffffff.",
      "format": "hex-color"
     },
     "contentWidth": {
      "type": "integer",
      "description": "Email content column width in px (320–800). Default: 600."
     },
     "fontFamily": {
      "type": "string",
      "description": "CSS font-family stack. Default: \"'Open Sans', Arial, Helvetica, sans-serif\"."
     }
    }
   },
   "send.EmailBlock": {
    "type": "object",
    "properties": {
     "type": {
      "type": "string",
      "description": "Block discriminator. Each value selects a different shape. See per-type field reference below.",
      "enum": [
       "heading",
       "text",
       "image",
       "button",
       "divider",
       "spacer",
       "header",
       "footer",
       "columns",
       "card",
       "video",
       "social",
       "merge_block",
       "ai_block",
       "rank_progress",
       "attendance_snapshot",
       "milestone_badge",
       "upcoming_classes",
       "belt_test_card",
       "event_promo",
       "payment_summary",
       "referral_card",
       "family_dashboard"
      ]
     },
     "id": {
      "type": "string",
      "description": "Optional client-side ID (used by composer for drag/drop ordering)."
     },
     "_shapes": {
      "type": "object",
      "description": "Per-type field reference (informational, not a real field). heading: { content: string (required), level: 'h1'|'h2'|'h3', align, color, backgroundColor }. text: { content: string, align, color, backgroundColor, fontSize 10 to 32 }. image: { src (required), alt, width 50 to 600, align, linkUrl }. button: { text (required), url (required), color, textColor, align, borderRadius 0 to 50 }. divider: { style: 'solid'|'dashed'|'dotted', color }. spacer: { height 4 to 100 }. header: { logoUrl, backgroundColor }. footer: { includeUnsubscribe boolean, includeAddress boolean, customText (max 2000) }. columns: { columns: array of 2 to 3 { width 10 to 90 (percent), blocks: inner-blocks (no nested columns) } }. card: { imageUrl, imageAlt, title (required), description, buttonText, buttonUrl, buttonColor }. video: { thumbnailUrl (required), videoUrl (required), alt }. social: { links: 1 to 7 of { platform: facebook|instagram|youtube|tiktok|x|linkedin|website, url } }. merge_block: { tagName (required): resolved at send time }. ai_block: { content (required), prompt, align, color, fontSize }. Smart blocks (rank_progress, attendance_snapshot, milestone_badge, upcoming_classes, belt_test_card, event_promo, payment_summary, referral_card, family_dashboard): {} or { data: {...} }: `data` is auto-resolved at send time from student context. Composer typically only sets `type` + `id` for smart blocks."
     }
    },
    "required": [
     "type"
    ]
   },
   "send.automations.AutomationListItem": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Automation ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Automation name"
     },
     "description": {
      "type": "string",
      "description": "Optional description"
     },
     "status": {
      "type": "string",
      "description": "Current status",
      "enum": [
       "draft",
       "active",
       "paused",
       "archived"
      ]
     },
     "category": {
      "type": "string",
      "description": "Category"
     },
     "audience": {
      "type": "string",
      "description": "Target audience",
      "enum": [
       "student",
       "admin",
       "instructor"
      ]
     },
     "source": {
      "type": "string",
      "description": "Origin of this automation",
      "readOnly": true,
      "enum": [
       "custom",
       "library",
       "marketplace",
       "system"
      ]
     },
     "triggerCount": {
      "type": "integer",
      "description": "Number of triggers",
      "readOnly": true
     },
     "stepCount": {
      "type": "integer",
      "description": "Number of steps",
      "readOnly": true
     },
     "statsActiveEnrollments": {
      "type": "integer",
      "description": "Currently enrolled students",
      "readOnly": true
     },
     "statsCompleted": {
      "type": "integer",
      "description": "Total completions",
      "readOnly": true
     },
     "statsTotalEnrollments": {
      "type": "integer",
      "description": "All-time enrollment count",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "updatedOn": {
      "type": [
       "integer",
       "null"
      ],
      "readOnly": true,
      "format": "unix-seconds"
     },
     "hasUnpublishedChanges": {
      "type": "boolean",
      "description": "A live automation has auto-saved changes awaiting publish",
      "readOnly": true
     }
    }
   },
   "send.automations.AutomationDetail": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "name": {
      "type": "string"
     },
     "description": {
      "type": "string"
     },
     "status": {
      "type": "string",
      "enum": [
       "draft",
       "active",
       "paused",
       "archived"
      ]
     },
     "category": {
      "type": "string"
     },
     "audience": {
      "type": "string",
      "enum": [
       "student",
       "admin",
       "instructor"
      ]
     },
     "reviewPoints": {
      "type": "array",
      "description": "Pre-launch review checklist copied from the library seed at import. Null once reviewed (POST /:id/mark-reviewed) or on activation.",
      "readOnly": true,
      "items": {}
     },
     "source": {
      "type": "string",
      "enum": [
       "custom",
       "library",
       "marketplace",
       "system"
      ]
     },
     "recipientUserIds": {
      "type": "array",
      "description": "Admin user IDs for admin audience",
      "items": {
       "type": "integer"
      }
     },
     "recipientInstructorIds": {
      "type": "array",
      "description": "Instructor IDs for instructor audience",
      "items": {
       "type": "integer"
      }
     },
     "statsActiveEnrollments": {
      "type": "integer",
      "description": "Currently enrolled students",
      "readOnly": true
     },
     "statsCompleted": {
      "type": "integer",
      "description": "Total completions",
      "readOnly": true
     },
     "statsCancelled": {
      "type": "integer",
      "description": "Total cancellations",
      "readOnly": true
     },
     "statsTotalEnrollments": {
      "type": "integer",
      "description": "All-time enrollment count",
      "readOnly": true
     },
     "statsTotalSends": {
      "type": "integer",
      "description": "Total messages sent by this automation",
      "readOnly": true
     },
     "statsTotalOpens": {
      "type": "integer",
      "description": "Total email opens",
      "readOnly": true
     },
     "statsTotalClicks": {
      "type": "integer",
      "description": "Total link clicks",
      "readOnly": true
     },
     "triggers": {
      "type": "array",
      "description": "Automation triggers",
      "items": {
       "$ref": "#/components/schemas/send.automations.Trigger"
      }
     },
     "steps": {
      "type": "array",
      "description": "Automation steps (tree structure via parentStepId)",
      "items": {
       "$ref": "#/components/schemas/send.automations.Step"
      }
     },
     "createdBy": {
      "type": "integer",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "updatedOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "draft": {
      "type": [
       "object",
       "null"
      ],
      "description": "The unpublished draft of a live automation: { definition (the PATCH shape: name, description, category, audience, recipients, triggers, steps), updatedOn }; null when there is none",
      "readOnly": true
     },
     "hasUnpublishedChanges": {
      "type": "boolean",
      "description": "A live automation has auto-saved changes awaiting publish",
      "readOnly": true
     }
    }
   },
   "send.automations.Trigger": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "type": {
      "type": "string",
      "description": "Trigger type",
      "enum": [
       "event",
       "schedule",
       "segment_entry"
      ]
     },
     "eventName": {
      "type": "string",
      "description": "DomainEvents key (required for event type)"
     },
     "schedule": {
      "type": "string",
      "description": "CRON expression (required for schedule type)"
     },
     "segmentId": {
      "type": "integer",
      "description": "Segment ID (required for segment_entry type)"
     },
     "conditions": {
      "type": "object",
      "description": "Filter rules against event payload + student state"
     },
     "reEnrollmentPolicy": {
      "type": "string",
      "description": "How students can re-enter",
      "enum": [
       "once",
       "once_per_period",
       "unlimited"
      ]
     },
     "reEnrollmentPeriodDays": {
      "type": "integer",
      "description": "Days before re-enrollment (for once_per_period)"
     }
    }
   },
   "send.automations.Step": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "stepKey": {
      "type": [
       "string",
       "null"
      ],
      "description": "Stable identity across publishes: echo it verbatim on PATCH, mint a UUID for a new step. Null only on rows written before stepKey existed, minted on the next save"
     },
     "parentStepId": {
      "type": "integer",
      "description": "Parent step ID for branch children (null for root-level)"
     },
     "branchPath": {
      "type": "string",
      "description": "Which branch this step belongs to",
      "enum": [
       "yes",
       "no"
      ]
     },
     "order": {
      "type": "integer",
      "description": "Position within parent/branch_path. Omit it and steps run in the order they are listed."
     },
     "type": {
      "type": "string",
      "description": "Step type",
      "enum": [
       "send_email",
       "send_sms",
       "send_chat",
       "send_push",
       "send_social",
       "wait",
       "branch",
       "update_student",
       "add_tag",
       "remove_tag",
       "change_status",
       "enroll_in_automation",
       "webhook",
       "notify_admin",
       "create_nudge",
       "log_note"
      ]
     },
     "config": {
      "type": "object",
      "description": "Type-specific configuration (template_id, duration, condition, etc.)"
     },
     "urgency": {
      "type": "string",
      "description": "Whether sends go through the digest buffer",
      "enum": [
       "buffered",
       "immediate"
      ]
     },
     "exitConditions": {
      "type": "array",
      "description": "Rules that cancel enrollment if true before this step",
      "items": {
       "type": "object"
      }
     }
    }
   },
   "send.automations.AutomationExplanation": {
    "type": "object",
    "properties": {
     "summary": {
      "type": "string",
      "description": "One-line summary (trigger and step count)"
     },
     "triggerDescriptions": {
      "type": "array",
      "description": "Plain-English trigger descriptions",
      "items": {
       "type": "string"
      }
     },
     "stepDescriptions": {
      "type": "array",
      "description": "Numbered plain-English step descriptions",
      "items": {
       "type": "string"
      }
     },
     "exitConditionCount": {
      "type": "integer",
      "description": "Total exit conditions across all steps"
     },
     "stats": {
      "type": "object",
      "description": "Enrollment statistics"
     }
    }
   },
   "send.automations.TriggerInput": {
    "type": "object",
    "properties": {
     "type": {
      "type": "string",
      "enum": [
       "event",
       "schedule",
       "segment_entry"
      ]
     },
     "eventName": {
      "type": "string",
      "description": "Required for event type"
     },
     "schedule": {
      "type": "string",
      "description": "Required for schedule type"
     },
     "segmentId": {
      "type": "integer",
      "description": "Required for segment_entry type"
     },
     "conditions": {
      "type": "object"
     },
     "reEnrollmentPolicy": {
      "type": "string",
      "enum": [
       "once",
       "once_per_period",
       "unlimited"
      ]
     },
     "reEnrollmentPeriodDays": {
      "type": "integer"
     }
    },
    "required": [
     "type"
    ]
   },
   "send.automations.StepInput": {
    "type": "object",
    "properties": {
     "parentStepId": {
      "type": "integer",
      "description": "1-based position index for referencing parent step"
     },
     "branchPath": {
      "type": "string",
      "enum": [
       "yes",
       "no"
      ]
     },
     "order": {
      "type": "integer",
      "description": "Position within parent. Omit it and steps run in the order they are listed."
     },
     "type": {
      "type": "string"
     },
     "config": {
      "type": "object",
      "description": "Step-specific configuration"
     },
     "urgency": {
      "type": "string",
      "enum": [
       "buffered",
       "immediate"
      ]
     },
     "exitConditions": {
      "type": "array",
      "items": {
       "type": "object"
      }
     }
    },
    "required": [
     "type",
     "config"
    ]
   },
   "send.automations.TriggerCatalog": {
    "type": "object",
    "properties": {
     "triggerTypes": {
      "type": "array",
      "description": "Available trigger types with descriptions",
      "items": {}
     },
     "eventNames": {
      "type": "array",
      "description": "All available domain event names for event-type triggers",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "send.automations.StepTypeCatalogItem": {
    "type": "object",
    "properties": {
     "type": {
      "type": "string",
      "description": "Step type identifier"
     },
     "description": {
      "type": "string",
      "description": "Human-readable description"
     },
     "category": {
      "type": "string",
      "description": "Step category for UI grouping",
      "enum": [
       "messaging",
       "flow",
       "action",
       "integration",
       "notification"
      ]
     }
    }
   },
   "send.automations.Enrollment": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "automationId": {
      "type": "integer",
      "readOnly": true
     },
     "studentId": {
      "type": "integer",
      "readOnly": true
     },
     "studentName": {
      "type": "string",
      "description": "Joined firstName + lastName",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "enum": [
       "active",
       "waiting",
       "completed",
       "cancelled",
       "errored"
      ]
     },
     "enrolledOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "lastStepOn": {
      "type": "integer",
      "description": "Nullable",
      "format": "unix-seconds"
     },
     "nextStepOn": {
      "type": "integer",
      "description": "When the next step is scheduled to run (null for completed/cancelled)",
      "format": "unix-seconds"
     },
     "completedOn": {
      "type": "integer",
      "description": "Nullable",
      "format": "unix-seconds"
     },
     "cancelledOn": {
      "type": "integer",
      "description": "Nullable",
      "format": "unix-seconds"
     },
     "cancelReason": {
      "type": "string",
      "description": "Reason for cancellation (e.g. 'admin_cancelled', 'exit_condition'). Nullable."
     },
     "currentStepId": {
      "type": "integer",
      "description": "Step currently in progress. Nullable."
     },
     "nextStepId": {
      "type": "integer",
      "description": "Next step queued for this enrollment. Nullable."
     },
     "triggerEventId": {
      "type": "integer",
      "description": "ID of the event that caused enrollment (0 for manual). Nullable."
     },
     "etag": {
      "type": "string",
      "description": "Per-row optimistic-concurrency token (format \"v<timestamp>\"). Send back as If-Match on cancelEnrollment.",
      "readOnly": true
     }
    }
   },
   "send.automations.ManualEnrollResult": {
    "type": "object",
    "properties": {
     "enrolled": {
      "type": "integer",
      "description": "Count of students newly enrolled (or that would be enrolled in preview)"
     },
     "skipped": {
      "type": "integer",
      "description": "Count of students skipped"
     },
     "details": {
      "type": "array",
      "description": "Per-student outcome: { studentId, status: 'enrolled' | 'skipped', reason? } where reason explains the skip (already_enrolled, opted_out, blocked_by_reenrollment_policy, not_found, etc).",
      "items": {
       "type": "object"
      }
     }
    }
   },
   "send.automations.EnrollmentStats": {
    "type": "object",
    "properties": {
     "totalEnrollments": {
      "type": "integer",
      "description": "Total enrollments across all statuses"
     },
     "byStatus": {
      "type": "object",
      "description": "Map of status to count, e.g. { active: 12, waiting: 3, completed: 47, cancelled: 5, errored: 0 }"
     },
     "completionRate": {
      "type": "integer",
      "description": "Percentage of enrollments completed (0 to 100)"
     },
     "totalSends": {
      "type": "integer",
      "description": "Aggregate messages sent"
     },
     "totalOpens": {
      "type": "integer",
      "description": "Aggregate email opens"
     },
     "totalClicks": {
      "type": "integer",
      "description": "Aggregate link clicks"
     }
    }
   },
   "send.automations.StepLog": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "enrollmentId": {
      "type": "integer",
      "readOnly": true
     },
     "stepId": {
      "type": "integer",
      "readOnly": true
     },
     "action": {
      "type": "string",
      "description": "What the engine did at this step",
      "enum": [
       "executed",
       "skipped",
       "branched_yes",
       "branched_no",
       "cancelled_by_exit"
      ]
     },
     "result": {
      "type": "string",
      "description": "Outcome of the step",
      "enum": [
       "success",
       "failed",
       "opted_out",
       "rate_limited",
       "anti_fatigue_suppressed",
       "combined_in_digest"
      ]
     },
     "deliveryId": {
      "type": "integer",
      "description": "Linked delivery log entry for messaging steps. Nullable."
     },
     "executedOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "durationMs": {
      "type": "integer",
      "description": "Step execution wall time"
     },
     "detail": {
      "type": "object",
      "description": "Free-form JSON with step-specific debug info (template ID, branch condition result, error message, etc.)"
     }
    }
   },
   "send.automations.ShareLinkState": {
    "type": "object",
    "properties": {
     "automationId": {
      "type": "integer",
      "readOnly": true
     },
     "enabled": {
      "type": "boolean",
      "description": "Whether the share link is live"
     },
     "shareSlug": {
      "type": "string",
      "description": "Stable per-automation slug. Generated on first enable. Nullable."
     },
     "shareUrl": {
      "type": "string",
      "description": "Full public share URL including ?ref= attribution slug. Null when disabled.",
      "format": "url"
     },
     "shareTitle": {
      "type": "string",
      "description": "Public title (max 200). Nullable."
     },
     "shareDescription": {
      "type": "string",
      "description": "Public description (max 1000). Nullable."
     },
     "ogImagePath": {
      "type": "string",
      "description": "Storage key for the rendered OG image. Nullable."
     },
     "ogImageUrl": {
      "type": "string",
      "description": "Resolved OG image URL for social previews. Nullable.",
      "format": "url"
     },
     "publisherRefSlug": {
      "type": "string",
      "description": "School-level ref slug used in attribution links. Nullable."
     },
     "publisherSchoolName": {
      "type": "string",
      "description": "School display name for 'Shared by …' line. Nullable."
     },
     "publisherAttributionEnabled": {
      "type": "boolean",
      "description": "Whether attribution is shown publicly (default: true)"
     }
    }
   },
   "send-chat.Conversation": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "schoolId": {
      "type": "number"
     },
     "studentId": {
      "type": "number"
     },
     "status": {
      "type": "string",
      "enum": [
       "active",
       "closed",
       "snoozed"
      ]
     },
     "isPriority": {
      "type": "boolean"
     },
     "snoozeUntil": {
      "type": "number",
      "description": "Unix seconds; nullable"
     },
     "studentTypingUntil": {
      "type": "number",
      "description": "Nullable"
     },
     "adminTypingUntil": {
      "type": "number",
      "description": "Nullable"
     },
     "pinnedMessageId": {
      "type": "number",
      "description": "Optional message id pinned in this conversation; nullable."
     },
     "createdOn": {
      "type": "number"
     },
     "updatedOn": {
      "type": "number"
     }
    }
   },
   "send-chat.ConversationWithStudent": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "status": {
      "type": "string"
     },
     "isPriority": {
      "type": "boolean"
     },
     "student": {
      "type": "object",
      "description": "{ id, firstName, lastName, emailAddress }"
     },
     "unreadCount": {
      "type": "number"
     },
     "lastMessagePreview": {
      "type": "string",
      "description": "Truncated to 140 chars; nullable"
     },
     "lastMessageAt": {
      "type": "number",
      "description": "Unix seconds; nullable"
     },
     "updatedOn": {
      "type": "number"
     }
    }
   },
   "send-chat.Message": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "conversationId": {
      "type": "number"
     },
     "senderType": {
      "type": "string",
      "enum": [
       "admin",
       "student"
      ]
     },
     "senderUserId": {
      "type": "number",
      "description": "Admin user id; nullable for student"
     },
     "studentId": {
      "type": "number"
     },
     "kind": {
      "type": "string",
      "enum": [
       "message",
       "note"
      ]
     },
     "message": {
      "type": "string"
     },
     "readOn": {
      "type": "number",
      "description": "Unix seconds; nullable (admin-sent never has readOn per legacy)"
     },
     "createdOn": {
      "type": "number"
     },
     "attachments": {
      "type": "array",
      "description": "Attachments on this message; absent when empty",
      "items": {}
     }
    }
   },
   "send-chat.Attachment": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "filename": {
      "type": "string"
     },
     "mimeType": {
      "type": "string"
     },
     "sizeBytes": {
      "type": "number"
     },
     "width": {
      "type": "number",
      "description": "Image width px; null for non-images"
     },
     "height": {
      "type": "number",
      "description": "Image height px; null for non-images"
     },
     "hasThumbnail": {
      "type": "boolean",
      "description": "True if a thumbnail variant is servable via ?variant=thumb. Always false once purgedOn is set."
     },
     "purgedOn": {
      "type": "number",
      "description": "Unix seconds when this attachment was auto-purged (orphan cleanup, retention sweep, or quota trim). Non-null = bytes are gone, download returns 404, but the metadata stays so UI can render '(attachment removed)' instead of a broken image."
     }
    }
   },
   "send-chat.ReclaimResult": {
    "type": "object",
    "properties": {
     "purgedCount": {
      "type": "number"
     },
     "freedBytes": {
      "type": "number"
     },
     "purgedIds": {
      "type": "array",
      "description": "IDs of purged attachments; callers can refresh specific message views",
      "items": {}
     },
     "usageBefore": {
      "type": "object",
      "description": "StorageUsage shape"
     },
     "usageAfter": {
      "type": "object",
      "description": "StorageUsage shape"
     },
     "message": {
      "type": "string"
     }
    }
   },
   "send-chat.StorageUsage": {
    "type": "object",
    "properties": {
     "studentFilesBytes": {
      "type": "number"
     },
     "chatAttachmentsBytes": {
      "type": "number"
     },
     "totalBytes": {
      "type": "number"
     },
     "limitBytes": {
      "type": "number"
     },
     "pctUsed": {
      "type": "number"
     },
     "overQuota": {
      "type": "boolean"
     },
     "availableBytes": {
      "type": "number",
      "description": "Bytes free; negative if already over quota"
     }
    }
   },
   "send-chat.MessagesPage": {
    "type": "object",
    "properties": {
     "messages": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/send-chat.Message"
      }
     },
     "olderCursor": {
      "type": "number",
      "description": "Nullable"
     },
     "hasMore": {
      "type": "boolean"
     }
    }
   },
   "send-chat.SendMessageResult": {
    "type": "object",
    "properties": {
     "conversationId": {
      "type": "number"
     },
     "messageId": {
      "type": "number"
     },
     "conversationCreated": {
      "type": "boolean"
     },
     "attachmentsLinked": {
      "type": "number",
      "description": "How many of the requested attachmentIds were linked. < requested count indicates stale/foreign/deleted IDs."
     }
    }
   },
   "send-chat.MarkReadResult": {
    "type": "object",
    "properties": {
     "markedCount": {
      "type": "number"
     },
     "message": {
      "type": "string"
     }
    }
   },
   "send-chat.TypingResult": {
    "type": "object",
    "properties": {
     "expiresAt": {
      "type": "number"
     }
    }
   },
   "send-chat.UnreadCount": {
    "type": "object",
    "properties": {
     "count": {
      "type": "number"
     }
    }
   },
   "send-chat.PushKey": {
    "type": "object",
    "properties": {
     "publicKey": {
      "type": "string"
     }
    }
   },
   "send-chat.SubscribeResult": {
    "type": "object",
    "properties": {
     "subscriptionId": {
      "type": "number"
     },
     "activeSubscriptions": {
      "type": "number"
     },
     "message": {
      "type": "string"
     }
    }
   },
   "send-social.Connection": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "platform": {
      "type": "string",
      "enum": [
       "facebook",
       "instagram"
      ]
     },
     "platformAccountId": {
      "type": "string"
     },
     "accountName": {
      "type": "string",
      "description": "Nullable"
     },
     "accountAvatarUrl": {
      "type": "string",
      "description": "Nullable"
     },
     "status": {
      "type": "string",
      "enum": [
       "active",
       "expired",
       "revoked"
      ]
     },
     "connectedOn": {
      "type": "number"
     },
     "tokenExpiresOn": {
      "type": "number",
      "description": "Unix seconds; null for non-expiring tokens (Facebook Page tokens)"
     }
    }
   },
   "send-social.Post": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "content": {
      "type": "string"
     },
     "mediaIds": {
      "type": "array",
      "items": {}
     },
     "targets": {
      "type": "array",
      "description": "[{ connectionId, platform, platformAccountId, accountName, result? }] where result = { status, platformPostId?, permalink?, error? }",
      "items": {}
     },
     "status": {
      "type": "string",
      "enum": [
       "draft",
       "scheduled",
       "publishing",
       "published",
       "partial",
       "failed"
      ]
     },
     "scheduledOn": {
      "type": "number",
      "description": "Nullable"
     },
     "publishedOn": {
      "type": "number",
      "description": "Nullable"
     },
     "createdOn": {
      "type": "number"
     }
    }
   },
   "send-social.Media": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "filename": {
      "type": "string"
     },
     "mimeType": {
      "type": "string"
     },
     "sizeBytes": {
      "type": "number"
     },
     "width": {
      "type": "number",
      "description": "Nullable (non-images)"
     },
     "height": {
      "type": "number",
      "description": "Nullable (non-images)"
     },
     "tags": {
      "type": "array",
      "items": {}
     },
     "previewUrl": {
      "type": "string",
      "description": "Signed URL, 10-min expiry. Null if deleted."
     },
     "thumbnailUrl": {
      "type": "string",
      "description": "Signed URL to thumbnail (images only). Null otherwise."
     },
     "createdOn": {
      "type": "number"
     },
     "lastUsedOn": {
      "type": "number",
      "description": "Nullable"
     },
     "deleted": {
      "type": "boolean",
      "description": "True = bucket bytes gone, tombstone only"
     }
    }
   },
   "send-social.StorageUsage": {
    "type": "object",
    "properties": {
     "studentFilesBytes": {
      "type": "number"
     },
     "chatAttachmentsBytes": {
      "type": "number"
     },
     "totalBytes": {
      "type": "number"
     },
     "limitBytes": {
      "type": "number",
      "description": "10 GB cap on the base tier"
     },
     "pctUsed": {
      "type": "number",
      "description": "0 to 100"
     },
     "overQuota": {
      "type": "boolean"
     },
     "availableBytes": {
      "type": "number",
      "description": "Negative if over quota"
     }
    }
   },
   "send-segments.Segment": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "schoolId": {
      "type": "number"
     },
     "name": {
      "type": "string"
     },
     "description": {
      "type": "string",
      "description": "Nullable"
     },
     "category": {
      "type": "string",
      "description": "Nullable; drives list grouping",
      "enum": [
       "retention",
       "acquisition",
       "engagement",
       "lifecycle"
      ]
     },
     "rules": {
      "type": "object",
      "description": "AND/OR rule tree: see RuleTree model below for the recursive shape."
     },
     "sentence": {
      "type": "string",
      "description": "English rendering of the rule tree (e.g. \"Students who attended fewer than 3 classes in the last 30 days\"). Computed server-side."
     },
     "isDynamic": {
      "type": "boolean"
     },
     "cachedCount": {
      "type": "number",
      "description": "Nullable; set by a live count or refresh"
     },
     "cachedOn": {
      "type": "number",
      "description": "Unix seconds; nullable"
     },
     "createdOn": {
      "type": "number",
      "description": "Unix seconds"
     },
     "updatedOn": {
      "type": "number",
      "description": "Unix seconds; nullable. Source of the ETag (\"v<updatedOn>\" or \"v<createdOn>\" for never-updated rows) used for optimistic concurrency on PATCH."
     }
    }
   },
   "send-segments.RuleTree": {
    "type": "object",
    "properties": {
     "type": {
      "type": "string",
      "description": "Group nodes only: combinator for the child rules.",
      "enum": [
       "AND",
       "OR"
      ]
     },
     "rules": {
      "type": "array",
      "description": "Group nodes only: array of child nodes (each is itself a RuleTree). Min 1 child per group.",
      "items": {}
     },
     "field": {
      "type": "string",
      "description": "Leaf nodes only: field ID from /v1/send/segments/fields catalog (e.g. \"student.type\", \"attendance.last_30_days\")."
     },
     "operator": {
      "type": "string",
      "description": "Leaf nodes only: comparison operator. Must be in the field's allowed operators list (see /fields).",
      "enum": [
       "eq",
       "ne",
       "in",
       "not_in",
       "contains",
       "gt",
       "lt",
       "gte",
       "lte",
       "exists",
       "not_exists"
      ]
     },
     "value": {
      "type": [
       "object",
       "null"
      ],
      "description": "Leaf nodes only: the value to compare against, in the field's own type: a string, a number, a boolean, an array for in/not_in (one element is fine, none is refused) or null for exists/not_exists."
     }
    }
   },
   "send-segments.SegmentFieldCatalog": {
    "type": "object",
    "properties": {
     "fields": {
      "type": "array",
      "description": "All queryable fields",
      "items": {}
     },
     "byCategory": {
      "type": "object",
      "description": "Fields grouped by UI category"
     },
     "capabilities": {
      "type": "object",
      "description": "Same shape as SegmentCapabilities: embedded for convenience."
     }
    }
   },
   "send-segments.SegmentCapabilities": {
    "type": "object",
    "properties": {
     "ranks": {
      "type": "boolean"
     },
     "styles": {
      "type": "boolean"
     },
     "families": {
      "type": "boolean"
     },
     "subscriptions": {
      "type": "boolean"
     },
     "bookings": {
      "type": "boolean"
     },
     "leadStages": {
      "type": "boolean"
     },
     "sendActivity": {
      "type": "boolean"
     },
     "tags": {
      "type": "boolean"
     }
    }
   },
   "send-segments.SegmentCount": {
    "type": "object",
    "properties": {
     "segmentId": {
      "type": "number"
     },
     "count": {
      "type": "number"
     },
     "evaluatedOn": {
      "type": "number",
      "description": "Unix seconds"
     }
    }
   },
   "send-segments.SegmentRefreshResult": {
    "type": "object",
    "properties": {
     "segmentId": {
      "type": "number"
     },
     "previousCount": {
      "type": "number",
      "description": "Cached count before this refresh; nullable on first-ever refresh"
     },
     "count": {
      "type": "number",
      "description": "Fresh count after evaluation"
     },
     "changed": {
      "type": "boolean",
      "description": "True when previousCount !== count"
     },
     "delta": {
      "type": "number",
      "description": "count - previousCount; null when previousCount was null"
     },
     "evaluatedOn": {
      "type": "number",
      "description": "Unix seconds"
     }
    }
   },
   "send-segments.SegmentPreview": {
    "type": "object",
    "properties": {
     "segmentId": {
      "type": "number"
     },
     "students": {
      "type": "array",
      "description": "Matching students (id + name)",
      "items": {}
     },
     "nextCursor": {
      "type": "number",
      "description": "Last student ID; nullable when no more pages"
     },
     "hasMore": {
      "type": "boolean"
     }
    }
   },
   "send-segments.SegmentRulesCount": {
    "type": "object",
    "properties": {
     "count": {
      "type": "number",
      "description": "Live count for the unsaved rule tree"
     },
     "sentence": {
      "type": "string",
      "description": "English rendering of the rules"
     },
     "evaluatedOn": {
      "type": "number",
      "description": "Unix seconds"
     }
    }
   },
   "send-segments.SegmentRulesPreview": {
    "type": "object",
    "properties": {
     "students": {
      "type": "array",
      "description": "Matching students (id + name)",
      "items": {}
     },
     "nextCursor": {
      "type": "number",
      "description": "Last student ID; nullable when no more pages"
     },
     "hasMore": {
      "type": "boolean"
     }
    }
   },
   "send-segments.RankAudienceCounts": {
    "type": "object",
    "properties": {
     "counts": {
      "type": "object",
      "description": "Rank ID -> student count"
     }
    }
   },
   "send-segments.RankAudienceMembers": {
    "type": "object",
    "properties": {
     "students": {
      "type": "array",
      "description": "Students (id + name)",
      "items": {}
     },
     "nextCursor": {
      "type": "number",
      "description": "Last student ID; nullable when no more pages"
     },
     "hasMore": {
      "type": "boolean"
     },
     "total": {
      "type": "number",
      "description": "Students at any of the ranks, each counted once"
     }
    }
   },
   "send-segments.SegmentSnapshotResult": {
    "type": "object",
    "properties": {
     "segmentId": {
      "type": "number"
     },
     "count": {
      "type": "number",
      "description": "Members captured in the snapshot"
     },
     "truncated": {
      "type": "boolean",
      "description": "True if segment matched more than the diff-safe cap"
     },
     "snapshotAt": {
      "type": "number",
      "description": "Unix seconds"
     },
     "message": {
      "type": "string"
     }
    }
   },
   "send-analytics.FeedUrl": {
    "type": "object",
    "properties": {
     "url": {
      "type": "string",
      "description": "The subscribable feed URL",
      "format": "url"
     }
    }
   },
   "send-analytics.Overview": {
    "type": "object",
    "properties": {
     "range": {
      "type": "object",
      "description": "{ from, to } unix seconds"
     },
     "totals": {
      "type": "object",
      "description": "{ sent, delivered, skipped, opened, clicked, bounced, failed }. sent excludes skipped rows (records of non-delivery); deliveryRate = delivered / sent"
     },
     "rates": {
      "type": "object",
      "description": "{ deliveryRate, openRate, clickRate, bounceRate } as 0-1 floats"
     },
     "byChannel": {
      "type": "object",
      "description": "{ [channel]: { sent, delivered, skipped } }"
     },
     "activeAutomations": {
      "type": "number"
     },
     "scheduledSocialPosts": {
      "type": "number"
     },
     "publishedSocialPosts": {
      "type": "number",
      "description": "Social posts published (or partly published) in the range"
     }
    }
   },
   "send-analytics.EmailAnalytics": {
    "type": "object",
    "properties": {
     "range": {
      "type": "object"
     },
     "counts": {
      "type": "object"
     },
     "rates": {
      "type": "object"
     },
     "daily": {
      "type": "array",
      "description": "[{ date: 'YYYY-MM-DD', sent, opened, clicked }]",
      "items": {}
     }
    }
   },
   "send-analytics.SmsAnalytics": {
    "type": "object",
    "properties": {
     "range": {
      "type": "object"
     },
     "counts": {
      "type": "object"
     },
     "rates": {
      "type": "object"
     },
     "totalCostSubunits": {
      "type": "number",
      "description": "Subunit currency (cents/pence)"
     }
    }
   },
   "send-analytics.ChatAnalytics": {
    "type": "object",
    "properties": {
     "range": {
      "type": "object"
     },
     "messagesSent": {
      "type": "number"
     },
     "messagesReceived": {
      "type": "number"
     },
     "avgResponseTimeSec": {
      "type": "number",
      "description": "Null until join is wired"
     }
    }
   },
   "send-analytics.SocialAnalytics": {
    "type": "object",
    "properties": {
     "range": {
      "type": "object"
     },
     "totals": {
      "type": "object",
      "description": "Counts by status"
     }
    }
   },
   "send-analytics.AutomationFunnels": {
    "type": "object",
    "properties": {
     "range": {
      "type": "object"
     },
     "items": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/send-analytics.AutomationFunnelRow"
      }
     }
    }
   },
   "send-analytics.AutomationFunnelRow": {
    "type": "object",
    "properties": {
     "automationId": {
      "type": "number"
     },
     "name": {
      "type": "string"
     },
     "status": {
      "type": "string"
     },
     "enrollments": {
      "type": "number",
      "description": "Started within range"
     },
     "activeEnrollments": {
      "type": "number",
      "description": "Currently active (all-time)"
     },
     "completed": {
      "type": "number",
      "description": "All-time total"
     },
     "cancelled": {
      "type": "number"
     },
     "stepsExecuted": {
      "type": "number",
      "description": "Step log count within range"
     }
    }
   },
   "send-analytics.StudentScore": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "number"
     },
     "score": {
      "type": "number",
      "description": "0-100"
     },
     "inputs": {
      "type": "object",
      "description": "{ delivered14d, opened14d, clicked14d }"
     }
    }
   },
   "send-analytics.ScheduleList": {
    "type": "object",
    "properties": {
     "range": {
      "type": "object"
     },
     "items": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/send-analytics.ScheduleItem"
      }
     },
     "truncated": {
      "type": "boolean",
      "description": "True if any per-kind result set hit its 500-item cap"
     },
     "truncatedKinds": {
      "type": "array",
      "description": "Which kinds were truncated, e.g. ['automation_step']",
      "items": {}
     }
    }
   },
   "send-analytics.ScheduleItem": {
    "type": "object",
    "properties": {
     "kind": {
      "type": "string",
      "enum": [
       "social_post",
       "automation_step"
      ]
     },
     "id": {
      "type": "number"
     },
     "scheduledOn": {
      "type": "number"
     },
     "title": {
      "type": "string"
     },
     "detail": {
      "type": "string"
     },
     "adminPath": {
      "type": "string",
      "description": "Admin-UI path, for deep linking"
     }
    }
   },
   "send-library.ImportResult": {
    "type": "object",
    "properties": {
     "automationId": {
      "type": "number",
      "description": "FK to send_automations (status=draft on first import)"
     },
     "stepCount": {
      "type": "number"
     },
     "triggerCount": {
      "type": "number"
     },
     "reused": {
      "type": "boolean",
      "description": "True when this call hit an existing automation via idempotencyKey instead of inserting. Always false when idempotencyKey was omitted."
     },
     "alreadyInstalled": {
      "type": "boolean",
      "description": "True when the school already has this template installed (matched by libraryRef) and force was not set: the returned automationId is the EXISTING install, nothing was created."
     },
     "overlaps": {
      "type": "array",
      "description": "Installed automations that cover the same student moment as this template (declared in seed metadata). Each entry: {ref, automationId, name, status, reason}. Show these so the admin does not install two automations for the same moment.",
      "items": {}
     }
    }
   },
   "send-library.ImportPreview": {
    "type": "object",
    "properties": {
     "templateId": {
      "type": "string"
     },
     "templateName": {
      "type": "string"
     },
     "resolvedName": {
      "type": "string",
      "description": "What the imported automation's name would be (input.name ?? template.name)"
     },
     "category": {
      "type": "string",
      "enum": [
       "onboarding",
       "retention",
       "milestones",
       "billing",
       "marketing",
       "operational"
      ]
     },
     "audience": {
      "type": "string",
      "enum": [
       "student",
       "admin",
       "instructor"
      ]
     },
     "triggerType": {
      "type": "string",
      "enum": [
       "event",
       "schedule",
       "segment_entry"
      ]
     },
     "stepCount": {
      "type": "number"
     },
     "reviewBeforeLaunch": {
      "type": "boolean"
     },
     "recipientFieldRequired": {
      "type": "string",
      "description": "Which recipient field the template's steps can use (derived from steps that send to admins). null when no step routes to admins. Advisory: the school owner is the delivery fallback.",
      "enum": [
       "recipientUserIds",
       "recipientInstructorIds"
      ]
     },
     "wouldReuseExisting": {
      "type": "boolean",
      "description": "True iff idempotencyKey is set AND an automation with that key already exists."
     },
     "existingAutomationId": {
      "type": "number",
      "description": "Present only when wouldReuseExisting=true."
     }
    }
   },
   "send-library.LibraryListItem": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "category": {
      "type": "string",
      "enum": [
       "onboarding",
       "retention",
       "milestones",
       "billing",
       "marketing",
       "operational"
      ]
     },
     "summary": {
      "type": "string"
     },
     "tags": {
      "type": "array",
      "items": {}
     },
     "audience": {
      "type": "string",
      "enum": [
       "student",
       "admin",
       "instructor"
      ]
     },
     "reviewBeforeLaunch": {
      "type": "boolean"
     }
    }
   },
   "send-library.LibraryTemplate": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "category": {
      "type": "string",
      "enum": [
       "onboarding",
       "retention",
       "milestones",
       "billing",
       "marketing",
       "operational"
      ]
     },
     "description": {
      "type": "string"
     },
     "summary": {
      "type": "string",
      "description": "Short marketing blurb shown in catalog cards"
     },
     "longDescription": {
      "type": "string",
      "description": "Optional rich explanation (flow, conversion bets, etc.); surfaced on detail pages"
     },
     "bestFor": {
      "type": "string",
      "description": "Optional free-text guidance for the admin on when to pick this blueprint"
     },
     "tags": {
      "type": "array",
      "items": {}
     },
     "audience": {
      "type": "string",
      "enum": [
       "student",
       "admin",
       "instructor"
      ]
     },
     "trigger": {
      "$ref": "#/components/schemas/send-library.LibraryTrigger"
     },
     "steps": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/send-library.LibraryStep"
      }
     },
     "reviewBeforeLaunch": {
      "type": "boolean"
     }
    }
   },
   "send-library.LibraryTrigger": {
    "type": "object",
    "properties": {
     "type": {
      "type": "string",
      "description": "event=fired by a DomainEvent; schedule=CRON; segment_entry=fired when a student enters a segment (note: segment_entry blueprints can't be pre-seeded since segments are per-school).",
      "enum": [
       "event",
       "schedule",
       "segment_entry"
      ]
     },
     "eventName": {
      "type": "string",
      "description": "DomainEvents key. Required when type='event'."
     },
     "schedule": {
      "type": "string",
      "description": "CRON expression in school local timezone unless documented otherwise. Required when type='schedule'."
     },
     "conditions": {
      "type": "object",
      "description": "Optional gating expression evaluated at trigger time"
     },
     "reEnrollmentPolicy": {
      "type": "string",
      "description": "How often a student can re-enter this automation. Default: once.",
      "enum": [
       "once",
       "once_per_period",
       "unlimited"
      ]
     },
     "reEnrollmentPeriodDays": {
      "type": "number",
      "description": "Cooldown in days when policy='once_per_period'."
     }
    },
    "required": [
     "type"
    ]
   },
   "send-library.LibraryStep": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Blueprint-local key. Resolved to a numeric DB id at import time so children can reference parents by string before the parent has an id."
     },
     "parentId": {
      "type": "string",
      "description": "Blueprint-local key of the parent step (for branched flows)"
     },
     "branchPath": {
      "type": "string",
      "description": "Which branch of the parent's condition this step belongs to",
      "enum": [
       "yes",
       "no"
      ]
     },
     "order": {
      "type": "number"
     },
     "type": {
      "type": "string",
      "description": "Step type. One of the values supported by send_automation_steps.type (send_email, send_sms, wait, condition, etc.)"
     },
     "config": {
      "type": "object",
      "description": "Step-type-specific configuration (template id, delay duration, condition expression, etc.)"
     },
     "urgency": {
      "type": "string",
      "description": "Default: buffered. immediate skips the digest queue.",
      "enum": [
       "buffered",
       "immediate"
      ]
     },
     "exitConditions": {
      "type": "array",
      "description": "Optional conditions that, if true at step entry, skip the step.",
      "items": {}
     }
    },
    "required": [
     "id",
     "type",
     "config"
    ]
   },
   "send-library.PlaybookListItem": {
    "type": "object",
    "properties": {
     "ref": {
      "type": "string",
      "description": "Stable identifier, e.g. playbook.payment_defence"
     },
     "version": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "lane": {
      "type": "string",
      "enum": [
       "foundations",
       "payment_defence",
       "growth",
       "retention",
       "instructor"
      ]
     },
     "summary": {
      "type": "string"
     },
     "segmentCount": {
      "type": "number"
     },
     "templateCount": {
      "type": "number"
     }
    }
   },
   "send-library.LibraryPlaybook": {
    "type": "object",
    "properties": {
     "ref": {
      "type": "string"
     },
     "version": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "lane": {
      "type": "string"
     },
     "summary": {
      "type": "string"
     },
     "longDescription": {
      "type": "string"
     },
     "segmentRefs": {
      "type": "array",
      "description": "Library segment refs the bundle installs",
      "items": {}
     },
     "templateRefs": {
      "type": "array",
      "description": "Library template refs the bundle imports",
      "items": {}
     },
     "slots": {
      "type": "array",
      "description": "Slots collected once at install time and applied across all templates in the bundle.",
      "items": {}
     }
    }
   },
   "send-library.PlaybookInstallResult": {
    "type": "object",
    "properties": {
     "playbookRef": {
      "type": "string"
     },
     "playbookVersion": {
      "type": "string"
     },
     "segments": {
      "type": "array",
      "description": "Per-segment install outcome: {ref, segmentId, name, reused}. `reused=true` means the school already had a segment with that library_ref.",
      "items": {}
     },
     "templates": {
      "type": "array",
      "description": "Per-template import outcome: {ref, automationId, name, reused}. `reused=true` means the idempotency key matched an existing automation.",
      "items": {}
     },
     "skipped": {
      "type": "object",
      "description": "Refs intentionally skipped because they require the not-yet-shipped Churn Insights engine: {segmentRefs: string[], templateRefs: string[]}."
     }
    }
   },
   "send.templates.Template": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Template ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Template name"
     },
     "channel": {
      "type": "string",
      "description": "Channel (set on create, immutable)",
      "enum": [
       "email",
       "sms",
       "chat",
       "social"
      ]
     },
     "category": {
      "type": "string",
      "description": "Template category",
      "enum": [
       "marketing",
       "transactional",
       "notification",
       "automation"
      ]
     },
     "content": {
      "type": "string",
      "description": "Template content. For channel=email: a JSON-serialized EmailDocument (see the EmailDocument model in GET /v1/send/_schema). For channel=sms/chat/social: plain text."
     },
     "mergeTagsUsed": {
      "type": "array",
      "description": "Merge tag names referenced in content. Auto-extracted from `{{tag}}` and `{{ dotted.path }}` patterns. See GET /v1/send/merge-tags for the catalog of resolver-bound tags (anything else renders literally).",
      "items": {
       "type": "string"
      }
     },
     "thumbnail": {
      "type": "string",
      "description": "Auto-generated preview image (nullable). Currently always null: thumbnail generation is not yet implemented. When it ships, this will be a Railway bucket path (e.g. \"templates/123/thumb.jpg\") fetched the same way as chat attachments. Do not depend on this field today.",
      "readOnly": true,
      "format": "url-path"
     },
     "isSystem": {
      "type": "boolean",
      "description": "Martialytics-provided template. Editability depends on `templateKey`: when `templateKey` is null, the row is a curated-library system template (read-only; duplicate to edit). When `templateKey` is set, the row is a per-school auto-seeded default that the school owner can edit, soft-delete, and reset.",
      "readOnly": true
     },
     "templateKey": {
      "type": "string",
      "description": "Stable lookup handle for system-seeded default templates that the platform code finds by name. Null on user-authored and curated-library templates. Examples: `bookings.public_confirmation`, `bookings.public_school_notification`, `bookings.capacity_inquiry`. When non-null on an `isSystem=true` row, the template is editable by the school.",
      "readOnly": true
     },
     "usageCount": {
      "type": "integer",
      "description": "Number of times this template has been used",
      "readOnly": true
     },
     "lastUsedOn": {
      "type": "integer",
      "description": "Last time this template was used to send a message",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "updatedOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "send.templates.TemplateValidationReport": {
    "type": "object",
    "properties": {
     "valid": {
      "type": "boolean",
      "description": "True when there are zero errors. Warnings do not affect validity."
     },
     "errors": {
      "type": "array",
      "description": "Hard problems: content won't send/render at all. Each item: { field, message, code }. Codes: INVALID_JSON, INVALID_EMAIL_DOCUMENT, SMS_TOO_LONG.",
      "items": {
       "type": "object"
      }
     },
     "warnings": {
      "type": "array",
      "description": "Soft problems: send proceeds but with caveats. Codes: UNKNOWN_MERGE_TAG (no registry entry: typo or removed tag), AUDIENCE_MISMATCH (tag exists but targets a different audience than the template; both render literally at send time), SMS_HIGH_SEGMENT_COUNT.",
      "items": {
       "type": "object"
      }
     },
     "mergeTags": {
      "type": "object",
      "description": "Merge-tag analysis with three buckets so an agent can distinguish typos from audience misconfiguration: { extracted: string[], found: string[], unknown: string[], audienceMismatches: string[], totalOccurrences: number }. `extracted` is every {{tag}} / {{ dotted.path }} the broad extractor caught; `found` is the engine-resolvable subset matching this audience; `unknown` is tags the engine doesn't know (will render literally); `audienceMismatches` is tags that exist but target a different audience (also render literally). `totalOccurrences` counts duplicates."
     },
     "sms": {
      "type": "object",
      "description": "Present only when channel=sms. { length, segments, charLimit, encoding }."
     },
     "email": {
      "type": "object",
      "description": "Present only when channel=email and content parsed. { blockCount }."
     }
    }
   },
   "send.templates.TemplateListItem": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "name": {
      "type": "string"
     },
     "channel": {
      "type": "string",
      "enum": [
       "email",
       "sms",
       "chat",
       "social"
      ]
     },
     "category": {
      "type": "string",
      "enum": [
       "marketing",
       "transactional",
       "notification",
       "automation"
      ]
     },
     "thumbnail": {
      "type": "string",
      "readOnly": true
     },
     "isSystem": {
      "type": "boolean",
      "readOnly": true
     },
     "templateKey": {
      "type": "string",
      "description": "Stable lookup handle for system-seeded defaults; null on user-authored and curated-library templates.",
      "readOnly": true
     },
     "usageCount": {
      "type": "integer",
      "readOnly": true
     },
     "lastUsedOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "updatedOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "send-credits.Balance": {
    "type": "object",
    "properties": {
     "balance": {
      "type": "number"
     },
     "autoRecharge": {
      "type": "object",
      "description": "{ enabled, thresholdCredits, topupCredits }"
     }
    }
   },
   "send-credits.AutoRecharge": {
    "type": "object",
    "properties": {
     "enabled": {
      "type": "boolean"
     },
     "thresholdCredits": {
      "type": "number"
     },
     "topupCredits": {
      "type": "number"
     }
    }
   },
   "send-credits.PricingEntry": {
    "type": "object",
    "properties": {
     "country": {
      "type": "string",
      "description": "ISO-3166 alpha-2"
     },
     "currency": {
      "type": "string",
      "description": "ISO-4217"
     },
     "subunitsPerSegment": {
      "type": "number",
      "description": "Cost per SMS segment in cents/pence, excluding tax"
     },
     "taxRate": {
      "type": "number",
      "description": "Sales tax added at purchase as a fraction. On the school's own price: 0.1 (GST) when the school is charged Australian GST (its venue is in Australia, its timezone is Australian, or it pays in AUD), else 0. On the price card: what the currency carries by default"
     },
     "taxLabel": {
      "type": "string",
      "description": "Tax name for receipts (\"GST\"); null when no tax applies"
     },
     "label": {
      "type": "string"
     }
    }
   },
   "send-credits.PricingResponse": {
    "type": "object",
    "properties": {
     "schoolCurrency": {
      "type": "string",
      "description": "ISO-4217 the school buys credits in: the one saved in its settings, else a guess from the country of the location it entered, then the country the request came from; USD when neither says."
     },
     "schoolPricing": {
      "type": "object",
      "description": "PricingEntry or null if unsupported"
     },
     "allPricing": {
      "type": "array",
      "items": {
       "$ref": "#/components/schemas/send-credits.PricingEntry"
      }
     }
    }
   },
   "send-credits.PaymentContext": {
    "type": "object",
    "properties": {
     "defaultCard": {
      "type": "object",
      "description": "{ id, brand, last4, expMonth, expYear, isDefault } or null when no saved card"
     },
     "publishableKey": {
      "type": "string",
      "description": "Platform Stripe publishable key; null when unconfigured"
     }
    }
   },
   "send-credits.PurchaseOutcome": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "enum": [
       "succeeded",
       "requires_action",
       "requires_payment_method"
      ]
     },
     "paymentIntentId": {
      "type": "string"
     },
     "credits": {
      "type": "number",
      "description": "Only on status=succeeded"
     },
     "balanceAfter": {
      "type": "number",
      "description": "Only on status=succeeded"
     },
     "clientSecret": {
      "type": "string",
      "description": "Only on requires_action / requires_payment_method"
     },
     "publishableKey": {
      "type": "string",
      "description": "Only on requires_action / requires_payment_method"
     }
    }
   },
   "send-credits.FinalizeResult": {
    "type": "object",
    "properties": {
     "status": {
      "type": "string",
      "enum": [
       "succeeded",
       "pending"
      ]
     },
     "credits": {
      "type": "number",
      "description": "Only on status=succeeded"
     },
     "balanceAfter": {
      "type": "number",
      "description": "Only on status=succeeded"
     },
     "paymentStatus": {
      "type": "string",
      "description": "The PI's Stripe status when status=pending"
     }
    }
   },
   "send-credits.HistoryEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "type": {
      "type": "string",
      "enum": [
       "topup",
       "spend",
       "adjustment",
       "refund"
      ]
     },
     "creditsDelta": {
      "type": "number",
      "description": "Positive = added, negative = spent"
     },
     "balanceAfter": {
      "type": "number"
     },
     "amountSubunits": {
      "type": "number",
      "description": "Nullable; only set for purchases"
     },
     "currency": {
      "type": "string",
      "description": "Nullable"
     },
     "note": {
      "type": "string",
      "description": "Nullable"
     },
     "createdOn": {
      "type": "number"
     }
    }
   },
   "send-marketplace.ListingSummary": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "title": {
      "type": "string"
     },
     "description": {
      "type": "string"
     },
     "category": {
      "type": "string"
     },
     "tags": {
      "type": "array",
      "items": {}
     },
     "publisherSchoolName": {
      "type": "string"
     },
     "publisherSchoolId": {
      "type": "number"
     },
     "statsImports": {
      "type": "number"
     },
     "publishedOn": {
      "type": "number",
      "description": "Unix seconds; nullable"
     },
     "status": {
      "type": "string",
      "enum": [
       "approved"
      ]
     }
    }
   },
   "send-marketplace.ListingDetail": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "title": {
      "type": "string"
     },
     "description": {
      "type": "string"
     },
     "category": {
      "type": "string"
     },
     "tags": {
      "type": "array",
      "items": {}
     },
     "publisherSchoolName": {
      "type": "string"
     },
     "publisherSchoolId": {
      "type": "number"
     },
     "statsImports": {
      "type": "number"
     },
     "publishedOn": {
      "type": "number"
     },
     "status": {
      "type": "string"
     },
     "shape": {
      "type": "object",
      "description": "{ triggerType, triggerEventName, audience, stepTypes[], stepCount }"
     },
     "alreadyImported": {
      "type": "boolean",
      "description": "True iff this school has already imported this listing. With per-listing idempotency, importing again would short-circuit to reused=true rather than create a duplicate."
     },
     "sourceAutomationIdForViewer": {
      "type": "integer",
      "description": "Source automation id. Returned ONLY when the viewer is the publisher (their own school's automation, no cross-school leak), so the UI can deep-link to /send/automations/:id. Null otherwise."
     }
    }
   },
   "send-marketplace.PublishResult": {
    "type": "object",
    "properties": {
     "listingId": {
      "type": "number"
     },
     "status": {
      "type": "string",
      "enum": [
       "pending_review"
      ]
     }
    }
   },
   "send-marketplace.PublishPreview": {
    "type": "object",
    "properties": {
     "wouldPublish": {
      "type": "boolean",
      "description": "True iff zero blockers fire. False means the real call would error. See `blockers` for the exact reasons."
     },
     "blockers": {
      "type": "array",
      "description": "Reasons the real call would fail. Possible types: automation_not_found (404), source_invalid (403; carries automationStatus + automationSource), duplicate (409; carries existingListingId), rate_limited (429; carries limit + nextAvailableTs). Multiple can stack.",
      "items": {}
     },
     "source": {
      "type": "object",
      "description": "Basic info on the source automation when it resolves (id, name, status, source, audience). Null when automation_not_found fires."
     },
     "resolvedShape": {
      "type": "object",
      "description": "Shape hash inputs that would be used for dedup (triggerType, triggerEventName, audience, stepTypes[], stepCount). Null when source can't be resolved."
     },
     "resolvedTitle": {
      "type": "string",
      "description": "Title that would land in the catalogue (echoed from body)."
     },
     "rateLimit": {
      "type": "object",
      "description": "Publisher's current usage in the rolling 24-hour window. Shape: { limit, used, remaining, nextAvailableTs? }."
     }
    }
   },
   "send-marketplace.ImportResult": {
    "type": "object",
    "properties": {
     "listingId": {
      "type": "number"
     },
     "automationId": {
      "type": "number",
      "description": "New send_automations row, status=draft"
     },
     "stepCount": {
      "type": "number"
     },
     "reused": {
      "type": "boolean",
      "description": "True when the (school, source='marketplace', source_ref) tuple matched an existing automation. That one is returned instead of inserting. False on first-time imports. Always check this before assuming a fresh draft was created."
     },
     "notes": {
      "type": "array",
      "description": "Install-time scoping notes. School-scoped ids in step configs do not cross tenants: tag steps are remapped to your tag of the same name, a self-enrol follows the copy, and anything that could not be mapped (a tag you do not have, another of the publisher's automations, a publisher template) is neutralised and listed here as a re-pick before activating. Empty on a clean import and on reuse.",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "send-marketplace.ImportPreview": {
    "type": "object",
    "properties": {
     "wouldImport": {
      "type": "boolean",
      "description": "True when a new automation would be created; false when wouldReuseExisting=true. A dry run that finds a blocker refuses instead of answering."
     },
     "wouldReuseExisting": {
      "type": "boolean",
      "description": "True when the (school, source_ref) tuple matched an existing automation. The real POST would short-circuit and return that automation with reused=true. Other blockers are suppressed when this is true."
     },
     "existingAutomationId": {
      "type": "integer",
      "description": "Set iff wouldReuseExisting=true. The automation that the reuse would return."
     },
     "blockers": {
      "type": "array",
      "description": "Always empty in a dry run's answer: a dry run that finds a blocker (listing_not_found 404, listing_not_importable 409, self_import 409, source_missing 409) refuses with the real call's status instead.",
      "items": {}
     },
     "source": {
      "type": "object",
      "description": "Source automation shape (triggerType, triggerEventName, audience, stepTypes[], stepCount) when it resolves. Null when source is missing."
     },
     "resolvedName": {
      "type": "string",
      "description": "What the new automation's name would be (input.name ?? listing.title). Null when listing doesn't resolve."
     },
     "listing": {
      "type": "object",
      "description": "Listing details echoed for the preview UI: { id, title, publisherSchoolId, publisherSchoolName, status }. Null when listing_not_found fires."
     }
    }
   },
   "send-marketplace.RemoveResult": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "removed": {
      "type": "boolean"
     },
     "alreadyRemoved": {
      "type": "boolean",
      "description": "True when the listing was already in status='removed' before this call. Idempotent: caller's intent ('make it removed') is satisfied either way."
     }
    }
   },
   "send-share-import.SharePreview": {
    "type": "object",
    "properties": {
     "shareSlug": {
      "type": "string",
      "description": "The slug from the URL: echoed back for confirmation"
     },
     "shareTitle": {
      "type": "string",
      "description": "Publisher-authored title shown on the public share page"
     },
     "shareDescription": {
      "type": "string",
      "description": "Publisher-authored description. Nullable when the publisher left it blank."
     },
     "publisherName": {
      "type": "string",
      "description": "Publisher school name for the 'Shared by {school}' byline. Null when the publisher has attribution disabled; UI should hide the byline entirely in that case."
     },
     "publisherRefSlug": {
      "type": "string",
      "description": "Publisher's school ref slug for attribution links. Nullable."
     },
     "ogImageUrl": {
      "type": "string",
      "description": "Resolved OG card image URL. Nullable when the OG renderer hasn't produced an image yet.",
      "format": "url"
     },
     "triggerLabel": {
      "type": "string",
      "description": "Human-readable trigger label (e.g. 'When student.created', 'On schedule'). Shape-only: no eventName / cron expression."
     },
     "stepLabels": {
      "type": "array",
      "description": "Ordered list of root-level step labels (e.g. 'Send email', 'Wait', 'Branch (Yes / No)'). Shape-only: no step config.",
      "items": {
       "description": "string"
      }
     },
     "canImport": {
      "type": "boolean",
      "description": "False when the viewer is the publisher (their own automation; open it directly). True otherwise."
     },
     "automationId": {
      "type": "integer",
      "description": "Source automation ID. Returned ONLY when canImport=false (viewer == publisher) so the UI can deep-link to /send/automations/:id. Null in all other cases: no cross-school ID leak."
     }
    }
   },
   "send-share-import.ImportResult": {
    "type": "object",
    "properties": {
     "automationId": {
      "type": "integer",
      "description": "ID of the DRAFT automation in the caller's school. Open at /send/automations/:id to review and activate. May be a previously-created row when reused=true.",
      "readOnly": true
     },
     "reused": {
      "type": "boolean",
      "description": "True when an idempotencyKey matched an existing share import for this school and that row was returned instead of inserting. Always false when idempotencyKey was omitted. Multiple distinct imports of the same share are allowed by design."
     },
     "notes": {
      "type": "array",
      "description": "Install-time scoping notes. School-scoped ids in step configs do not cross tenants: tag steps are remapped to your tag of the same name, a self-enrol follows the copy, and anything that could not be mapped is neutralised and listed here as a re-pick before activating. Empty on a clean import and on reuse.",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "send-share-import.ImportPreview": {
    "type": "object",
    "properties": {
     "wouldImport": {
      "type": "boolean",
      "description": "Always true in a dry run's answer (a blocker refuses instead): the real call would create the automation, or return the existing one when wouldReuseExisting=true."
     },
     "wouldReuseExisting": {
      "type": "boolean",
      "description": "True when `idempotencyKey` matched an existing share import for this school. The real POST would short-circuit and return that automation with reused=true. Blockers are suppressed in that case."
     },
     "existingAutomationId": {
      "type": "integer",
      "description": "Set iff wouldReuseExisting=true. The automation that the reuse would return."
     },
     "blockers": {
      "type": "array",
      "description": "Always empty in a dry run's answer: a dry run that finds a blocker (rate_limited 429, source_not_found 404, self_import 409) refuses with the real call's status instead.",
      "items": {}
     },
     "source": {
      "type": "object",
      "description": "Shape of the source automation when it resolves. Mirrors the GET preview's shape (triggerLabel, stepLabels, publisherName, etc.). Null when source is missing/disabled."
     },
     "resolvedName": {
      "type": "string",
      "description": "What the new automation's name would be (source.shareTitle ?? source.name). Null when source resolution failed."
     },
     "attributionRef": {
      "type": "string",
      "description": "Echoed back from the body's `ref` field: what would be persisted as share_source_ref_slug."
     },
     "rateLimit": {
      "type": "object",
      "description": "Importer's current usage in the rolling 7-day window. Shape: { limit, used, remaining }."
     }
    }
   },
   "send-system.SystemAutomation": {
    "type": "object",
    "properties": {
     "key": {
      "type": "string"
     },
     "name": {
      "type": "string"
     },
     "description": {
      "type": "string"
     },
     "audience": {
      "type": "string",
      "enum": [
       "admin",
       "instructor"
      ]
     },
     "sections": {
      "type": "array",
      "description": "Human-readable section labels",
      "items": {}
     },
     "status": {
      "type": "string",
      "enum": [
       "active",
       "paused",
       "not_installed"
      ]
     },
     "deliveryHour": {
      "type": "number"
     },
     "schedule": {
      "type": "string",
      "description": "CRON expression (school-local tz)"
     },
     "recipientUserIds": {
      "type": "array",
      "items": {}
     },
     "recipientInstructorIds": {
      "type": "array",
      "items": {}
     },
     "automationId": {
      "type": "number",
      "description": "FK to send_automations; null if not installed"
     }
    }
   },
   "send-suppression.RemoveResult": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "removed": {
      "type": "boolean"
     },
     "channel": {
      "type": "string",
      "enum": [
       "email",
       "sms"
      ]
     },
     "recipientAddress": {
      "type": "string"
     },
     "provider": {
      "type": "object",
      "description": "{status: 'cleared', streams: string[]} | {status: 'failed', streams: string[], message} | {status: 'unconfigured'} | {status: 'not_applicable'}"
     },
     "stillBlockedBy": {
      "type": [
       "string",
       "null"
      ],
      "description": "The reason of another active row for the same address that still stops every message, or null when none does. With more than one, the weightiest: spam_complaint, then hard_bounce, opt_out, manual.",
      "enum": [
       "hard_bounce",
       "spam_complaint",
       "opt_out",
       "manual"
      ]
     },
     "marketingStaysOff": {
      "type": "boolean",
      "description": "Another active row for the same address still stops marketing (an unsubscribe, or a row that stops everything)."
     }
    }
   },
   "send-suppression.SuppressionEntry": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number"
     },
     "channel": {
      "type": "string",
      "enum": [
       "email",
       "sms"
      ]
     },
     "recipientAddress": {
      "type": "string"
     },
     "reason": {
      "type": "string",
      "enum": [
       "hard_bounce",
       "spam_complaint",
       "opt_out",
       "unsubscribe_link",
       "manual"
      ]
     },
     "detail": {
      "type": "string",
      "description": "Provider bounce code / feedback; nullable"
     },
     "createdOn": {
      "type": "number"
     },
     "createdByType": {
      "type": "string",
      "description": "'system' | 'admin'; nullable"
     }
    }
   },
   "school.TaxChangePreview": {
    "type": "object",
    "properties": {
     "total": {
      "type": "integer",
      "description": "Members whose plan takes the new tax"
     },
     "stripe": {
      "type": "integer",
      "description": "Of those, billed through Stripe"
     },
     "gocardless": {
      "type": "integer",
      "description": "Of those, billed through GoCardless"
     },
     "local": {
      "type": "integer",
      "description": "Of those, paying offline"
     },
     "chargeChanges": {
      "type": "integer",
      "description": "Of those, charged a different amount per period"
     }
    }
   },
   "school.SchoolSettings": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "School ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "School name"
     },
     "timezone": {
      "type": "string",
      "description": "IANA timezone"
     },
     "locale": {
      "type": "string",
      "description": "Locale for formatting",
      "readOnly": true
     },
     "currency": {
      "type": "string",
      "description": "Currency code"
     },
     "dateFormat": {
      "type": "string",
      "description": "Date format preference",
      "readOnly": true
     },
     "primaryColor": {
      "type": "string",
      "description": "Primary brand colour hex"
     },
     "secondaryColor": {
      "type": "string",
      "description": "Secondary brand colour hex"
     },
     "logoUrl": {
      "type": "string",
      "description": "Logo URL",
      "readOnly": true
     },
     "kioskPin": {
      "type": "string",
      "description": "4-digit kiosk PIN"
     },
     "kioskLockout": {
      "type": "integer",
      "description": "Kiosk lockout minutes"
     },
     "attendanceLimitOverride": {
      "type": "boolean",
      "description": "Allow over-capacity attendance"
     },
     "gateOnPayment": {
      "type": "boolean",
      "description": "Kiosk refuses students whose plan is overdue or expired"
     },
     "hideProgress": {
      "type": "boolean",
      "description": "Hide rank progress"
     },
     "taxName": {
      "type": "string",
      "description": "Tax label"
     },
     "taxRate": {
      "type": "number",
      "description": "Tax rate %"
     },
     "taxNumber": {
      "type": "string",
      "description": "Tax registration number"
     },
     "taxMode": {
      "type": "string",
      "description": "Tax mode",
      "enum": [
       "inclusive",
       "exclusive"
      ]
     }
    }
   },
   "school.SchoolBranding": {
    "type": "object",
    "properties": {
     "schoolName": {
      "type": "string",
      "description": "Display name",
      "readOnly": true
     },
     "logoUrl": {
      "type": "string",
      "description": "Logo image URL",
      "readOnly": true
     },
     "primaryColour": {
      "type": "string",
      "description": "Primary brand colour",
      "readOnly": true
     },
     "secondaryColour": {
      "type": "string",
      "description": "Secondary brand colour",
      "readOnly": true
     }
    }
   },
   "school.PresignedUpload": {
    "type": "object",
    "properties": {
     "uploadUrl": {
      "type": "string",
      "description": "Presigned S3 URL to PUT the file to",
      "readOnly": true
     },
     "storageKey": {
      "type": "string",
      "description": "Storage key to pass to the confirm endpoint",
      "readOnly": true
     }
    }
   },
   "school.ContentImageResult": {
    "type": "object",
    "properties": {
     "url": {
      "type": "string",
      "description": "Permanent public URL for embedding: /v1/public/content-images/{schoolId}/{file}",
      "readOnly": true
     }
    }
   },
   "school.MemberSelfServiceSettings": {
    "type": "object",
    "properties": {
     "buyPlan": {
      "type": "boolean",
      "description": "Members with no plan can start one",
      "readOnly": true
     },
     "buyPasses": {
      "type": "boolean",
      "description": "Packs and drop-ins alongside a plan",
      "readOnly": true
     },
     "changePlan": {
      "type": "boolean",
      "description": "Switch plan immediately, prorated",
      "readOnly": true
     },
     "pause": {
      "type": "boolean",
      "description": "Pause with a return date",
      "readOnly": true
     },
     "cancel": {
      "type": "boolean",
      "description": "End the plan at the end of the paid period",
      "readOnly": true
     }
    }
   },
   "school.ReportsIncomeSettings": {
    "type": "object",
    "properties": {
     "horizonMonths": {
      "type": "integer",
      "description": "Projection lookahead window in months",
      "readOnly": true,
      "enum": [
       3,
       6,
       12
      ]
     },
     "includedSources": {
      "type": "array",
      "description": "Revenue sources contributing to the headline totals",
      "readOnly": true,
      "items": {
       "type": "string",
       "enum": [
        "subscription",
        "payg",
        "shop",
        "events",
        "one_off",
        "other"
       ]
      }
     },
     "churnFallbackRate": {
      "type": "number",
      "description": "Fallback churn rate (0..1) when history is too thin",
      "readOnly": true
     },
     "includePausedSubs": {
      "type": "boolean",
      "description": "Whether paused subscriptions count toward MRR",
      "readOnly": true
     },
     "paygSmoothingWindow": {
      "type": "integer",
      "description": "Months of history smoothed for non-subscription sources",
      "readOnly": true
     }
    }
   },
   "school.User": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "User ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Display name"
     },
     "surname": {
      "type": "string",
      "description": "Surname"
     },
     "email": {
      "type": "string",
      "description": "Login email"
     },
     "isPrimary": {
      "type": "boolean",
      "description": "Whether this is the primary account",
      "readOnly": true
     },
     "permissions": {
      "type": "array",
      "description": "Granted permission IDs",
      "readOnly": true,
      "items": {}
     },
     "createdAt": {
      "type": "string",
      "description": "Account creation date",
      "readOnly": true,
      "format": "date-time"
     }
    }
   },
   "school.AccountInfo": {
    "type": "object",
    "properties": {
     "planName": {
      "type": "string",
      "description": "Current plan name",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "description": "Subscription status",
      "readOnly": true
     },
     "currentPeriodEnd": {
      "type": "integer",
      "description": "Current period end (Unix timestamp)",
      "readOnly": true
     },
     "cancelAtPeriodEnd": {
      "type": "boolean",
      "description": "Whether cancellation is pending",
      "readOnly": true
     }
    }
   },
   "school.PaymentMethod": {
    "type": "object",
    "properties": {
     "brand": {
      "type": "string",
      "description": "Card brand (visa, mastercard, etc.)",
      "readOnly": true
     },
     "last4": {
      "type": "string",
      "description": "Last 4 digits",
      "readOnly": true
     },
     "expMonth": {
      "type": "integer",
      "description": "Expiry month",
      "readOnly": true
     },
     "expYear": {
      "type": "integer",
      "description": "Expiry year",
      "readOnly": true
     }
    }
   },
   "school.AccountPayment": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Payment ID",
      "readOnly": true
     },
     "amount": {
      "type": "integer",
      "description": "Amount in cents",
      "readOnly": true
     },
     "currency": {
      "type": "string",
      "description": "Currency code",
      "readOnly": true
     },
     "status": {
      "type": "string",
      "description": "Payment status",
      "readOnly": true
     },
     "paidOn": {
      "type": "integer",
      "description": "Payment date (Unix timestamp)",
      "readOnly": true
     }
    }
   },
   "school.CancellationResult": {
    "type": "object",
    "properties": {
     "cancelAtPeriodEnd": {
      "type": "boolean",
      "description": "Always true on success",
      "readOnly": true
     },
     "effectiveDate": {
      "type": "integer",
      "description": "When cancellation takes effect (Unix timestamp)",
      "readOnly": true
     }
    }
   },
   "school-users.Permission": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "The id create and update take."
     },
     "area": {
      "type": "string",
      "description": "The staff area it belongs to, e.g. Attendance or Billing."
     },
     "name": {
      "type": "string",
      "description": "Its name within the area, e.g. Check-in."
     },
     "description": {
      "type": "string",
      "description": "What it allows."
     },
     "grantable": {
      "type": "boolean",
      "description": "Whether this caller may grant it."
     }
    }
   },
   "school-users.SchoolUser": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "User id."
     },
     "name": {
      "type": "string",
      "description": "Display/role name."
     },
     "email": {
      "type": "string",
      "format": "email"
     },
     "permissions": {
      "type": "array",
      "description": "Granted granular permission ids.",
      "items": {}
     },
     "createdOn": {
      "type": "integer",
      "description": "Unix seconds."
     },
     "invited": {
      "type": "boolean",
      "description": "Invited and not yet chosen a password; resendInvite sends a fresh link."
     }
    }
   },
   "lead-stages.LeadStage": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Stage ID"
     },
     "name": {
      "type": "string",
      "description": "Display name"
     },
     "color": {
      "type": "string",
      "description": "Hex color for column header"
     },
     "position": {
      "type": "integer",
      "description": "Sort order (0-based, terminals at 100+)"
     },
     "isSystem": {
      "type": "boolean",
      "description": "True for core stages (New, Won, Lost), which cannot be deleted"
     },
     "terminalType": {
      "type": "string",
      "description": "Pipeline endpoint type: 'won', 'lost', 'trial', or null for regular pipeline stages",
      "enum": [
       "won",
       "lost",
       "trial"
      ]
     },
     "leadCount": {
      "type": "integer",
      "description": "Number of leads currently in this stage"
     }
    }
   },
   "webhooks.WebhookEventCatalog": {
    "type": "object",
    "properties": {
     "events": {
      "type": "array",
      "description": "Event names, e.g. student.created",
      "items": {
       "type": "string"
      }
     }
    }
   },
   "webhooks.WebhookDelivery": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Delivery id, sent as X-Webhook-Delivery",
      "readOnly": true
     },
     "event": {
      "type": "string",
      "description": "The domain event"
     },
     "status": {
      "type": "string",
      "enum": [
       "pending",
       "delivered",
       "failed"
      ]
     },
     "attempts": {
      "type": "integer",
      "description": "Attempts made so far (at most 6)"
     },
     "nextAttemptAt": {
      "type": "integer",
      "description": "When the next attempt is due; null once delivered or failed",
      "format": "unix-seconds"
     },
     "lastStatusCode": {
      "type": "integer",
      "description": "The receiver's last HTTP status"
     },
     "lastError": {
      "type": "string",
      "description": "Why the last attempt failed"
     },
     "createdOn": {
      "type": "integer",
      "format": "unix-seconds"
     },
     "deliveredOn": {
      "type": "integer",
      "format": "unix-seconds"
     },
     "replayOf": {
      "type": "integer",
      "description": "The delivery this one repeats"
     },
     "payload": {
      "type": "object",
      "description": "The body sent: event, data, timestamp, webhookId, and replayOf on a replay (getDelivery only)"
     }
    }
   },
   "webhooks.Webhook": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "description": "Webhook ID",
      "readOnly": true
     },
     "name": {
      "type": "string",
      "description": "Human-readable name"
     },
     "url": {
      "type": "string",
      "description": "Endpoint URL",
      "format": "url"
     },
     "events": {
      "type": "array",
      "description": "Subscribed event patterns",
      "items": {
       "type": "string"
      }
     },
     "description": {
      "type": [
       "string",
       "null"
      ],
      "description": "Optional description"
     },
     "isActive": {
      "type": "integer",
      "description": "1 while enabled",
      "enum": [
       0,
       1
      ]
     },
     "successCount": {
      "type": "integer",
      "description": "Deliveries that succeeded",
      "readOnly": true
     },
     "failureCount": {
      "type": "integer",
      "description": "Deliveries that failed",
      "readOnly": true
     },
     "lastSuccessAt": {
      "type": [
       "integer",
       "null"
      ],
      "readOnly": true,
      "format": "unix-seconds"
     },
     "lastFailureAt": {
      "type": [
       "integer",
       "null"
      ],
      "readOnly": true,
      "format": "unix-seconds"
     },
     "lastStatusCode": {
      "type": [
       "integer",
       "null"
      ],
      "description": "The receiver's last HTTP status",
      "readOnly": true
     },
     "consecutiveFailures": {
      "type": "integer",
      "description": "Failed deliveries since the last success; the platform disables the webhook at 10",
      "readOnly": true
     },
     "disabledReason": {
      "type": [
       "string",
       "null"
      ],
      "description": "Why the platform disabled this webhook; null when active or when the school disabled it",
      "readOnly": true
     },
     "disabledAt": {
      "type": [
       "integer",
       "null"
      ],
      "description": "Unix seconds of the platform disable; null otherwise",
      "readOnly": true,
      "format": "unix-seconds"
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "webhooks.WebhookCreated": {
    "type": "object",
    "properties": {
     "id": {
      "type": "integer",
      "readOnly": true
     },
     "name": {
      "type": "string"
     },
     "url": {
      "type": "string",
      "format": "url"
     },
     "events": {
      "type": "array",
      "items": {
       "type": "string"
      }
     },
     "description": {
      "type": [
       "string",
       "null"
      ]
     },
     "isActive": {
      "type": "integer",
      "enum": [
       0,
       1
      ]
     },
     "secret": {
      "type": "string",
      "description": "HMAC signing secret, returned only here; rotateSecret mints another",
      "readOnly": true
     },
     "createdOn": {
      "type": "integer",
      "readOnly": true,
      "format": "unix-seconds"
     }
    }
   },
   "batch.BatchOperation": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Unique identifier for this operation (returned in response)"
     },
     "method": {
      "type": "string",
      "description": "HTTP method",
      "enum": [
       "GET",
       "POST",
       "PUT",
       "PATCH",
       "DELETE"
      ]
     },
     "path": {
      "type": "string",
      "description": "API path (must start with /v1/), with any query string the operation needs (?confirm=true, filters, limits)"
     },
     "body": {
      "type": "object",
      "description": "Request body (for POST/PUT/PATCH)"
     },
     "headers": {
      "type": "object",
      "description": "Additional headers (auth headers cannot be overridden)"
     }
    },
    "required": [
     "id",
     "method",
     "path"
    ]
   },
   "batch.BatchResult": {
    "type": "object",
    "properties": {
     "id": {
      "type": "string",
      "description": "Operation ID from request"
     },
     "status": {
      "type": "integer",
      "description": "HTTP status code"
     },
     "body": {
      "type": "object",
      "description": "Response body"
     }
    }
   },
   "batch.BatchResponse": {
    "type": "object",
    "properties": {
     "results": {
      "type": "array",
      "description": "Array of results in same order as operations",
      "items": {
       "type": "object"
      }
     },
     "summary": {
      "type": "object",
      "description": "Summary counts",
      "properties": {
       "total": {
        "type": "integer",
        "description": "Total operations"
       },
       "succeeded": {
        "type": "integer",
        "description": "Operations with status < 400"
       },
       "failed": {
        "type": "integer",
        "description": "Operations with status >= 400"
       }
      }
     }
    }
   },
   "student-insight.ClassInsight": {
    "type": "object",
    "properties": {
     "eventId": {
      "type": "number",
      "description": "Event id"
     },
     "date": {
      "type": "string",
      "description": "Occurrence date",
      "format": "date"
     },
     "eventName": {
      "type": "string",
      "description": "Event name"
     },
     "isCancelled": {
      "type": "boolean",
      "description": "Occurrence cancelled via exception"
     },
     "asOf": {
      "type": "number",
      "description": "Evaluation time (unix seconds)"
     },
     "ruleVersion": {
      "type": "string",
      "description": "Rule set version"
     },
     "counts": {
      "type": "object",
      "description": "checkedIn, expected, eligible, withInsight. Overlapping, not additive."
     },
     "dataCoverage": {
      "type": "object",
      "description": "usualAttendance: ok | insufficient | not_recurring; comparableOccurrences"
     },
     "summary": {
      "type": "array",
      "description": "Up to five distinct people with their primary signal",
      "items": {}
     },
     "roster": {
      "type": "array",
      "description": "One InsightRosterRow per student, sorted by tier",
      "items": {}
     }
    }
   },
   "student-insight.InsightRosterRow": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "number",
      "description": "Student id"
     },
     "firstName": {
      "type": "string",
      "description": "First name"
     },
     "lastName": {
      "type": "string",
      "description": "Last name"
     },
     "rank": {
      "type": "object",
      "description": "Rank in the event's style, or null"
     },
     "tier": {
      "type": "number",
      "description": "Relevance tier 1-5"
     },
     "source": {
      "type": "string",
      "description": "Strongest attendance source",
      "enum": [
       "checked_in",
       "booked",
       "enrolled",
       "eligible"
      ]
     },
     "checkedInAt": {
      "type": "string",
      "description": "HH:MM in school tz, or null"
     },
     "bookingStatus": {
      "type": "string",
      "description": "Booking status when booked"
     },
     "owedCents": {
      "type": "integer",
      "description": "The event price still owed on the booking, in cents; null when nothing is owed or it is paid"
     },
     "gaveUpSeat": {
      "type": "object",
      "description": "Set when the student gave up their own seat: { paid } says the seat had been paid for and the money stays with the school; null otherwise"
     },
     "eligible": {
      "type": "boolean",
      "description": "Passes the event's eligibility rules now"
     },
     "usual": {
      "type": "object",
      "description": "attended, of, label (usually | sometimes | insufficient | none)"
     },
     "primary": {
      "type": "object",
      "description": "Highest-priority signal or null"
     },
     "otherSignals": {
      "type": "number",
      "description": "Further signals available in the detail view"
     }
    }
   },
   "student-insight.InsightSignal": {
    "type": "object",
    "properties": {
     "type": {
      "type": "string",
      "description": "Signal type",
      "enum": [
       "first_class",
       "returning",
       "birthday",
       "attendance_decline",
       "milestone",
       "recent_note"
      ]
     },
     "headline": {
      "type": "string",
      "description": "One-sentence roster copy"
     },
     "detail": {
      "type": "string",
      "description": "Evidence sentence"
     },
     "suggestedAction": {
      "type": "string",
      "description": "What to do"
     },
     "evidence": {
      "type": "object",
      "description": "Machine-readable evidence"
     },
     "actioned": {
      "type": "boolean",
      "description": "Spoke today already recorded"
     }
    }
   },
   "student-insight.StudentInsightDetail": {
    "type": "object",
    "properties": {
     "studentId": {
      "type": "number",
      "description": "Student id"
     },
     "signals": {
      "type": "array",
      "description": "All signals in priority order",
      "items": {}
     },
     "retention": {
      "type": "object",
      "description": "Owner/admin only: rule-baseline score, band, factors"
     },
     "account": {
      "type": "object",
      "description": "Owner/admin only: followUpNeeded, billingStatus"
     }
    }
   },
   "student-insight.DayInsightCount": {
    "type": "object",
    "properties": {
     "eventId": {
      "type": "number",
      "description": "Event id"
     },
     "startTime": {
      "type": "string",
      "description": "HH:MM"
     },
     "withInsight": {
      "type": "number",
      "description": "People with Insight"
     }
    }
   },
   "student-insight.InsightAction": {
    "type": "object",
    "properties": {
     "id": {
      "type": "number",
      "description": "Action row id"
     },
     "expiresOn": {
      "type": "number",
      "description": "Suppression end (unix), null for spoke"
     }
    }
   }
  },
  "headers": {
   "X-RateLimit-Limit": {
    "schema": {
     "type": "integer"
    },
    "description": "Requests allowed per minute on an API-key request (tiered)."
   },
   "X-RateLimit-Remaining": {
    "schema": {
     "type": "integer"
    },
    "description": "Requests left in the current minute."
   },
   "X-RateLimit-Reset": {
    "schema": {
     "type": "integer"
    },
    "description": "Unix seconds when the window resets."
   },
   "Retry-After": {
    "schema": {
     "type": "integer"
    },
    "description": "Seconds to wait before trying again."
   },
   "ETag": {
    "schema": {
     "type": "string"
    },
    "description": "Send it back as If-None-Match to get 304 while the answer is unchanged."
   },
   "X-Preview-Token": {
    "schema": {
     "type": "string"
    },
    "description": "The dry run's previewToken (also in the body): send it in X-Preview-Token to commit what was shown."
   },
   "Preview-Token-Status": {
    "schema": {
     "type": "string",
     "enum": [
      "replayed"
     ]
    },
    "description": "Set when a commit sent its token a second time: this is the first answer again, nothing ran twice."
   },
   "Location": {
    "schema": {
     "type": "string",
     "format": "uri"
    },
    "description": "Where to go next."
   }
  },
  "securitySchemes": {
   "apiKeyAuth": {
    "type": "apiKey",
    "in": "header",
    "name": "X-API-Key",
    "description": "API key (mk_live_…) created in Settings → API & AI. Also accepted as `Authorization: Bearer mk_live_…`. Scoped per area; reaches exactly the endpoints documented here."
   },
   "bearerAuth": {
    "type": "http",
    "scheme": "bearer",
    "bearerFormat": "JWT",
    "description": "Admin JWT from POST /v1/auth/login (first-party apps). Kiosk, student-portal, and public-form endpoints use their own credentials — see the module descriptions."
   }
  }
 },
 "security": [
  {
   "apiKeyAuth": []
  },
  {
   "bearerAuth": []
  }
 ]
}