pub mod time_providers;
pub mod market_data_sources;
pub mod execution_handlers;
pub mod market_microstructure;
pub mod mock_data_generator;

use crate::{MarketDataSource, ExecutionHandler, TimeProvider, TradingMode};

// Factory functions to create appropriate implementations based on mode
pub fn create_market_data_source(mode: &TradingMode) -> Box<dyn MarketDataSource> {
    match mode {
        TradingMode::Backtest { .. } => {
            Box::new(market_data_sources::HistoricalDataSource::new())
        }
        TradingMode::Paper { .. } | TradingMode::Live { .. } => {
            Box::new(market_data_sources::LiveDataSource::new())
        }
    }
}

pub fn create_execution_handler(mode: &TradingMode) -> Box<dyn ExecutionHandler> {
    match mode {
        TradingMode::Backtest { .. } => {
            Box::new(execution_handlers::SimulatedExecution::new(
                Box::new(execution_handlers::BacktestFillSimulator::new())
            ))
        }
        TradingMode::Paper { .. } => {
            Box::new(execution_handlers::SimulatedExecution::new(
                Box::new(execution_handlers::PaperFillSimulator::new())
            ))
        }
        TradingMode::Live { broker, account_id } => {
            Box::new(execution_handlers::BrokerExecution::new(
                broker.clone(),
                account_id.clone()
            ))
        }
    }
}

pub fn create_time_provider(mode: &TradingMode) -> Box<dyn TimeProvider> {
    match mode {
        TradingMode::Backtest { start_time, .. } => {
            Box::new(time_providers::SimulatedTime::new(*start_time))
        }
        TradingMode::Paper { .. } | TradingMode::Live { .. } => {
            Box::new(time_providers::SystemTime::new())
        }
    }
}