//! Example: practical insert -> fetch -> update -> delete workflow.
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>> {
    let client: AthenaClient =
        AthenaClient::new("http://localhost:4052", "secret", "reporting").await?;

    let email: &str = "workflow.user@example.com";

    let inserted: QueryResult = client
        .insert("users")
        .payload(json!({
            "email": email,
            "name": "Workflow User",
            "status": "pending"
        }))
        .execute()
        .await?;

    println!("Inserted rows: {}", inserted.rows.len());

    let fetched: QueryResult = client
        .fetch("users")
        .columns(["id", "email", "status"])
        .where_eq("email", email)
        .limit(1)
        .execute()
        .await?;

    println!("Fetched rows: {}", fetched.rows.len());

    let updated: QueryResult = client
        .update("users")
        .where_eq("email", email)
        .payload(json!({ "status": "active" }))
        .execute()
        .await?;

    println!("Updated rows: {}", updated.rows.len());

    let deleted: QueryResult = client
        .delete("users")
        .where_eq("email", email)
        .execute()
        .await?;

    println!("Deleted rows: {}", deleted.rows.len());

    Ok(())
}
