use chrono::{DateTime, Utc};
use serde::{Serialize, Deserialize};
use crate::{MarketUpdate, Order, Fill};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum EventType {
    MarketData(MarketUpdate),
    OrderSubmitted(Order),
    OrderFilled(Fill),
    OrderCancelled(String), // order_id
    TimeUpdate(DateTime<Utc>),
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BacktestEvent {
    pub timestamp: DateTime<Utc>,
    pub event_type: EventType,
}

impl BacktestEvent {
    pub fn market_data(timestamp: DateTime<Utc>, data: MarketUpdate) -> Self {
        Self {
            timestamp,
            event_type: EventType::MarketData(data),
        }
    }
    
    pub fn order_submitted(timestamp: DateTime<Utc>, order: Order) -> Self {
        Self {
            timestamp,
            event_type: EventType::OrderSubmitted(order),
        }
    }
    
    pub fn order_filled(timestamp: DateTime<Utc>, fill: Fill) -> Self {
        Self {
            timestamp,
            event_type: EventType::OrderFilled(fill),
        }
    }
    
    pub fn order_cancelled(timestamp: DateTime<Utc>, order_id: String) -> Self {
        Self {
            timestamp,
            event_type: EventType::OrderCancelled(order_id),
        }
    }
    
    pub fn time_update(timestamp: DateTime<Utc>) -> Self {
        Self {
            timestamp,
            event_type: EventType::TimeUpdate(timestamp),
        }
    }
}