use log::{error, info};
use crate::pg::get_pool;
use sqlx::types::BigDecimal;

#[utoipa::path(
    post,
    path = "/examples/single",
    responses(
        (status = 200, description = "Example Loaded"),
        (status = NOT_FOUND, description = "Example not found")
    )
)]
pub async fn single() -> Result<(), ()> {
    info!("Got request for single example");

    info!("Getting pool...");
    let pool = get_pool().await.map_err(|e| {
        error!("Failed to get pool: {:?}", e);
    })?;

    info!("Querying database...");
    let query = r#"SELECT "name", "mass_kg", "binding_energy_mev" FROM particle_types WHERE binding_energy_mev > 0.0"#;
    let row: (String,BigDecimal,BigDecimal) = sqlx::query_as(query)
        // .bind(150_i64)
        .fetch_one(pool)
        .await
        .map_err(|e| {
            error!("Failed to fetch row: {:?}", e);
        })?;

    info!("row: {:?}", row);

    Ok(())
}
