//! Configuration models shared across AthenaClient pipelines.
use crate::client::backend::BackendType;
use std::time::Duration;

/// High level configuration for Athena clients.
#[derive(Clone, Debug)]
pub struct ClientConfig {
    pub backend_type: BackendType,
    pub connection: ConnectionConfig,
    pub pool: PoolConfig,
    pub health: HealthConfig,
}

impl ClientConfig {
    pub fn new(
        backend_type: BackendType,
        connection: ConnectionConfig,
        pool: PoolConfig,
        health: HealthConfig,
    ) -> Self {
        Self {
            backend_type,
            connection,
            pool,
            health,
        }
    }
}

/// Connection-specific options.
#[derive(Clone, Debug)]
pub struct ConnectionConfig {
    pub url: String,
    pub key: Option<String>,
    pub ssl: bool,
    pub port: Option<u16>,
    pub database: Option<String>,
}

impl ConnectionConfig {
    pub fn new(url: impl Into<String>) -> Self {
        Self {
            url: url.into(),
            key: None,
            ssl: true,
            port: None,
            database: None,
        }
    }

    pub fn with_key(mut self, key: impl Into<String>) -> Self {
        self.key = Some(key.into());
        self
    }
}

/// Pool configuration shared by JDBC/Postgres backends.
#[derive(Clone, Debug)]
pub struct PoolConfig {
    pub max_connections: u32,
    pub min_connections: u32,
    pub connection_timeout: Duration,
    pub idle_timeout: Duration,
}

impl Default for PoolConfig {
    fn default() -> Self {
        Self {
            max_connections: 50,
            min_connections: 5,
            connection_timeout: Duration::from_secs(5),
            idle_timeout: Duration::from_secs(300),
        }
    }
}

/// Health tracking configuration (circuit breaker, probes).
#[derive(Clone, Debug)]
pub struct HealthConfig {
    pub enabled: bool,
    pub check_interval: Duration,
    pub circuit_breaker_threshold: u32,
    pub circuit_breaker_timeout: Duration,
}

impl Default for HealthConfig {
    fn default() -> Self {
        Self {
            enabled: true,
            check_interval: Duration::from_secs(30),
            circuit_breaker_threshold: 5,
            circuit_breaker_timeout: Duration::from_secs(60),
        }
    }
}
