//! Athena
//!
//! A lightweight Database Gateway that proxies and executes queries across multiple backends
//! (Athena/ScyllaDB, PostgreSQL, and Supabase) with simple caching and routing.
//!
//! - Provides REST endpoints for executing SQL against supported drivers
//! - Proxies arbitrary requests while handling auth headers and basic response shaping
//! - Exposes a small set of utilities for driver execution and routing

// re-exports intentionally minimal in lib
use api::pipelines::PipelineDefinition;
use moka::future::Cache;
use reqwest::Client;
use serde_json::Value;
use std::collections::HashMap;

use crate::drivers::postgresql::sqlx_driver::PostgresClientRegistry;
use std::sync::Arc;

/// REST API surface, endpoints and request handlers.
pub mod api;
/// Athena client SDK with unified query helpers.
pub mod client;
/// Utils for configuration
pub mod config;
/// Data access helpers and Supabase clients used by endpoints.
pub mod data;
/// Database driver integrations (Scylla/Athena, PostgreSQL, Supabase).
pub mod drivers;
/// Error processing and sanitization utilities.
pub mod error;
/// Parsers and helpers related to SQL processing.
pub mod parser;
/// Reverse proxy that forwards requests to the configured target services.
pub mod proxy_request;

pub mod bootstrap;
pub mod cli;

/// HTTP routing helpers and target URL determination.
pub mod router;

pub mod cdc;

/// Shared Actix application state.
pub struct AppState {
    /// Short‑lived response cache for JSON payloads.
    pub cache: Arc<Cache<String, Value>>,
    /// Non‑expiring cache for values that should persist across requests.
    pub immortal_cache: Arc<Cache<String, Value>>,
    /// Shared Reqwest client used by the proxy and endpoints.
    pub client: Client,
    /// Registry of Postgres connections keyed by logical client name.
    pub pg_registry: Arc<PostgresClientRegistry>,
    /// When true, gateway fetch routes force camelCase column names to snake_case.
    pub gateway_force_camel_case_to_snake_case: bool,
    /// Optional registry of prebuilt pipeline definitions by name.
    pub pipeline_registry: Option<Arc<HashMap<String, PipelineDefinition>>>,
    /// Optional Postgres client (by name) that receives gateway logs.
    pub logging_client_name: Option<String>,
}

/// Wrapper for the non‑expiring cache used by some endpoints.
pub struct ImmortalCache {
    /// Non‑expiring cache instance.
    pub cache: Arc<Cache<String, Value>>,
}

/// Miscellaneous utilities (logging, helpers).
pub mod utils;

pub use client::AthenaClient;
pub use client::backend::BackendType;
pub use client::builder::AthenaClientBuilder;
