{
  "openapi": "3.1.0",
  "info": {
    "title": "CrewChief UK Officiating Management API",
    "description": "Comprehensive REST API for basketball officiating appointments, multi-tenancy league management, assignor intelligence, HMRC expense reconciliation, and governance.",
    "version": "2.5.0",
    "contact": {
      "name": "CrewChief UK Technical Team",
      "url": "https://github.com/Gamenews6/refsync-uk",
      "email": "support@refsync.uk"
    },
    "license": {
      "name": "Proprietary / Basketball England Aligned",
      "url": "https://refsync.uk/terms"
    }
  },
  "servers": [
    {
      "url": "https://refsync-uk-production.up.railway.app",
      "description": "Railway Container Production Environment"
    },
    {
      "url": "https://refsync.newhamyoungbloods.co.uk",
      "description": "RochenHost LiteSpeed Production Environment"
    },
    {
      "url": "http://localhost:8000",
      "description": "Local Development Server"
    }
  ],
  "tags": [
    {
      "name": "Bootstrap",
      "description": "Client initialisation and core database hydration"
    },
    {
      "name": "Authentication",
      "description": "Session creation, persona switching, WebAuthn Passkeys, and OAuth SSO"
    },
    {
      "name": "Fixtures & Appointments",
      "description": "Game management, official slots, acceptance, declines, and swaps"
    },
    {
      "name": "Assignor Intelligence",
      "description": "Smart candidate recommendations, clash detection, auto-assign, and workload telemetry"
    },
    {
      "name": "Governance & Rulebook",
      "description": "Basketball England regulations, FIBA 2024 mechanics, safeguarding, and rule interpretations"
    },
    {
      "name": "Financials & Expenses",
      "description": "BACS automated export, mileage splitting, expense auditing, and club recharge invoices"
    },
    {
      "name": "Reports & Exports",
      "description": "Season executive reports, iCal calendar synchronization, CSV, and printable documents"
    },
    {
      "name": "Administration & Tenancy",
      "description": "Multi-league federation, automated backups, and database disaster recovery"
    }
  ],
  "paths": {
    "/api/bootstrap": {
      "get": {
        "tags": [
          "Bootstrap"
        ],
        "summary": "Retrieve complete platform state for active session",
        "description": "Hydrates client UI with user session, games, officials, venues, courts, position types, and league metadata.",
        "responses": {
          "200": {
            "description": "Bootstrap payload loaded successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BootstrapResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/session": {
      "post": {
        "tags": [
          "Authentication"
        ],
        "summary": "Create session or switch active persona",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "userId": {
                    "type": "string",
                    "example": "usr-assignor-1"
                  }
                },
                "required": [
                  "userId"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Session established",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthSessionResponse"
                }
              }
            }
          },
          "400": {
            "description": "Missing userId"
          },
          "404": {
            "description": "User not found"
          }
        }
      }
    },
    "/api/auth/switch-persona": {
      "post": {
        "tags": [
          "Authentication"
        ],
        "summary": "Fast switch active persona for multi-role assignors/officials",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "userId": {
                    "type": "string",
                    "example": "off-sarah"
                  }
                },
                "required": [
                  "userId"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Persona switched",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AuthSessionResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/auth/me": {
      "get": {
        "tags": [
          "Authentication"
        ],
        "summary": "Get authenticated user profile and roles",
        "security": [
          {
            "BearerAuth": []
          },
          {
            "SessionToken": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current user profile",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/User"
                }
              }
            }
          },
          "401": {
            "description": "Unauthenticated"
          }
        }
      }
    },
    "/api/officials/me/statement": {
      "get": {
        "tags": [
          "Finance"
        ],
        "summary": "The signed-in official's own season statement (fees, mileage, expenses, paid status)",
        "description": "Always the caller's own statement: an official_id in the query is ignored. Grouped by the fixture's UK date; a UK tax year runs 6 April to 5 April. Money is whole pence and as text (e.g. 'totalGbp'). Fixtures with no claim are listed as not yet claimed and left out of the totals. 'Marked paid' is the time of the claim's last status change (no separate paid date is recorded). This is a summary of what is recorded, not tax advice.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "taxYear",
            "in": "query",
            "schema": {
              "type": "integer"
            },
            "description": "The year a UK tax year starts in (2026 means 6 April 2026 to 5 April 2027). Default: the current one."
          },
          {
            "name": "seasonId",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Use a season's dates instead of a tax year."
          }
        ],
        "responses": {
          "200": {
            "description": "The statement",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Invalid tax year, or a season without dates"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "The signed-in person is not an official"
          },
          "404": {
            "description": "Season not found"
          }
        }
      }
    },
    "/api/officials/me/statement.csv": {
      "get": {
        "tags": [
          "Finance"
        ],
        "summary": "The same statement as a CSV download (spreadsheet formulas in text cells are neutralised)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "taxYear",
            "in": "query",
            "schema": {
              "type": "integer"
            }
          },
          {
            "name": "seasonId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "CSV file",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid tax year, or a season without dates"
          },
          "401": {
            "description": "Unauthenticated"
          },
          "403": {
            "description": "The signed-in person is not an official"
          },
          "404": {
            "description": "Season not found"
          }
        }
      }
    },
    "/api/games": {
      "get": {
        "tags": [
          "Fixtures & Appointments"
        ],
        "summary": "List scheduled games and appointments",
        "parameters": [
          {
            "name": "league_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of games",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "games": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/Game"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Fixtures & Appointments"
        ],
        "summary": "Create new scheduled fixture with crew template",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateGameRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Game created successfully"
          },
          "403": {
            "description": "Assignor privilege required"
          }
        }
      }
    },
    "/api/games/{game_id}/appointments": {
      "post": {
        "tags": [
          "Fixtures & Appointments"
        ],
        "summary": "Appoint an official to a fixture slot",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "game_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "officialId": {
                    "type": "string"
                  },
                  "position": {
                    "type": "string"
                  },
                  "allowOverride": {
                    "type": "boolean"
                  },
                  "overrideReason": {
                    "type": "string"
                  }
                },
                "required": [
                  "officialId",
                  "position"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Official appointed"
          },
          "409": {
            "description": "Conflict detected and override not granted"
          }
        }
      },
      "patch": {
        "tags": [
          "Fixtures & Appointments"
        ],
        "summary": "Update appointment status (Accept, Decline, Revoke)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "game_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "officialId": {
                    "type": "string"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "ACCEPTED",
                      "DECLINED",
                      "REVOKED"
                    ]
                  },
                  "declineReason": {
                    "type": "string"
                  }
                },
                "required": [
                  "officialId",
                  "status"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Appointment status updated"
          },
          "400": {
            "description": "Invalid transition"
          }
        }
      }
    },
    "/api/assignor/suggest-officials": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Get ranked official recommendations for a fixture slot",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "game_id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "position",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "include_conflicted",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Ranked candidates with conflict telemetry and suitability scores",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SuggestionsResponse"
                }
              }
            }
          }
        }
      }
    },
    "/api/league/auto-assign-settings": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Read a league's auto-appoint settings",
        "description": "Returns the league's settings, the defaults, the weight schema (labels, help, ranges), the safety rules (read-only) and the available fill methods and fairness modes.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "leagueId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Settings view"
          },
          "403": {
            "description": "Caller does not administer this league"
          }
        }
      },
      "put": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Change a league's auto-appoint settings (partial update) or reset them",
        "description": "Only the named settings change. Whole numbers within each weight's range; unknown keys are refused, so a safety rule can never be switched off. Send {\"reset\": true} to restore the defaults. Audited with before and after.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "leagueId": {
                    "type": "string"
                  },
                  "reset": {
                    "type": "boolean"
                  },
                  "config": {
                    "type": "object",
                    "properties": {
                      "fillStrategy": {
                        "type": "string",
                        "enum": [
                          "GAME_ORDER",
                          "MOST_CONSTRAINED_FIRST"
                        ]
                      },
                      "fairnessMode": {
                        "type": "string",
                        "enum": [
                          "SEASON_COUNT",
                          "AVAILABILITY_WEIGHTED",
                          "OFF"
                        ]
                      },
                      "mentorPairing": {
                        "type": "boolean"
                      },
                      "maxPerOfficialPerDay": {
                        "type": [
                          "integer",
                          "null"
                        ],
                        "minimum": 1,
                        "maximum": 6
                      },
                      "weights": {
                        "type": "object",
                        "additionalProperties": {
                          "type": "integer",
                          "minimum": -50,
                          "maximum": 50
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated settings view"
          },
          "400": {
            "description": "Invalid value or unknown setting"
          },
          "403": {
            "description": "Caller does not administer this league"
          }
        }
      }
    },
    "/api/assignor/auto-assign/compare": {
      "post": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Compare the current and improved auto-appoint methods on the same open slots",
        "description": "Changes nothing. Returns both plans, per-slot differences and a summary. Either side's proposals can be applied through the normal preview/apply/undo flow.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "leagueId": {
                    "type": "string"
                  },
                  "gameId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Comparison"
          },
          "403": {
            "description": "Not an assignor of this league"
          }
        }
      }
    },
    "/api/league/officials": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "List a league's official pool",
        "description": "Officials are a shared pool across the leagues they belong to. Only members of a league are candidates for its fixtures.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "leagueId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Officials in the league's pool"
          },
          "403": {
            "description": "Caller is not an assignor of this league"
          }
        }
      },
      "post": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Add an official to a league's pool",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Provide userId, or the official's exact email address (no fuzzy search).",
                "properties": {
                  "userId": {
                    "type": "string"
                  },
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "leagueId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Official added"
          },
          "200": {
            "description": "Already in the pool"
          },
          "403": {
            "description": "Caller is not an assignor of this league"
          }
        }
      }
    },
    "/api/leagues/public": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "List active leagues a person can ask to join",
        "description": "Returns only id, name and code. No members, admins or counts.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Active leagues"
          }
        }
      }
    },
    "/api/league/join-requests": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "List join requests for a league (assignors and league admins)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "leagueId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "PENDING",
                "APPROVED",
                "REJECTED",
                "WITHDRAWN"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Requests plus pendingCount for the badge"
          },
          "403": {
            "description": "Caller does not administer this league"
          }
        }
      },
      "post": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Ask to join one or more leagues",
        "description": "For a signed-in official. All-or-nothing; up to 5 open requests; a declined request can be repeated after 7 days. Membership is only created when an approver approves.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "leagueIds"
                ],
                "properties": {
                  "leagueIds": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "message": {
                    "type": "string",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Requests created"
          },
          "400": {
            "description": "Duplicate, already a member, cap reached, cool-down, or invalid"
          }
        }
      }
    },
    "/api/league/join-requests/mine": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "List my own join requests",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "My requests with status and any decision note"
          }
        }
      }
    },
    "/api/league/join-requests/{id}": {
      "delete": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Withdraw my pending join request",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Withdrawn"
          },
          "404": {
            "description": "Not found (including someone else's request)"
          }
        }
      }
    },
    "/api/league/join-requests/{id}/approve": {
      "post": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Approve a join request and add the official to the league",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "note": {
                    "type": "string",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Approved"
          },
          "400": {
            "description": "Already decided"
          },
          "404": {
            "description": "Not found, or belongs to a league the caller does not administer"
          }
        }
      }
    },
    "/api/league/join-requests/{id}/reject": {
      "post": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Decline a join request",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "note": {
                    "type": "string",
                    "maxLength": 500
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Declined"
          },
          "400": {
            "description": "Already decided"
          },
          "404": {
            "description": "Not found, or belongs to a league the caller does not administer"
          }
        }
      }
    },
    "/api/league/fixtures/import/preview": {
      "post": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Check a fixture CSV without saving anything",
        "description": "Validates every row against the caller's league (teams, venues, courts, dates, fees, crew) and reports what would be created or updated. Nothing is written.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "csv"
                ],
                "properties": {
                  "csv": {
                    "type": "string"
                  },
                  "leagueId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Per-row results and a summary"
          },
          "400": {
            "description": "IMPORT_FILE_PROBLEM: the file could not be read"
          },
          "403": {
            "description": "Caller is not an assignor of this league"
          }
        }
      }
    },
    "/api/league/fixtures/import/apply": {
      "post": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Import a fixture CSV",
        "description": "Re-checks the file and imports it all-or-nothing: refused with 400 IMPORT_HAS_PROBLEMS if any row has an error, or NOTHING_TO_IMPORT if it is empty. Rows can only create or update fixtures in the caller's own league. Recorded in the audit ledger.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "csv"
                ],
                "properties": {
                  "csv": {
                    "type": "string"
                  },
                  "leagueId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Imported"
          },
          "400": {
            "description": "IMPORT_HAS_PROBLEMS, NOTHING_TO_IMPORT or IMPORT_FILE_PROBLEM"
          },
          "403": {
            "description": "Caller is not an assignor of this league"
          }
        }
      }
    },
    "/api/league/activity": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "A league's own activity feed (who did what), newest first",
        "description": "For the league's admins and assignors (a Super Admin may ask for any league). Only entries that belong to this league: platform-level entries are never included. Names only, no contact details. Page with `nextCursor`.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "leagueId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "category",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "people",
                "appointments",
                "fixtures",
                "settings",
                "other"
              ]
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "cursor",
            "in": "query",
            "description": "The `nextCursor` of the previous page.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Entries with when, who, what (label and category) and a one-sentence summary, plus nextCursor"
          },
          "400": {
            "description": "Unknown category or invalid cursor"
          },
          "403": {
            "description": "Not an assignor of this league, or a read-only account"
          }
        }
      }
    },
    "/api/league/viewers": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "List a league's read-only viewers",
        "description": "A viewer can look at the league's fixtures and coverage. Every write from a viewer is refused with 403 READ_ONLY_ACCOUNT, and viewers do not see people's details, claims or messages.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "leagueId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Viewers of the league"
          },
          "403": {
            "description": "Caller is not an assignor of this league"
          }
        }
      },
      "post": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Make an existing account a read-only viewer of a league",
        "description": "By exact email address. Refused for administrators, assignors, club reps and officials with appointments or pool memberships. Recorded in the audit ledger.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "email"
                ],
                "properties": {
                  "email": {
                    "type": "string",
                    "format": "email"
                  },
                  "leagueId": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Viewer added (or already a viewer)"
          },
          "400": {
            "description": "That person can already make changes, or has appointments"
          },
          "403": {
            "description": "Caller is not an assignor of this league"
          },
          "404": {
            "description": "No account uses that email address"
          }
        }
      }
    },
    "/api/league/viewers/{userId}": {
      "delete": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Remove a read-only viewer from a league",
        "description": "Access ends immediately. A person who is no longer a viewer of any league goes back to a plain sign-up account.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "leagueId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Viewer removed"
          },
          "404": {
            "description": "Not a viewer of this league"
          }
        }
      }
    },
    "/api/league/officials/{userId}": {
      "delete": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Remove an official from a league's pool",
        "description": "Blocked while the official has upcoming appointments in the league, and for league administrators.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "leagueId",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Official removed"
          },
          "400": {
            "description": "Has upcoming appointments, or is an administrator"
          },
          "403": {
            "description": "Caller is not an assignor of this league"
          }
        }
      }
    },
    "/api/assignor/audit-logs": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Retrieve immutable assignor audit trail and override ledger",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 100
            }
          },
          {
            "name": "game_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Audit entries retrieved",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "auditLogs": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/AuditLog"
                      }
                    },
                    "count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/assignor/workload-analytics": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Official workload distribution, fatigue markers, and game limits",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Workload analytics data"
          }
        }
      }
    },
    "/api/assignor/availability-heatmap": {
      "get": {
        "tags": [
          "Assignor Intelligence"
        ],
        "summary": "Regional official availability heatmap across date corridors",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Availability heatmap matrix"
          }
        }
      }
    },
    "/api/governance/rules": {
      "get": {
        "tags": [
          "Governance & Rulebook"
        ],
        "summary": "Search Basketball England & FIBA regulations knowledge base",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Search keyword or citation",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "category",
            "in": "query",
            "description": "Regulation category filter",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "List of indexed governance regulations",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "rules": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/GovernanceRule"
                      }
                    },
                    "categories": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "label": {
                            "type": "string"
                          },
                          "icon": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/export/bacs-csv": {
      "get": {
        "tags": [
          "Financials & Expenses"
        ],
        "summary": "Generate standard BACS bank payout file for officials",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "BACS CSV format file",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              },
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/reports/season-committee-summary": {
      "get": {
        "tags": [
          "Reports & Exports"
        ],
        "summary": "Season executive summary data for League Committees (JSON)",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "season_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Committee summary report",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SeasonCommitteeReport"
                }
              }
            }
          }
        }
      }
    },
    "/api/reports/season-committee-summary.html": {
      "get": {
        "tags": [
          "Reports & Exports"
        ],
        "summary": "Print-ready A4 executive summary report (HTML / PDF export)",
        "description": "Assignors only, and only the caller's own leagues. The session token can be sent as `token` so the report opens in a new browser tab.",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "season_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A4 printable HTML document",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Not signed in"
          },
          "403": {
            "description": "Not an assignor"
          }
        }
      }
    },
    "/api/admin/backups": {
      "get": {
        "tags": [
          "Administration & Tenancy"
        ],
        "summary": "List automated database backups and snapshots",
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of available backup files"
          },
          "403": {
            "description": "Admin privilege required"
          }
        }
      }
    },
    "/api/openapi.json": {
      "get": {
        "tags": [
          "Documentation"
        ],
        "summary": "Export OpenAPI 3.1 JSON specification",
        "responses": {
          "200": {
            "description": "OpenAPI 3.1 specification",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/api/docs": {
      "get": {
        "tags": [
          "Documentation"
        ],
        "summary": "Interactive Swagger UI documentation page",
        "responses": {
          "200": {
            "description": "Interactive API explorer interface",
            "content": {
              "text/html": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "Token",
        "description": "Standard Authorization: Bearer <session-token> header"
      },
      "SessionToken": {
        "type": "apiKey",
        "in": "query",
        "name": "token",
        "description": "Query parameter ?token=<session-token> or cookie session=<session-token>"
      }
    },
    "schemas": {
      "User": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "email": {
            "type": "string",
            "format": "email"
          },
          "firstName": {
            "type": "string"
          },
          "lastName": {
            "type": "string"
          },
          "roles": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "isAssignor": {
            "type": "boolean"
          },
          "isAdmin": {
            "type": "boolean"
          },
          "isOfficial": {
            "type": "boolean"
          }
        }
      },
      "Game": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "externalGameCode": {
            "type": "string"
          },
          "startTime": {
            "type": "string",
            "format": "date-time"
          },
          "endTime": {
            "type": "string",
            "format": "date-time"
          },
          "homeTeamName": {
            "type": "string"
          },
          "awayTeamName": {
            "type": "string"
          },
          "venueName": {
            "type": "string"
          },
          "courtName": {
            "type": "string"
          },
          "coverageHealth": {
            "type": "string",
            "enum": [
              "FULLY_CONFIRMED",
              "PENDING_CONFIRMATION",
              "PARTIALLY_ASSIGNED",
              "DECLINED_REPLACEMENT_NEEDED",
              "CRITICAL_UNASSIGNED"
            ]
          },
          "crewSize": {
            "type": "integer"
          },
          "acceptedCount": {
            "type": "integer"
          },
          "appointments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Appointment"
            }
          }
        }
      },
      "Appointment": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "gameId": {
            "type": "string"
          },
          "officialId": {
            "type": "string"
          },
          "officialName": {
            "type": "string"
          },
          "position": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "PROPOSED",
              "ACCEPTED",
              "DECLINED",
              "REVOKED"
            ]
          }
        }
      },
      "GovernanceRule": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "categoryLabel": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "summary": {
            "type": "string"
          },
          "keyPoints": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "citation": {
            "type": "string"
          }
        }
      },
      "AuditLog": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer"
          },
          "timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "actionType": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          },
          "assignorUserId": {
            "type": "string"
          },
          "officialUserId": {
            "type": "string"
          },
          "gameId": {
            "type": "string"
          }
        }
      },
      "BootstrapResponse": {
        "type": "object",
        "properties": {
          "sessionUser": {
            "$ref": "#/components/schemas/User"
          },
          "games": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Game"
            }
          },
          "officials": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "venues": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "AuthSessionResponse": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "token": {
            "type": "string"
          },
          "user": {
            "$ref": "#/components/schemas/User"
          }
        }
      },
      "CreateGameRequest": {
        "type": "object",
        "properties": {
          "externalGameCode": {
            "type": "string"
          },
          "courtId": {
            "type": "string"
          },
          "homeTeamId": {
            "type": "string"
          },
          "awayTeamId": {
            "type": "string"
          },
          "startTime": {
            "type": "string",
            "format": "date-time"
          },
          "endTime": {
            "type": "string",
            "format": "date-time"
          },
          "crewTemplateId": {
            "type": "string"
          }
        },
        "required": [
          "externalGameCode",
          "courtId",
          "homeTeamId",
          "awayTeamId",
          "startTime",
          "endTime"
        ]
      },
      "SuggestionsResponse": {
        "type": "object",
        "properties": {
          "gameId": {
            "type": "string"
          },
          "position": {
            "type": "string"
          },
          "candidates": {
            "type": "array",
            "items": {
              "type": "object"
            }
          }
        }
      },
      "SeasonCommitteeReport": {
        "type": "object",
        "properties": {
          "seasonTitle": {
            "type": "string"
          },
          "totalGames": {
            "type": "integer"
          },
          "coverageRate": {
            "type": "number"
          },
          "unfilledSlots": {
            "type": "integer"
          },
          "declineRate": {
            "type": "number"
          },
          "totalOfficiatingFeesPence": {
            "type": "integer"
          }
        }
      }
    }
  }
}