//! Example showing how to instantiate the new AthenaClient SDK.
use athena_rs::AthenaClient;
use athena_rs::client::backend::QueryResult;
use serde_json::json;
use std::error::Error;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    // Native SQL backend via gateway routing (`X-Athena-Client: reporting`)
    let native: AthenaClient =
        AthenaClient::new("http://localhost:4052", "secret", "reporting").await?;

    // Variant backends
    let supabase: AthenaClient =
        AthenaClient::new("http://localhost:4052", "service-role-key", "supabase").await?;

    let scylla: AthenaClient = AthenaClient::new_with_backend(
        "http://localhost:4052",
        "password",
        "scylla",
        athena_rs::BackendType::Scylla,
    )
    .await?;

    let _neon: AthenaClient = AthenaClient::new_with_backend(
        "http://localhost:4052",
        "key",
        "reporting",
        athena_rs::BackendType::Neon,
    )
    .await?;

    let _postgrest: AthenaClient = AthenaClient::new_with_backend(
        "http://localhost:4052",
        "key",
        "reporting",
        athena_rs::BackendType::Postgrest,
    )
    .await?;

    let rows: QueryResult = native
        .select("users")
        .columns(vec!["id", "email"])
        .where_eq("status", "active")
        .limit(5)
        .execute()
        .await?;

    println!("Native rows: {rows:?}");

    supabase
        .insert("logs")
        .payload(json!({"message": "sdk started"}))
        .execute()
        .await?;

    // Use raw execution for CQL
    scylla
        .execute_cql("SELECT * FROM users WHERE id = 'abcd-1234' LIMIT 1")
        .await?;

    Ok(())
}
