use axum::{extract::{Extension, Json}, http::StatusCode};

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

pub async fn create_event(
    Extension(state): Extension<AppState>,
    Json(payload): Json<EventManifestSnapshot>,
) -> Result<(StatusCode, Json<EventManifestSnapshot>), AppError> {
    let created = state.admin_create_event_manifest(payload).await?;
    Ok((StatusCode::CREATED, Json(created)))
}

pub async fn create_market(
    Extension(state): Extension<AppState>,
    Json(payload): Json<MarketSnapshot>,
) -> Result<(StatusCode, Json<MarketSnapshot>), AppError> {
    let created = state.admin_create_market(payload).await?;
    Ok((StatusCode::CREATED, Json(created)))
}

pub async fn create_odds(
    Extension(state): Extension<AppState>,
    Json(payload): Json<OddsVersionSnapshot>,
) -> Result<(StatusCode, Json<OddsVersionSnapshot>), AppError> {
    let created = state.admin_publish_odds(payload).await?;
    Ok((StatusCode::CREATED, Json(created)))
}

pub async fn create_settlement(
    Extension(state): Extension<AppState>,
    Json(payload): Json<SettlementSnapshot>,
) -> Result<(StatusCode, Json<SettlementSnapshot>), AppError> {
    let created = state.admin_publish_settlement(payload).await?;
    Ok((StatusCode::CREATED, Json(created)))
}
