use engine::{Order, OrderType, Side, TimeInForce, Quote, Bar, Trade, MarketDataType};
use chrono::Utc;

#[test]
fn test_order_creation() {
    let order = Order {
        id: "test-order-1".to_string(),
        symbol: "AAPL".to_string(),
        side: Side::Buy,
        quantity: 100.0,
        order_type: OrderType::Market,
        time_in_force: TimeInForce::Day,
    };

    assert_eq!(order.id, "test-order-1");
    assert_eq!(order.symbol, "AAPL");
    assert_eq!(order.side, Side::Buy);
    assert_eq!(order.quantity, 100.0);
}

#[test]
fn test_order_types() {
    let market = OrderType::Market;
    let limit = OrderType::Limit { price: 150.0 };
    let stop = OrderType::Stop { stop_price: 145.0 };
    let stop_limit = OrderType::StopLimit {
        stop_price: 145.0,
        limit_price: 144.5,
    };

    match limit {
        OrderType::Limit { price } => assert_eq!(price, 150.0),
        _ => panic!("Expected limit order"),
    }

    match stop {
        OrderType::Stop { stop_price } => assert_eq!(stop_price, 145.0),
        _ => panic!("Expected stop order"),
    }

    match stop_limit {
        OrderType::StopLimit { stop_price, limit_price } => {
            assert_eq!(stop_price, 145.0);
            assert_eq!(limit_price, 144.5);
        }
        _ => panic!("Expected stop limit order"),
    }

    assert!(matches!(market, OrderType::Market));
}

#[test]
fn test_quote_creation() {
    let quote = Quote {
        bid: 149.95,
        ask: 150.05,
        bid_size: 1000.0,
        ask_size: 800.0,
    };

    assert_eq!(quote.bid, 149.95);
    assert_eq!(quote.ask, 150.05);
    assert_eq!(quote.bid_size, 1000.0);
    assert_eq!(quote.ask_size, 800.0);
}

#[test]
fn test_bar_creation() {
    let bar = Bar {
        open: 150.0,
        high: 152.0,
        low: 149.0,
        close: 151.0,
        volume: 1_000_000.0,
        vwap: Some(150.5),
    };

    assert_eq!(bar.open, 150.0);
    assert_eq!(bar.high, 152.0);
    assert_eq!(bar.low, 149.0);
    assert_eq!(bar.close, 151.0);
    assert_eq!(bar.volume, 1_000_000.0);
    assert_eq!(bar.vwap, Some(150.5));
}

#[test]
fn test_trade_creation() {
    let trade = Trade {
        price: 150.0,
        size: 500.0,
        side: Side::Buy,
    };

    assert_eq!(trade.price, 150.0);
    assert_eq!(trade.size, 500.0);
    assert_eq!(trade.side, Side::Buy);
}

#[test]
fn test_market_data_type() {
    let quote = Quote {
        bid: 149.95,
        ask: 150.05,
        bid_size: 100.0,
        ask_size: 100.0,
    };
    
    let quote_data = MarketDataType::Quote(quote.clone());
    
    match quote_data {
        MarketDataType::Quote(q) => {
            assert_eq!(q.bid, quote.bid);
            assert_eq!(q.ask, quote.ask);
        }
        _ => panic!("Expected quote data"),
    }
    
    let bar = Bar {
        open: 150.0,
        high: 152.0,
        low: 149.0,
        close: 151.0,
        volume: 10000.0,
        vwap: None,
    };
    
    let bar_data = MarketDataType::Bar(bar.clone());
    
    match bar_data {
        MarketDataType::Bar(b) => {
            assert_eq!(b.open, bar.open);
            assert_eq!(b.close, bar.close);
        }
        _ => panic!("Expected bar data"),
    }
}

#[test]
fn test_side_equality() {
    assert_eq!(Side::Buy, Side::Buy);
    assert_eq!(Side::Sell, Side::Sell);
    assert_ne!(Side::Buy, Side::Sell);
}