//! Configuration module for the server
//!
//! This module provides configuration management with support for TOML files,
//! environment variable overrides, encryption, and validation.

// Module definitions
#[allow(clippy::module_inception)]
pub mod config;
pub mod defs;
#[cfg(feature = "crypto")]
pub mod encryption;
pub mod features;
#[cfg(test)]
mod tests;

// Re-exports
use std::path::PathBuf;

pub use config::Config;
pub use defs::*;
#[cfg(feature = "crypto")]
pub use encryption::ConfigEncryption;
pub use features::FeatureConfig;

// TLS configuration functions
#[cfg(feature = "tls")]
#[allow(dead_code)]
pub async fn create_tls_config(
    cert_path: &PathBuf,
    key_path: &PathBuf,
) -> Result<axum_rustelo_server::tls_rustls::RustlsConfig, ConfigError> {
    axum_rustelo_server::tls_rustls::RustlsConfig::from_pem_file(cert_path, key_path)
        .await
        .map_err(|e| ConfigError::ValidationError(format!("Failed to load TLS config: {}", e)))
}

#[cfg(not(feature = "tls"))]
#[allow(dead_code)]
pub async fn create_tls_config(
    _cert_path: &PathBuf,
    _key_path: &PathBuf,
) -> Result<(), ConfigError> {
    Err(ConfigError::ValidationError(
        "TLS support not compiled in".to_string(),
    ))
}
