/**
 * Crypto.com OTC 2.0 API Integration
 *
 * This module provides a complete integration with the Crypto.com Exchange
 * OTC 2.0 REST and WebSocket APIs for institutional OTC trading.
 *
 * Features:
 * - REST API client for reference data and query operations
 * - WebSocket client for real-time RFQ (Request for Quote) operations
 * - Digital signature generation for API authentication
 * - Event-driven architecture for quote and deal updates
 * - Automatic reconnection and heartbeat handling
 *
 * Documentation: https://exchange-docs.crypto.com/exchange/v1/rest-ws/index_OTC2.html
 *
 * @example
 * ```typescript
 * import { createCryptoComOtcService } from '@/core/exchange/crypto-com-otc';
 *
 * const otcService = createCryptoComOtcService({
 *   apiKey: process.env.CRYPTO_COM_API_KEY!,
 *   apiSecret: process.env.CRYPTO_COM_API_SECRET!,
 *   environment: 'production', // or 'uat' for sandbox
 * });
 *
 * // Initialize (connects WebSocket and subscribes to channels)
 * await otcService.initialize();
 *
 * // Listen for new quotes
 * otcService.on('newQuote', (quote) => {
 *   console.log('Received quote:', quote.quote_id);
 *
 *   // Execute deal if price is acceptable
 *   if (parseFloat(quote.leg_list[0].ask!) < targetPrice) {
 *     otcService.executeDealFromQuote(quote, 'BUY', `deal-${Date.now()}`);
 *   }
 * });
 *
 * // Request a quote
 * await otcService.requestQuote({
 *   cl_quote_req_id: `quote-${Date.now()}`,
 *   firm_quote: false,
 *   settlement_arrangement: 'IMMEDIATE',
 *   duration: '10000',
 *   leg_list: [{
 *     instrument_name: 'BTC_USD',
 *     side: 'BUY',
 *     quantity: '1',
 *   }],
 * });
 * ```
 *
 * @module crypto-com-otc
 */

// Main service
export {
  CryptoComOtcService,
  createCryptoComOtcService,
  type CryptoComOtcServiceEvents,
} from './crypto-com-otc.service';

// REST client
export {
  CryptoComRestClient,
  createRestClient,
} from './clients/rest-client';

// WebSocket client
export {
  CryptoComWebSocketClient,
  createWebSocketClient,
  type CryptoComWebSocketClientEvents,
} from './clients/websocket-client';

// Authentication
export {
  generateSignature,
  signRequest,
  createSignedRequest,
  verifySignature,
  generateParamsString,
} from './auth/signature';

// Configuration
export {
  ENVIRONMENTS,
  REST_RATE_LIMITS,
  WEBSOCKET_RATE_LIMITS,
  QUOTE_DURATIONS,
  QUOTE_TTL_OPTIONS,
  SETTLEMENT_ARRANGEMENTS,
  API_METHODS,
  WS_CHANNELS,
  DEFAULT_CONFIG,
  VALIDATION,
  RESPONSE_CODES,
  getEnvironmentConfig,
  isValidClientId,
  type EnvironmentConfig,
} from './config';

// Types - API Request/Response
export type {
  CryptoComApiRequest,
  CryptoComApiResponse,
  CryptoComError,
} from './types';

// Types - Configuration
export type {
  CryptoComOtcConfig,
  CryptoComRestClientConfig,
  CryptoComWebSocketClientConfig,
} from './types';

// Types - Instruments
export type {
  OtcInstrument,
  GetOtcInstrumentsResult,
} from './types';

// Types - Quote Request
export type {
  SettlementArrangement,
  QuoteRequestDuration,
  QuoteTtl,
  TradeSide,
  QuoteRequestLeg,
  RequestQuoteParams,
  QuoteRequestStatus,
  QuoteRequest,
  QuoteRequestLegResult,
  QuoteRequestUpdate,
} from './types';

// Types - Quote
export type {
  QuoteStatus,
  QuoteLeg,
  Quote,
} from './types';

// Types - Deal
export type {
  DealType,
  DealStatus,
  DealLeg,
  RequestDealParams,
  Deal,
  RequestDealResult,
} from './types';

// Types - Query Parameters
export type {
  GetOpenQuoteRequestsParams,
  GetOpenQuoteRequestsResult,
  GetOpenQuotesParams,
  GetOpenQuotesResult,
  GetQuoteRequestHistoryParams,
  GetQuoteRequestHistoryResult,
  GetQuoteHistoryParams,
  GetQuoteHistoryResult,
  GetOpenDealsParams,
  GetOpenDealsResult,
  GetDealHistoryParams,
  GetDealHistoryResult,
} from './types';

// Types - Settle Later
export type {
  SettleLaterLimit,
  UnsettledAmounts,
} from './types';

// Types - WebSocket
export type {
  SubscriptionChannel,
  SubscriptionRequest,
  SubscriptionResponse,
  SubscriptionMessage,
} from './types';

// Types - Error Codes
export {
  QuoteRequestReasonCode,
  DealReasonCode,
  WebSocketTerminationCode,
} from './types';

// Types - Events
export type { CryptoComOtcEvents } from './types';

// Routes
export { default as cryptoComOtcRoutes } from './crypto-com-otc.routes';

// Services
export {
  OtcPriceProvider,
  OtcTradePersistenceService,
  otcTradePersistenceService,
  SettleLaterTrackingService,
} from './services';

// Adapters
export {
  CryptoComOtcMarketReportingAdapter,
  type CryptoPriceReport,
} from './adapters/market-reporting-adapter';

// Utils
export { RateLimiter, TokenBucketRateLimiter } from './utils/rate-limiter';
export { withRetry, getExponentialBackoffDelay } from './utils/retry';

// Default export - main service
export { default } from './crypto-com-otc.service';
