use axum::{
    extract::{Extension, Path},
    http::StatusCode,
    response::IntoResponse,
    routing::{get, Router},
};
use std::collections::HashMap;

use super::{get_page, AppState};

pub fn get_router() -> Router {
    Router::new()
        .route("/", get(garden))
        .route("/:page", get(page))
}

async fn garden(state: Extension<AppState>) -> Result<impl IntoResponse, StatusCode> {
    get_page(&state.db, "garden").await
}

async fn page(
    state: Extension<AppState>,
    Path(params): Path<HashMap<String, String>>,
) -> Result<impl IntoResponse, StatusCode> {
    let page_id: &String = params.get("page").unwrap();
    get_page(&state.db, page_id).await
}
