//! Athena router data access.
//!
//! This module provides functions for accessing Athena router entries stored in the
//! Suitsbooks Supabase project. Router entries define routing configurations used by
//! the Athena system.

use serde_json::Value;
use supabase_rs::SupabaseClient;
// use tracing::error;

use crate::data::suitsbooks_supabase;

/// Fetch all Athena router entries from Supabase.
///
/// Retrieves all router entries from the `pm_athena_router` table in the Suitsbooks
/// Supabase project.
///
/// # Returns
///
/// Returns `Result<Vec<Value>, String>` where:
/// - `Ok(Vec<Value>)` contains the list of router entries on success
/// - `Err(String)` contains a formatted error message on failure
///
/// # Example
///
/// ```ignore
/// match list_athena_router_entries().await {
///     Ok(entries) => println!("Found {} entries", entries.len()),
///     Err(e) => eprintln!("Error: {}", e),
/// }
/// ```
pub async fn list_athena_router_entries() -> Result<Vec<Value>, String> {
    let client: SupabaseClient = suitsbooks_supabase().await;

    let data: Result<Vec<Value>, String> = client
        .select("pm_athena_router")
        .columns(["*"].to_vec())
        .execute()
        .await;

    match data {
        Ok(result) => Ok(result),
        Err(err) => Err(format!(
            "Failed to fetch list_athena_router_entries data: {:?}",
            err
        )),
    }
}
