/**
 * Crypto.com OTC Market Reporting Adapter
 * Provides OTC prices for market reporting services
 * Can be imported by smom-dbis-138/services/market-reporting
 */

import { CryptoComOtcService } from '../crypto-com-otc.service';

export interface OtcMarketReportingConfig {
  otcService: CryptoComOtcService;
}

/**
 * Adapter that provides Crypto.com OTC prices for market reporting
 */
export class CryptoComOtcMarketReportingAdapter {
  private otcService: CryptoComOtcService;

  constructor(config: OtcMarketReportingConfig) {
    this.otcService = config.otcService;
  }

  /**
   * Get crypto price reports from OTC cached quotes
   */
  async getCryptoPriceReports(): Promise<CryptoPriceReport[]> {
    const reports: CryptoPriceReport[] = [];
    const priceProvider = this.otcService.getPriceProvider();
    const stats = priceProvider.getCacheStats();

    for (const pair of stats.pairs) {
      const price = priceProvider.getPrice(pair);
      if (price) {
        const [base] = pair.split('/');
        reports.push({
          symbol: base,
          price: parseFloat(price),
          volume24h: 0,
          timestamp: Date.now(),
          source: 'crypto_com_otc',
        });
      }
    }

    return reports;
  }

  /**
   * Get OTC instruments for market data
   */
  getInstruments() {
    return this.otcService.getInstruments();
  }
}

export interface CryptoPriceReport {
  symbol: string;
  price: number;
  volume24h: number;
  timestamp: number;
  source?: string;
}
