{
  "openapi": "3.0.3",
  "info": {
    "title": "MCRanks Public Tier API",
    "version": "2.0.0",
    "description": "Public read-only API for MCRanks player profiles, gamemode tier boards, overall rankings, and player search. Current GET endpoints do not require authentication."
  },
  "servers": [
    {
      "url": "/api/v2"
    }
  ],
  "tags": [
    {
      "name": "System"
    },
    {
      "name": "Players"
    },
    {
      "name": "Rankings"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "tags": [
          "System"
        ],
        "summary": "Health check",
        "responses": {
          "200": {
            "description": "API process is responding",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string"
                    },
                    "service": {
                      "type": "string"
                    },
                    "version": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/modes": {
      "get": {
        "tags": [
          "System"
        ],
        "summary": "List supported gamemodes",
        "responses": {
          "200": {
            "description": "Mode keys and labels",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "key": {
                            "type": "string"
                          },
                          "name": {
                            "type": "string"
                          },
                          "url": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/rankings/overall": {
      "get": {
        "tags": [
          "Rankings"
        ],
        "summary": "Get overall leaderboard",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "minimum": 0,
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paged overall leaderboard",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      }
                    },
                    "meta": {
                      "type": "object",
                      "properties": {
                        "limit": {
                          "type": "integer"
                        },
                        "offset": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        },
                        "has_more": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/BackendUnavailable"
          }
        }
      }
    },
    "/rankings/{mode}": {
      "get": {
        "tags": [
          "Rankings"
        ],
        "summary": "Get a gamemode tier board",
        "parameters": [
          {
            "name": "mode",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "uhc",
                "sword",
                "mace",
                "vanilla",
                "netherite_pot",
                "smp",
                "axe_shield",
                "diamond_smp"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tier board grouped into tier1\u2013tier5 and ht/lt buckets",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "object",
                      "properties": {
                        "mode": {
                          "type": "object"
                        },
                        "tiers": {
                          "type": "object"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "503": {
            "$ref": "#/components/responses/BackendUnavailable"
          }
        }
      }
    },
    "/players/{username}": {
      "get": {
        "tags": [
          "Players"
        ],
        "summary": "Get profile by Minecraft username",
        "parameters": [
          {
            "name": "username",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Player profile",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PlayerProfile"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "503": {
            "$ref": "#/components/responses/BackendUnavailable"
          }
        }
      }
    },
    "/players/uuid/{uuid}": {
      "get": {
        "tags": [
          "Players"
        ],
        "summary": "Get profile by Minecraft UUID",
        "parameters": [
          {
            "name": "uuid",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Player profile",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "$ref": "#/components/schemas/PlayerProfile"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "503": {
            "$ref": "#/components/responses/BackendUnavailable"
          }
        }
      }
    },
    "/players": {
      "get": {
        "tags": [
          "Players"
        ],
        "summary": "Search player usernames",
        "parameters": [
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Up to 10 matching usernames",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "username": {
                            "type": "string"
                          },
                          "url": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "503": {
            "$ref": "#/components/responses/BackendUnavailable"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "TierMetadata": {
        "type": "object",
        "required": [
          "tier",
          "level",
          "kind",
          "points",
          "label"
        ],
        "properties": {
          "tier": {
            "type": "string",
            "example": "HT1"
          },
          "level": {
            "type": "integer",
            "minimum": 0,
            "maximum": 5
          },
          "kind": {
            "type": "string",
            "nullable": true,
            "enum": [
              "HT",
              "LT",
              null
            ]
          },
          "points": {
            "type": "integer"
          },
          "label": {
            "type": "string"
          }
        }
      },
      "PlayerProfile": {
        "type": "object",
        "properties": {
          "username": {
            "type": "string"
          },
          "uuid": {
            "type": "string"
          },
          "location": {
            "type": "string",
            "description": "Canonical stored region: NORTH_AMERICA, EUROPE, ASIA, AUSTRALIA, or SOUTH_AMERICA."
          },
          "rank": {
            "type": "integer",
            "nullable": true
          },
          "points": {
            "type": "object",
            "additionalProperties": {
              "type": "integer"
            }
          },
          "modes": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "properties": {
                "current": {
                  "$ref": "#/components/schemas/TierMetadata"
                },
                "peak": {
                  "$ref": "#/components/schemas/TierMetadata"
                },
                "previous": {
                  "$ref": "#/components/schemas/TierMetadata"
                },
                "points": {
                  "type": "integer"
                }
              }
            }
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "responses": {
      "NotFound": {
        "description": "Player or gamemode not found",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "BackendUnavailable": {
        "description": "Database/backend temporarily unavailable",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}
