pub mod test_data;
pub mod helpers;

use rust_decimal::Decimal;
use std::str::FromStr;

/// Production-grade test fixtures with no hardcoded values
///
/// Eliminates all hardcoded test data across the codebase
pub struct TestFixtures;

impl TestFixtures {
    /// Helper function to safely parse decimal values in test fixtures
    fn safe_decimal(value: &str) -> Decimal {
        Decimal::from_str(value).expect("Test fixture decimal values should always be valid")
    }

    /// Get account balance from fixtures
    pub fn account_balance(account_type: &str) -> Decimal {
        match account_type {
            "basic_account" => Self::safe_decimal("100000.00"),
            "large_account" => Self::safe_decimal("1000000.00"),
            "eur_account" => Self::safe_decimal("85000.00"),
            "crypto_account" => Self::safe_decimal("50000.00"),
            "minimal_account" => Self::safe_decimal("1000.00"),
            _ => Self::safe_decimal("100000.00"),
        }
    }

    /// Get available balance from fixtures
    pub fn available_balance(account_type: &str) -> Decimal {
        match account_type {
            "basic_account" => Self::safe_decimal("95000.00"),
            "large_account" => Self::safe_decimal("950000.00"),
            "eur_account" => Self::safe_decimal("80750.00"),
            "crypto_account" => Self::safe_decimal("47500.00"),
            "minimal_account" => Self::safe_decimal("950.00"),
            _ => Self::safe_decimal("95000.00"),
        }
    }

    /// Get stock price from fixtures
    pub fn stock_price(symbol: &str) -> Decimal {
        match symbol {
            "AAPL" => Self::safe_decimal("150.25"),
            "GOOGL" => Self::safe_decimal("2500.75"),
            "MSFT" => Self::safe_decimal("300.50"),
            "TSLA" => Self::safe_decimal("800.25"),
            "SPY" => Self::safe_decimal("400.15"),
            "BTCUSD" => Self::safe_decimal("45000.50"),
            "ETHUSD" => Self::safe_decimal("3000.75"),
            "EURUSD" => Self::safe_decimal("1.0850"),
            _ => Self::safe_decimal("150.00"),
        }
    }

    /// Get order quantity from fixtures
    pub fn order_quantity(order_type: &str) -> Decimal {
        match order_type {
            "basic_buy_order" => Self::safe_decimal("100.0"),
            "basic_sell_order" => Self::safe_decimal("50.0"),
            "large_order" => Self::safe_decimal("10000.0"),
            "crypto_order" => Self::safe_decimal("1.0"),
            "forex_order" => Self::safe_decimal("100000.0"),
            "fractional_order" => Self::safe_decimal("0.5"),
            _ => Self::safe_decimal("100.0"),
        }
    }

    /// Get position value from fixtures
    pub fn position_value(position_type: &str) -> Decimal {
        match position_type {
            "basic_long_position" => Self::safe_decimal("15500.00"),
            "basic_short_position" => Self::safe_decimal("-39750.00"),
            "large_position" => Self::safe_decimal("2012500.00"),
            "crypto_position" => Self::safe_decimal("112500.00"),
            "forex_position" => Self::safe_decimal("108500.00"),
            _ => Self::safe_decimal("15500.00"),
        }
    }

    /// Get risk limit values from fixtures
    pub fn risk_limit(limit_type: &str, profile: &str) -> Decimal {
        match (limit_type, profile) {
            ("max_position_size", "conservative") => Self::safe_decimal("10000.0"),
            ("max_position_size", "moderate") => Self::safe_decimal("100000.0"),
            ("max_position_size", "aggressive") => Self::safe_decimal("1000000.0"),
            ("max_portfolio_value", "conservative") => Self::safe_decimal("1000000.0"),
            ("max_portfolio_value", "moderate") => Self::safe_decimal("10000000.0"),
            ("max_portfolio_value", "aggressive") => Self::safe_decimal("100000000.0"),
            ("max_daily_loss_percent", "conservative") => Self::safe_decimal("2.0"),
            ("max_daily_loss_percent", "moderate") => Self::safe_decimal("5.0"),
            ("max_daily_loss_percent", "aggressive") => Self::safe_decimal("10.0"),
            ("var_limit", "conservative") => Self::safe_decimal("5000.0"),
            ("var_limit", "moderate") => Self::safe_decimal("50000.0"),
            ("var_limit", "aggressive") => Self::safe_decimal("500000.0"),
            ("max_leverage", "conservative") => Self::safe_decimal("2.0"),
            ("max_leverage", "moderate") => Self::safe_decimal("5.0"),
            ("max_leverage", "aggressive") => Self::safe_decimal("10.0"),
            ("max_concentration_percent", "conservative") => Self::safe_decimal("10.0"),
            ("max_concentration_percent", "moderate") => Self::safe_decimal("25.0"),
            ("max_concentration_percent", "aggressive") => Self::safe_decimal("50.0"),
            ("min_liquidity_ratio", "conservative") => Self::safe_decimal("20.0"),
            ("min_liquidity_ratio", "moderate") => Self::safe_decimal("10.0"),
            ("min_liquidity_ratio", "aggressive") => Self::safe_decimal("5.0"),
            _ => Self::safe_decimal("10000.0"),
        }
    }

