//! Example: define shared filter conditions once and reuse them.
use athena_rs::{AthenaClient, Condition, ConditionOperator};
use serde_json::json;
use std::error::Error;

fn base_filters() -> Vec<Condition> {
    vec![
        Condition::new("workspace_id", ConditionOperator::Eq, vec![json!("ws_123")]),
        Condition::new("archived", ConditionOperator::Eq, vec![json!(false)]),
    ]
}

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let client = AthenaClient::new("http://localhost:4052", "secret", "reporting").await?;
    let shared = base_filters();

    let fetch_result = client
        .fetch("projects")
        .columns(["id", "name", "status"])
        .where_conditions(shared.clone())
        .limit(10)
        .execute()
        .await?;
    println!("Fetched rows: {}", fetch_result.rows.len());

    let update_result = client
        .update("projects")
        .where_conditions(shared.clone())
        .where_eq("status", "pending")
        .payload(json!({ "status": "active" }))
        .execute()
        .await?;
    println!("Updated rows: {}", update_result.rows.len());

    let delete_result = client
        .delete("projects")
        .where_conditions(shared)
        .where_eq("status", "archived")
        .execute()
        .await?;
    println!("Deleted rows: {}", delete_result.rows.len());

    Ok(())
}
