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

use crate::{app_state::{AppState, BetIntentRequest, BetIntentResponse}, error::AppError};

pub async fn submit(
    Extension(state): Extension<AppState>,
    Json(payload): Json<BetIntentRequest>,
) -> Result<(StatusCode, Json<BetIntentResponse>), AppError> {
    let response = state.submit_bet_intent(payload).await;
    Ok((StatusCode::CREATED, Json(response)))
}

pub async fn show(
    Path(bet_intent_id): Path<Uuid>,
    Extension(state): Extension<AppState>,
) -> Result<Json<BetIntentResponse>, AppError> {
    let Some(intent) = state.bet_intent(bet_intent_id).await else {
        return Err(AppError::not_found("Bet intent not found"));
    };

    Ok(Json(intent))
}
