{
  "openapi": "3.1.0",
  "info": {
    "title": "MatchDoku API",
    "version": "1.0.0",
    "description": "Health, public leaderboards, guest ids, emailed OTP sign-in, and daily puzzles for MatchDoku."
  },
  "servers": [
    {
      "url": "https://matchdoku.com"
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "summary": "Process health",
        "operationId": "getHealth",
        "responses": {
          "200": {
            "description": "The API process is up.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "ok": { "type": "boolean" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/leaderboard": {
      "get": {
        "summary": "Public leaderboard",
        "operationId": "getLeaderboard",
        "parameters": [
          {
            "name": "difficulty",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["easy", "medium", "hard", "expert", "extreme"]
            }
          },
          {
            "name": "mode",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["random", "daily", "progression"],
              "default": "random"
            }
          },
          {
            "name": "date",
            "in": "query",
            "required": false,
            "description": "UTC date YYYY-MM-DD. Required when mode is daily.",
            "schema": { "type": "string", "format": "date" }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": { "type": "integer", "minimum": 1, "maximum": 50, "default": 10 }
          }
        ],
        "responses": {
          "200": {
            "description": "Best run per signed-in player on that board."
          }
        }
      }
    },
    "/api/guest": {
      "post": {
        "summary": "Issue a guest id",
        "operationId": "createGuest",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "type": "object" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Opaque guest id for unsigned play."
          }
        }
      }
    },
    "/api/auth/otp/request": {
      "post": {
        "summary": "Email a one-time sign-in code",
        "operationId": "requestOtp",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email"],
                "properties": {
                  "email": { "type": "string", "format": "email" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Code sent (or shown in development)."
          }
        }
      }
    },
    "/api/auth/otp/verify": {
      "post": {
        "summary": "Exchange an OTP for a session token",
        "operationId": "verifyOtp",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["email", "code"],
                "properties": {
                  "email": { "type": "string", "format": "email" },
                  "code": { "type": "string" },
                  "guestId": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bearer token and user profile."
          }
        }
      }
    },
    "/api/me": {
      "get": {
        "summary": "Current signed-in user",
        "operationId": "getMe",
        "security": [{ "bearerAuth": [] }],
        "responses": {
          "200": { "description": "The authenticated user." },
          "401": { "description": "Missing or invalid bearer token." }
        }
      }
    },
    "/api/daily-puzzle": {
      "get": {
        "summary": "Shared daily puzzle",
        "operationId": "getDailyPuzzle",
        "parameters": [
          {
            "name": "difficulty",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["easy", "medium", "hard", "expert", "extreme"]
            }
          },
          {
            "name": "date",
            "in": "query",
            "required": false,
            "schema": { "type": "string", "format": "date" }
          }
        ],
        "responses": {
          "200": { "description": "The daily grid for that UTC date and difficulty." }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    }
  }
}
