use napi_derive::napi;
use napi::bindgen_prelude::*;
use std::sync::Arc;

#[napi]
pub struct MarketDataAPI {
    core: Arc<crate::TradingCore>,
}

impl MarketDataAPI {
    pub fn new(core: Arc<crate::TradingCore>) -> Self {
        Self { core }
    }
}

#[napi]
impl MarketDataAPI {
    #[napi]
    pub async fn subscribe(&self, symbols: Vec<String>) -> Result<()> {
        // Subscribe to market data for symbols
        self.core.subscribe_market_data(symbols)
            .await
            .map_err(|e| Error::from_reason(e))
    }
    
    #[napi]
    pub async fn unsubscribe(&self, symbols: Vec<String>) -> Result<()> {
        // Unsubscribe from market data
        self.core.unsubscribe_market_data(symbols)
            .await
            .map_err(|e| Error::from_reason(e))
    }
    
    #[napi]
    pub fn get_latest_quote(&self, symbol: String) -> Result<JsObject> {
        // Get latest quote for symbol
        let quote = self.core.orderbook_manager
            .get_best_bid_ask(&symbol)
            .ok_or_else(|| Error::from_reason("No quote available"))?;
            
        // Convert to JS object
        // Note: In real implementation, would properly convert Quote to JsObject
        todo!("Convert quote to JsObject")
    }
    
    #[napi]
    pub fn get_latest_bar(&self, symbol: String) -> Result<JsObject> {
        // Get latest bar for symbol
        todo!("Get latest bar implementation")
    }
}