use axum::{extract::{Extension, Path}, Json};
use uuid::Uuid;

use crate::{app_state::{AppState, MarketSnapshot, OddsVersionSnapshot}, error::AppError};

pub async fn list_for_event(
    Path(event_id): Path<Uuid>,
    Extension(state): Extension<AppState>,
) -> Result<Json<Vec<MarketSnapshot>>, AppError> {
    let Some(markets) = state.markets_for_event(event_id).await else {
        return Err(AppError::not_found("Markets not found"));
    };
    Ok(Json(markets))
}

pub async fn current_odds(
    Path(market_id): Path<Uuid>,
    Extension(state): Extension<AppState>,
) -> Result<Json<OddsVersionSnapshot>, AppError> {
    let Some(odds) = state.current_odds(market_id).await else {
        return Err(AppError::not_found("Current odds not found"));
    };
    Ok(Json(odds))
}
