//! JSON API handlers

use axum::{
    extract::{State, Path},
    response::Json,
    http::StatusCode,
};
use sqlx::SqlitePool;
use serde::Serialize;

#[derive(Clone)]
pub struct AppState {
    pub pool: SqlitePool,
}

#[derive(Serialize)]
pub struct PlayerJson {
    pub id: i64,
    pub name: String,
    pub rating: f64,
}

#[derive(Serialize)]
pub struct LeaderboardEntry {
    pub rank: usize,
    pub player: PlayerJson,
}

pub async fn api_players_handler(
    State(_state): State<AppState>,
) -> Json<Vec<PlayerJson>> {
    Json(vec![])
}

pub async fn api_player_details_handler(
    State(_state): State<AppState>,
    Path(_player_id): Path<i64>,
) -> Result<Json<PlayerJson>, (StatusCode, String)> {
    Err((StatusCode::NOT_FOUND, "Player not found".to_string()))
}

pub async fn api_leaderboard_handler(
    State(_state): State<AppState>,
) -> Json<Vec<LeaderboardEntry>> {
    Json(vec![])
}
