openapi: 3.1.0
info:
  title: NSGo Self-Hosted Leaderboard API
  version: 1.0.0
  summary: Cross-platform leaderboards with periodic resets and optional server-signed score proofs.
  description: >-
    HTTP API served by github.com/nsgo-dev/game/pkg/online/leaderboard/selfhost.
    Every endpoint except GET /v1/openapi.yaml requires a bearer token issued by
    the account service (pkg/online/accounts), verified offline with Options.Tokens.
    JSON request bodies refuse unknown fields and trailing data, and are bounded
    to 64 KiB. Every response carries Cache-Control: no-store. Pages leave out the
    accounts operators hid, except the caller's own. The /admin/v1/ routes are
    served on the daemon's separate admin listener (Service.AdminRoutes with package
    admin), never on the player listener, and take an operator's token or session
    instead of an account token.
  license:
    name: MIT

security:
  - bearerAuth: []

paths:
  /v1/openapi.yaml:
    get:
      operationId: getOpenAPI
      summary: Download this OpenAPI 3.1 description
      description: >-
        Returns the OpenAPI 3.1 YAML description of the self-hosted leaderboard
        service without requiring authentication.
      security: []
      responses:
        "200":
          description: The OpenAPI 3.1 document in YAML.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/yaml:
              schema:
                type: string

  /v1/boards:
    get:
      operationId: listBoards
      summary: List configured leaderboards
      description: >-
        Returns every declared board in configuration order, along with its
        current period and readable earlier periods.
      responses:
        "200":
          description: Configured boards and their active periods.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/BoardsResponse"
        "401":
          $ref: "#/components/responses/InvalidToken"

  /v1/boards/{board}/scores:
    parameters:
      - $ref: "#/components/parameters/Board"
    post:
      operationId: submitScore
      summary: Submit a score for the authenticated account
      description: >-
        Records a score for the bearer token's subject in the board's current
        period. A score replaces the account's best only when it improves on the
        current best according to the board's order. Boards with validation: signed
        require a valid game server proof.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/ScoreRequest"
      responses:
        "200":
          description: The account's resulting rank and whether the score improved its best.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/SubmitResult"
        "400":
          description: Invalid request body, invalid account ID, or score outside board bounds.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - bad_request
                      - invalid_account
                      - score_out_of_range
                      - invalid_metadata
        "401":
          $ref: "#/components/responses/InvalidToken"
        "403":
          description: Missing, invalid or expired game server score proof.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - proof_required
                      - invalid_proof
                      - proof_expired
        "404":
          description: No board with that name is configured.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - unknown_board
        "413":
          $ref: "#/components/responses/RequestTooLarge"
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          $ref: "#/components/responses/Unavailable"

  /v1/boards/{board}/top:
    parameters:
      - $ref: "#/components/parameters/Board"
      - $ref: "#/components/parameters/Period"
      - $ref: "#/components/parameters/Offset"
      - $ref: "#/components/parameters/Limit"
    get:
      operationId: getTop
      summary: Fetch top-ranked entries of a board
      description: >-
        Returns up to limit entries starting from 1-based rank offset + 1 in the
        selected period.
      responses:
        "200":
          description: A ranked page of entries.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Page"
        "400":
          $ref: "#/components/responses/BadRequest"
        "401":
          $ref: "#/components/responses/InvalidToken"
        "404":
          description: Board or period does not exist or is no longer kept.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - unknown_board
                      - unknown_period
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          $ref: "#/components/responses/Unavailable"

  /v1/boards/{board}/around:
    parameters:
      - $ref: "#/components/parameters/Board"
      - $ref: "#/components/parameters/Period"
      - $ref: "#/components/parameters/Radius"
    get:
      operationId: getAround
      summary: Fetch entries around the authenticated account
      description: >-
        Returns the authenticated account's entry with up to radius entries on
        each side (shifted near either end to keep the window size when possible).
        Returns 404 not_ranked if the account has no score in the period.
      responses:
        "200":
          description: A ranked page centered around the authenticated account.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Page"
        "400":
          description: Invalid radius query parameter or account ID.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - bad_request
                      - invalid_account
        "401":
          $ref: "#/components/responses/InvalidToken"
        "404":
          description: Board or period does not exist, or the account has no score in the period.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - unknown_board
                      - unknown_period
                      - not_ranked
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          $ref: "#/components/responses/Unavailable"

  /v1/boards/{board}/friends:
    parameters:
      - $ref: "#/components/parameters/Board"
      - $ref: "#/components/parameters/Period"
    post:
      operationId: getFriends
      summary: Fetch ranked entries for a list of accounts
      description: >-
        Looks up up to 200 accounts in the selected period and returns those with
        scores in rank order, each carrying its overall rank on the board.
        Duplicate account IDs are ignored.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/FriendsRequest"
      responses:
        "200":
          description: Ranked entries for the requested accounts that have a score.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Page"
        "400":
          description: Malformed JSON, unknown fields, more than 200 accounts, or an invalid account ID.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - bad_request
                      - invalid_account
        "401":
          $ref: "#/components/responses/InvalidToken"
        "404":
          description: Board or period does not exist or is no longer kept.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - unknown_board
                      - unknown_period
        "413":
          $ref: "#/components/responses/RequestTooLarge"
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          $ref: "#/components/responses/Unavailable"

  /admin/v1/leaderboard/boards:
    get:
      operationId: adminListBoards
      summary: List boards with their periods' entry counts (operators)
      description: >-
        Served on the admin listener (Service.AdminRoutes with package admin), never on
        the player listener. Needs the leaderboard.read permission. Returns every
        declared board with its current and kept periods, the number of entries each
        holds, and how many accounts are hidden on it.
      security:
        - adminBearer: []
        - adminSession: []
      responses:
        "200":
          description: Boards with entry counts.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminBoardsResponse"
        "401":
          $ref: "#/components/responses/AdminUnauthorized"
        "403":
          $ref: "#/components/responses/AdminForbidden"
        "500":
          $ref: "#/components/responses/InternalError"

  /admin/v1/leaderboard/boards/{board}/entries:
    parameters:
      - $ref: "#/components/parameters/Board"
      - $ref: "#/components/parameters/Period"
    get:
      operationId: adminListEntries
      summary: Read a period's entries, hidden ones included (operators)
      description: >-
        Needs leaderboard.read. Ranks every entry of the period, including those of
        hidden accounts, each marked with "hidden". With account, returns that
        account's entry alone, or 404 not_ranked.
      security:
        - adminBearer: []
        - adminSession: []
      parameters:
        - name: account
          in: query
          required: false
          description: Account ID whose entry to return instead of a page.
          schema:
            type: string
            maxLength: 128
        - $ref: "#/components/parameters/Offset"
        - $ref: "#/components/parameters/Limit"
      responses:
        "200":
          description: A page of entries.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminPage"
        "400":
          description: Malformed offset or limit, or an invalid account ID.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - bad_request
                      - invalid_account
        "401":
          $ref: "#/components/responses/AdminUnauthorized"
        "403":
          $ref: "#/components/responses/AdminForbidden"
        "404":
          description: Board or period does not exist, or the account has no entry in the period.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - unknown_board
                      - unknown_period
                      - not_ranked
        "500":
          $ref: "#/components/responses/InternalError"

  /admin/v1/leaderboard/boards/{board}/entries/{account}:
    parameters:
      - $ref: "#/components/parameters/Board"
      - name: account
        in: path
        required: true
        description: Account ID whose entries to delete.
        schema:
          type: string
          minLength: 1
          maxLength: 128
    delete:
      operationId: adminDeleteEntries
      summary: Delete an account's entries (operators)
      description: >-
        Needs leaderboard.delete and is audited. Removes the account's entry from the
        named period, or from every period of the board with period=all, in the store
        and in the ranking at once, so the ranks below it close up. The deletion
        survives a restart. period=all erases the account from the board: it also
        removes the account's entries in periods the service no longer serves and its
        hiding on the board, and succeeds even when no period the service serves held
        an entry. The audit record lists the removed entries.
      security:
        - adminBearer: []
        - adminSession: []
      parameters:
        - name: period
          in: query
          required: true
          description: >-
            "current", "previous", a kept period's ID, or "all" for every period of
            the board.
          schema:
            type: string
            minLength: 1
      responses:
        "200":
          description: The periods the entry was removed from, latest first; empty when period=all found no entry the service serves.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminDeleted"
        "400":
          description: No period, or an invalid account ID.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - bad_request
                      - invalid_account
        "401":
          $ref: "#/components/responses/AdminUnauthorized"
        "403":
          $ref: "#/components/responses/AdminForbidden"
        "404":
          description: Board or period does not exist, or the account has no entry in the named period.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - unknown_board
                      - unknown_period
                      - not_ranked
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          $ref: "#/components/responses/Unavailable"

  /admin/v1/leaderboard/boards/{board}/hidden:
    parameters:
      - $ref: "#/components/parameters/Board"
    get:
      operationId: adminListHidden
      summary: List the accounts hidden on a board (operators)
      description: Needs leaderboard.read. Returns the hidings in force, sorted by account.
      security:
        - adminBearer: []
        - adminSession: []
      responses:
        "200":
          description: The hidden accounts.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminHiddenList"
        "401":
          $ref: "#/components/responses/AdminUnauthorized"
        "403":
          $ref: "#/components/responses/AdminForbidden"
        "404":
          $ref: "#/components/responses/AdminUnknownBoard"
        "500":
          $ref: "#/components/responses/InternalError"

  /admin/v1/leaderboard/boards/{board}/hide:
    parameters:
      - $ref: "#/components/parameters/Board"
    post:
      operationId: adminHide
      summary: Hide an account from other players (operators)
      description: >-
        Needs leaderboard.hide and is audited. Until until, or until unhidden, every
        page leaves the account out for everyone but the account itself, which still
        sees its own entry and rank; the ranks below it close up for the others.
        Hiding an account again replaces the earlier hiding.
      security:
        - adminBearer: []
        - adminSession: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AdminHideRequest"
      responses:
        "200":
          description: The hiding now in force.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminHidden"
        "400":
          description: Malformed JSON, an invalid account ID, an until not in the future, or a reason too long.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - bad_request
                      - invalid_account
        "401":
          $ref: "#/components/responses/AdminUnauthorized"
        "403":
          $ref: "#/components/responses/AdminForbidden"
        "404":
          $ref: "#/components/responses/AdminUnknownBoard"
        "413":
          $ref: "#/components/responses/RequestTooLarge"
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          $ref: "#/components/responses/Unavailable"

  /admin/v1/leaderboard/boards/{board}/unhide:
    parameters:
      - $ref: "#/components/parameters/Board"
    post:
      operationId: adminUnhide
      summary: End an account's hiding (operators)
      description: Needs leaderboard.hide and is audited as leaderboard.unhide.
      security:
        - adminBearer: []
        - adminSession: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/AdminUnhideRequest"
      responses:
        "204":
          description: The account is visible again.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
        "400":
          description: Malformed JSON or an invalid account ID.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - bad_request
                      - invalid_account
        "401":
          $ref: "#/components/responses/AdminUnauthorized"
        "403":
          $ref: "#/components/responses/AdminForbidden"
        "404":
          description: The board does not exist, or the account is not hidden on it.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - unknown_board
                      - not_hidden
        "413":
          $ref: "#/components/responses/RequestTooLarge"
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          $ref: "#/components/responses/Unavailable"

  /admin/v1/leaderboard/boards/{board}/reset:
    parameters:
      - $ref: "#/components/parameters/Board"
    post:
      operationId: adminReset
      summary: Reset a board now (operators)
      description: >-
        Needs leaderboard.reset and is audited. A daily, weekly or monthly board ends
        its current period at the present second and starts one whose ID is that time
        (20060102T150405Z), running to the end of the period it cut short; the ended
        period becomes the previous one and the board keeps as many earlier periods as
        its keep setting says. An all-time board keeps none, so the reset removes every
        entry. The reset survives a restart, and its audit record counts the entries
        it removed.
      security:
        - adminBearer: []
        - adminSession: []
      responses:
        "200":
          description: The board's new current period and the one the reset ended.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AdminResetResult"
        "401":
          $ref: "#/components/responses/AdminUnauthorized"
        "403":
          $ref: "#/components/responses/AdminForbidden"
        "404":
          $ref: "#/components/responses/AdminUnknownBoard"
        "409":
          description: The current period or the board's last reset began less than a second ago, or later than the present.
          headers:
            Cache-Control:
              $ref: "#/components/headers/CacheControl"
          content:
            application/json:
              schema:
                type: object
                additionalProperties: false
                required:
                  - error
                properties:
                  error:
                    type: string
                    enum:
                      - reset_too_soon
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          $ref: "#/components/responses/Unavailable"

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: Account token
      description: >-
        Signed bearer token from the account service (pkg/online/accounts),
        verified offline with Options.Tokens. The token's subject is the account
        ID. Only a token for the service's audience (Config.TokenAudience,
        "leaderboard" by default) is accepted; a token for game servers is
        invalid_token.

    adminBearer:
      type: http
      scheme: bearer
      bearerFormat: Operator token
      description: >-
        Operator token for the "admin" audience, subject "op:<id>" of an operator in
        operators.yaml, signed by the account service's key (accountsd admin-token).
        Accepted only on the admin listener.

    adminSession:
      type: apiKey
      in: cookie
      name: nsgo_admin_leaderboard
      description: >-
        Operator session cookie from POST /admin/v1/session on the admin listener. A
        state-changing request on a session also carries the session's CSRF token in
        X-CSRF-Token and an allowed Origin.

  parameters:
    Board:
      name: board
      in: path
      required: true
      description: Board name declared in the service configuration.
      schema:
        type: string
        minLength: 1
        maxLength: 64
        pattern: "^[a-z0-9][a-z0-9._-]{0,63}$"

    Period:
      name: period
      in: query
      required: false
      description: >-
        Period selector: "current" (default when omitted or empty), "previous",
        "all" (for all-time boards), or a kept period ID (the UTC start date
        YYYY-MM-DD of a daily or weekly period, the month YYYY-MM of a monthly one,
        or the UTC time YYYYMMDDTHHMMSSZ of an operator's reset).
      schema:
        type: string
        default: current

    Offset:
      name: offset
      in: query
      required: false
      description: Zero-based rank offset (non-negative decimal integer).
      schema:
        type: integer
        minimum: 0
        default: 0

    Limit:
      name: limit
      in: query
      required: false
      description: Maximum number of entries to return (1 to 100).
      schema:
        type: integer
        minimum: 1
        maximum: 100
        default: 25

    Radius:
      name: radius
      in: query
      required: false
      description: Number of entries above and below the authenticated account (0 to 50).
      schema:
        type: integer
        minimum: 0
        maximum: 50
        default: 5

  headers:
    CacheControl:
      description: Every response disables HTTP caching.
      required: true
      schema:
        type: string
        enum:
          - no-store

    WWWAuthenticate:
      description: Bearer challenge returned when authentication fails.
      required: true
      schema:
        type: string
        enum:
          - Bearer error="invalid_token"

  schemas:
    ScoreRequest:
      type: object
      additionalProperties: false
      required:
        - score
      properties:
        score:
          type: integer
          format: int64
          minimum: -9007199254740991
          maximum: 9007199254740991
          description: Score value within the board's configured bounds (at most ±(2^53 - 1)).
        subscore:
          type: integer
          format: int64
          description: Tie-break score, ranked higher first when scores are equal.
        metadata:
          type: object
          additionalProperties: true
          description: Optional JSON metadata retained with the entry.
        proof:
          type: string
          description: >-
            Game server proof ("v1.<key id>.<unix seconds>.<signature>").
            Required on boards with validation: signed; ignored on others.

    FriendsRequest:
      type: object
      additionalProperties: false
      required:
        - accounts
      properties:
        accounts:
          type: array
          maxItems: 200
          items:
            type: string
            minLength: 1
            maxLength: 128
          description: Account IDs to look up (up to 200).

    Period:
      type: object
      additionalProperties: false
      required:
        - id
      properties:
        id:
          type: string
          description: Period ID ("all" for all-time boards, YYYY-MM for a monthly period, YYYYMMDDTHHMMSSZ for a period an operator's reset began, otherwise the UTC start date YYYY-MM-DD).
        start:
          type: string
          format: date-time
          description: UTC start instant in RFC 3339. Omitted for all-time boards.
        end:
          type: string
          format: date-time
          description: UTC end instant (start of the next period) in RFC 3339. Omitted for all-time boards.

    Entry:
      type: object
      additionalProperties: false
      required:
        - rank
        - account
        - score
        - achieved
      properties:
        rank:
          type: integer
          minimum: 1
          description: 1-based overall rank in the period.
        account:
          type: string
          minLength: 1
          maxLength: 128
          description: Account ID.
        score:
          type: integer
          format: int64
          minimum: -9007199254740991
          maximum: 9007199254740991
          description: Account's best score in the period.
        subscore:
          type: integer
          format: int64
          description: Tie-break score.
        metadata:
          type: object
          additionalProperties: true
          description: Optional JSON metadata retained with the entry.
        achieved:
          type: string
          format: date-time
          description: UTC timestamp when the score was achieved, in RFC 3339 (up to nanosecond precision).

    Board:
      type: object
      additionalProperties: false
      required:
        - name
        - order
        - reset
        - current
        - previous
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 64
          pattern: "^[a-z0-9][a-z0-9._-]{0,63}$"
          description: Board name.
        order:
          type: string
          enum:
            - descending
            - ascending
          description: Sort direction ("descending" ranks highest first, "ascending" ranks lowest first).
        reset:
          type: string
          enum:
            - allTime
            - daily
            - weekly
            - monthly
          description: Reset cadence in UTC.
        operator:
          type: string
          enum:
            - best
            - set
            - increment
            - decrement
          description: Submission operator. Omitted means best.
        metadataMaxBytes:
          type: integer
          minimum: 0
          maximum: 4096
        validation:
          type: string
          enum:
            - signed
          description: Present as "signed" when submissions require a game server proof; omitted otherwise.
        current:
          $ref: "#/components/schemas/Period"
        previous:
          type: array
          items:
            $ref: "#/components/schemas/Period"
          description: Readable earlier periods, newest first.

    BoardsResponse:
      type: object
      additionalProperties: false
      required:
        - boards
      properties:
        boards:
          type: array
          items:
            $ref: "#/components/schemas/Board"

    SubmitResult:
      type: object
      additionalProperties: false
      required:
        - period
        - entry
        - total
        - improved
      properties:
        period:
          $ref: "#/components/schemas/Period"
        entry:
          $ref: "#/components/schemas/Entry"
        total:
          type: integer
          minimum: 1
          description: Number of ranked accounts in the period.
        improved:
          type: boolean
          description: True when this submission became the account's new best in the period.

    Page:
      type: object
      additionalProperties: false
      required:
        - board
        - period
        - total
        - entries
      properties:
        board:
          type: string
          minLength: 1
          maxLength: 64
          pattern: "^[a-z0-9][a-z0-9._-]{0,63}$"
          description: Board name.
        period:
          $ref: "#/components/schemas/Period"
        total:
          type: integer
          minimum: 0
          description: Total number of ranked accounts in the period.
        entries:
          type: array
          items:
            $ref: "#/components/schemas/Entry"

    AdminPeriod:
      type: object
      additionalProperties: false
      required:
        - id
        - entries
      properties:
        id:
          type: string
          description: Period ID, as in Period.
        start:
          type: string
          format: date-time
          description: UTC start instant in RFC 3339. Omitted for all-time boards.
        end:
          type: string
          format: date-time
          description: UTC end instant in RFC 3339. Omitted for all-time boards.
        entries:
          type: integer
          minimum: 0
          description: Number of entries the period holds, hidden ones included.

    AdminBoard:
      type: object
      additionalProperties: false
      required:
        - name
        - reset
        - current
        - previous
        - hidden
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 64
          pattern: "^[a-z0-9][a-z0-9._-]{0,63}$"
          description: Board name.
        reset:
          type: string
          enum:
            - allTime
            - daily
            - weekly
            - monthly
          description: Reset cadence in UTC.
        current:
          $ref: "#/components/schemas/AdminPeriod"
        previous:
          type: array
          items:
            $ref: "#/components/schemas/AdminPeriod"
          description: Kept earlier periods, newest first.
        hidden:
          type: integer
          minimum: 0
          description: Number of accounts hidden on the board now.

    AdminBoardsResponse:
      type: object
      additionalProperties: false
      required:
        - boards
      properties:
        boards:
          type: array
          items:
            $ref: "#/components/schemas/AdminBoard"

    AdminEntry:
      type: object
      additionalProperties: false
      required:
        - rank
        - account
        - score
        - achieved
        - hidden
      properties:
        rank:
          type: integer
          minimum: 1
          description: 1-based rank among every entry of the period, hidden ones included.
        account:
          type: string
          minLength: 1
          maxLength: 128
          description: Account ID.
        score:
          type: integer
          format: int64
          minimum: -9007199254740991
          maximum: 9007199254740991
          description: Account's best score in the period.
        subscore:
          type: integer
          format: int64
          description: Tie-break score.
        metadata:
          type: object
          additionalProperties: true
          description: Optional JSON metadata retained with the entry.
        achieved:
          type: string
          format: date-time
          description: UTC timestamp when the score was achieved, in RFC 3339.
        hidden:
          type: boolean
          description: True when the account is hidden from other players now.

    AdminPage:
      type: object
      additionalProperties: false
      required:
        - board
        - period
        - total
        - entries
      properties:
        board:
          type: string
          minLength: 1
          maxLength: 64
          pattern: "^[a-z0-9][a-z0-9._-]{0,63}$"
          description: Board name.
        period:
          $ref: "#/components/schemas/Period"
        total:
          type: integer
          minimum: 0
          description: Number of entries in the period, hidden ones included.
        entries:
          type: array
          items:
            $ref: "#/components/schemas/AdminEntry"

    AdminDeleted:
      type: object
      additionalProperties: false
      required:
        - board
        - account
        - periods
      properties:
        board:
          type: string
          description: Board name.
        account:
          type: string
          description: Account ID.
        periods:
          type: array
          items:
            type: string
          description: IDs of the periods the entry was removed from, newest first; empty when period=all found no entry the service serves.

    AdminHidden:
      type: object
      additionalProperties: false
      required:
        - account
        - at
      properties:
        account:
          type: string
          minLength: 1
          maxLength: 128
          description: Hidden account ID.
        until:
          type: string
          format: date-time
          description: When the hiding ends, in RFC 3339; omitted when it lasts until unhidden.
        reason:
          type: string
          maxLength: 256
          description: The operator's note; never shown to players.
        by:
          type: string
          description: The operator who hid the account, as "op:<id>".
        at:
          type: string
          format: date-time
          description: When the account was hidden, in RFC 3339.

    AdminHiddenList:
      type: object
      additionalProperties: false
      required:
        - hidden
      properties:
        hidden:
          type: array
          items:
            $ref: "#/components/schemas/AdminHidden"

    AdminHideRequest:
      type: object
      additionalProperties: false
      required:
        - account
      properties:
        account:
          type: string
          minLength: 1
          maxLength: 128
          description: Account ID to hide.
        until:
          type: string
          format: date-time
          description: When the hiding ends, an RFC 3339 time in the future; omit to hide until unhidden.
        reason:
          type: string
          maxLength: 256
          description: A note for operators, up to 256 bytes without control characters.

    AdminUnhideRequest:
      type: object
      additionalProperties: false
      required:
        - account
      properties:
        account:
          type: string
          minLength: 1
          maxLength: 128
          description: Account ID to show again.

    AdminResetResult:
      type: object
      additionalProperties: false
      required:
        - board
        - current
      properties:
        board:
          type: string
          description: Board name.
        current:
          $ref: "#/components/schemas/Period"
        previous:
          $ref: "#/components/schemas/Period"

  responses:
    BadRequest:
      description: Malformed or out-of-range request parameter.
      headers:
        Cache-Control:
          $ref: "#/components/headers/CacheControl"
      content:
        application/json:
          schema:
            type: object
            additionalProperties: false
            required:
              - error
            properties:
              error:
                type: string
                enum:
                  - bad_request

    InvalidToken:
      description: Missing, expired or invalid bearer token.
      headers:
        Cache-Control:
          $ref: "#/components/headers/CacheControl"
        WWW-Authenticate:
          $ref: "#/components/headers/WWWAuthenticate"
      content:
        application/json:
          schema:
            type: object
            additionalProperties: false
            required:
              - error
            properties:
              error:
                type: string
                enum:
                  - invalid_token

    RequestTooLarge:
      description: Request body exceeds 64 KiB.
      headers:
        Cache-Control:
          $ref: "#/components/headers/CacheControl"
      content:
        application/json:
          schema:
            type: object
            additionalProperties: false
            required:
              - error
            properties:
              error:
                type: string
                enum:
                  - request_too_large

    Unavailable:
      description: Request was cancelled or timed out.
      headers:
        Cache-Control:
          $ref: "#/components/headers/CacheControl"
      content:
        application/json:
          schema:
            type: object
            additionalProperties: false
            required:
              - error
            properties:
              error:
                type: string
                enum:
                  - unavailable

    InternalError:
      description: Unexpected server error.
      headers:
        Cache-Control:
          $ref: "#/components/headers/CacheControl"
      content:
        application/json:
          schema:
            type: object
            additionalProperties: false
            required:
              - error
            properties:
              error:
                type: string
                enum:
                  - internal

    AdminUnauthorized:
      description: No operator session or token, or an invalid one.
      headers:
        Cache-Control:
          $ref: "#/components/headers/CacheControl"
      content:
        application/json:
          schema:
            type: object
            additionalProperties: false
            required:
              - error
            properties:
              error:
                type: string
                enum:
                  - unauthorized

    AdminForbidden:
      description: >-
        The operator lacks the route's permission (forbidden, naming it), or a
        session request failed the CSRF and Origin check (csrf).
      headers:
        Cache-Control:
          $ref: "#/components/headers/CacheControl"
      content:
        application/json:
          schema:
            type: object
            additionalProperties: false
            required:
              - error
            properties:
              error:
                type: string
                enum:
                  - forbidden
                  - csrf
              permission:
                type: string
                description: The permission the route needs.

    AdminUnknownBoard:
      description: The board does not exist.
      headers:
        Cache-Control:
          $ref: "#/components/headers/CacheControl"
      content:
        application/json:
          schema:
            type: object
            additionalProperties: false
            required:
              - error
            properties:
              error:
                type: string
                enum:
                  - unknown_board
