//! 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
    let native: AthenaClient =
        AthenaClient::new("postgres://localhost:5432/athena", "secret").await?;

    // Variant backends
    let supabase: AthenaClient =
        AthenaClient::new("https://project.supabase.co", "service-role-key").await?;

    let scylla: AthenaClient = AthenaClient::new_with_backend(
        "127.0.0.1:9042",
        "password",
        athena_rs::BackendType::Scylla,
    )
    .await?;

    let _neon: AthenaClient =
        AthenaClient::new_with_backend("https://neon.com", "key", athena_rs::BackendType::Neon)
            .await?;

    let _postgrest: AthenaClient = AthenaClient::new_with_backend(
        "https://postgrest.com",
        "key",
        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(())
}
