/**
 * Factory Function
 *
 * Creates a typed currency service with exchange inference
 */

import type { CurrencyConfig, CurrencyExchanges } from './types/index.js'
import { CurrencyService } from './services/index.js'
import type { BaseCurrencyExchange } from './exchanges/base_exchange.js'

/**
 * Create a typed currency service with exchange inference
 *
 * @example
 * ```typescript
 * const config = defineConfig({
 *   default: 'google' as const,
 *   exchanges: {
 *     google: exchanges.google({ base: 'USD' }),
 *     fixer: exchanges.fixer({ accessKey: 'your-key' })
 *   }
 * })
 *
 * const currency = createCurrency(config)
 *
 * // TypeScript knows these are valid
 * currency.use('google')  // ✅
 * currency.use('fixer')   // ✅
 * // currency.use('invalid') // ❌ TypeScript error
 * ```
 */
export function createCurrency<KnownExchanges extends Record<keyof CurrencyExchanges, BaseCurrencyExchange>>(
  config: CurrencyConfig<KnownExchanges>
): CurrencyService<KnownExchanges> {
  return new CurrencyService<KnownExchanges>(config)
}
