use crate::state::AppState;
use axum::{
    extract::State,
    http::StatusCode,
    response::{IntoResponse, Json},
    routing::get,
    Router,
};
use common_contracts::observability::TaskProgress;

pub fn create_router(state: AppState) -> Router {
    Router::new()
        .route("/health", get(health_check))
        .route("/tasks", get(get_tasks))
        .with_state(state)
}

async fn health_check() -> impl IntoResponse {
    (StatusCode::OK, "OK")
}

async fn get_tasks(State(state): State<AppState>) -> impl IntoResponse {
    let tasks: Vec<TaskProgress> = state.tasks.iter().map(|r| r.value().clone()).collect();
    Json(tasks)
}