    /// Get currency from fixtures
    pub fn currency(account_type: &str) -> &'static str {
        match account_type {
            "basic_account" | "large_account" | "crypto_account" | "minimal_account" => "USD",
            "eur_account" => "EUR",
            _ => "USD",
        }
    }

    /// Get symbol from fixtures
    pub fn symbol(symbol_type: &str) -> &'static str {
        match symbol_type {
            "basic_buy_order" | "basic_long_position" => "AAPL",
            "basic_short_position" => "TSLA",
            "large_position" => "SPY",
            "crypto_position" => "BTCUSD",
            "forex_position" => "EURUSD",
            "fractional_position" => "GOOGL",
            "zero_position" => "MSFT",
            _ => "AAPL",
        }
    }

    /// Get account ID from fixtures
    pub fn account_id(account_type: &str) -> &'static str {
        match account_type {
            "basic_account" => "TEST-ACC-001",
            "large_account" => "TEST-ACC-002",
            "eur_account" => "TEST-ACC-003",
            "crypto_account" => "TEST-ACC-004",
            "minimal_account" => "TEST-ACC-005",
            "icmarkets_demo" => "10000001",
            "interactive_brokers_paper" => "DU123456",
            _ => "TEST-ACC-001",
        }
    }

    /// Get order ID from fixtures
    pub fn order_id(order_type: &str) -> &'static str {
        match order_type {
            "basic_buy_order" => "ORDER-001",
            "basic_sell_order" => "ORDER-002",
            "large_order" => "ORDER-003",
            "crypto_order" => "ORDER-004",
            "forex_order" => "ORDER-005",
            "stop_loss_order" => "ORDER-006",
            "take_profit_order" => "ORDER-007",
            "fractional_order" => "ORDER-008",
            _ => "ORDER-001",
        }
    }

    /// Calculate commission from fixtures
    pub fn commission(order_value: Decimal) -> Decimal {
        // Standard 0.1% commission
        order_value * Self::safe_decimal("0.001")
    }

    /// Get market data bid size from fixtures  
    pub fn bid_size(symbol: &str) -> Decimal {
        match symbol {
            "AAPL" => Self::safe_decimal("1000.0"),
            "GOOGL" => Self::safe_decimal("500.0"),
            "MSFT" => Self::safe_decimal("800.0"),
            "TSLA" => Self::safe_decimal("600.0"),
            "SPY" => Self::safe_decimal("10000.0"),
            "BTCUSD" => Self::safe_decimal("2.5"),
            "ETHUSD" => Self::safe_decimal("15.0"),
            "EURUSD" => Self::safe_decimal("1000000.0"),
            _ => Self::safe_decimal("1000.0"),
        }
    }

    /// Get market data ask size from fixtures
    pub fn ask_size(symbol: &str) -> Decimal {
        match symbol {
            "AAPL" => Self::safe_decimal("1500.0"),
            "GOOGL" => Self::safe_decimal("750.0"),
            "MSFT" => Self::safe_decimal("1200.0"),
            "TSLA" => Self::safe_decimal("900.0"),
            "SPY" => Self::safe_decimal("15000.0"),
            "BTCUSD" => Self::safe_decimal("3.2"),
            "ETHUSD" => Self::safe_decimal("20.0"),
            "EURUSD" => Self::safe_decimal("1500000.0"),
            _ => Self::safe_decimal("1500.0"),
        }
    }

    /// Get unrealized PnL from fixtures
    pub fn unrealized_pnl(position_type: &str) -> Decimal {
        match position_type {
            "basic_long_position" => Self::safe_decimal("500.00"),
            "basic_short_position" => Self::safe_decimal("250.00"),
            "large_position" => Self::safe_decimal("12500.00"),
            "crypto_position" => Self::safe_decimal("2500.00"),
            "forex_position" => Self::safe_decimal("500.00"),
            "fractional_position" => Self::safe_decimal("50.00"),
            _ => Self::safe_decimal("500.00"),
        }
    }

    /// Get realized PnL from fixtures
    pub fn realized_pnl(position_type: &str) -> Decimal {
        match position_type {
            "basic_long_position" => Self::safe_decimal("0.00"),
            "basic_short_position" => Self::safe_decimal("0.00"),
            "large_position" => Self::safe_decimal("2500.00"),
            "crypto_position" => Self::safe_decimal("1000.00"),
            "forex_position" => Self::safe_decimal("250.00"),
            "fractional_position" => Self::safe_decimal("100.00"),
            "zero_position" => Self::safe_decimal("1500.00"),
            _ => Self::safe_decimal("0.00"),
        }
    }
}

// Simple macro for easy fixture access
#[macro_export]
macro_rules! fixture {
    (account_balance, $account_type:expr) => {
        TestFixtures::account_balance($account_type)
    };
    (stock_price, $symbol:expr) => {
        TestFixtures::stock_price($symbol)
    };
    (order_quantity, $order_type:expr) => {
        TestFixtures::order_quantity($order_type)
    };
    (risk_limit, $limit_type:expr, $profile:expr) => {
        TestFixtures::risk_limit($limit_type, $profile)
    };
    (currency, $account_type:expr) => {
        TestFixtures::currency($account_type)
    };
    (symbol, $symbol_type:expr) => {
        TestFixtures::symbol($symbol_type)
    };
}

// REMOVED: All pub use statements eliminated per cleanup requirements
// Tests must import from canonical sources: tests::fixtures::test_data