//! Configuration test fixtures
//!
//! Provides test configurations for various components.

use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use tempfile::TempDir;

/// Test configuration builder
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct TestConfig {
    pub database_url: String,
    pub storage_path: PathBuf,
    pub max_connections: u32,
    pub timeout_seconds: u64,
}

impl TestConfig {
    /// Create default test configuration
    pub fn default_test() -> Self {
        Self {
            database_url: "postgresql://foxhunt:foxhunt_dev_password@localhost:5432/foxhunt"
                .to_string(),
            storage_path: PathBuf::from("/tmp/foxhunt_test"),
            max_connections: 5,
            timeout_seconds: 30,
        }
    }

    /// Create configuration with temporary directory
    pub fn with_temp_dir(temp_dir: &TempDir) -> Self {
        Self {
            database_url: "postgresql://foxhunt:foxhunt_dev_password@localhost:5432/foxhunt"
                .to_string(),
            storage_path: temp_dir.path().to_path_buf(),
            max_connections: 5,
            timeout_seconds: 30,
        }
    }
}

/// ML training test configuration
#[derive(Clone, Debug)]
pub struct MLTestConfig {
    pub batch_size: usize,
    pub learning_rate: f64,
    pub epochs: usize,
    pub checkpoint_dir: PathBuf,
}

impl MLTestConfig {
    pub fn default_test() -> Self {
        Self {
            batch_size: 32,
            learning_rate: 0.001,
            epochs: 10,
            checkpoint_dir: PathBuf::from("/tmp/foxhunt_checkpoints"),
        }
    }

    pub fn with_temp_dir(temp_dir: &TempDir) -> Self {
        Self {
            batch_size: 32,
            learning_rate: 0.001,
            epochs: 10,
            checkpoint_dir: temp_dir.path().to_path_buf(),
        }
    }
}

/// Risk engine test configuration
#[derive(Clone, Debug)]
pub struct RiskTestConfig {
    pub var_confidence: f64,
    pub max_position_size: f64,
    pub circuit_breaker_threshold: f64,
}

impl RiskTestConfig {
    pub fn default_test() -> Self {
        Self {
            var_confidence: 0.99,
            max_position_size: 100000.0,
            circuit_breaker_threshold: 0.10,
        }
    }

    pub fn conservative() -> Self {
        Self {
            var_confidence: 0.99,
            max_position_size: 50000.0,
            circuit_breaker_threshold: 0.05,
        }
    }

    pub fn aggressive() -> Self {
        Self {
            var_confidence: 0.95,
            max_position_size: 200000.0,
            circuit_breaker_threshold: 0.15,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_default_config() {
        let config = TestConfig::default_test();
        assert_eq!(config.max_connections, 5);
        assert_eq!(config.timeout_seconds, 30);
    }

    #[test]
    fn test_ml_config() {
        let config = MLTestConfig::default_test();
        assert_eq!(config.batch_size, 32);
        assert_eq!(config.learning_rate, 0.001);
    }

    #[test]
    fn test_risk_configs() {
        let conservative = RiskTestConfig::conservative();
        let aggressive = RiskTestConfig::aggressive();

        assert!(conservative.max_position_size < aggressive.max_position_size);
        assert!(conservative.circuit_breaker_threshold < aggressive.circuit_breaker_threshold);
    }
}
