import { getPaymentMode } from './paymentMode'

export type PaymentMethod = 'bank_transfer' | 'credit_card' | 'gopay' | 'cstore'

export class PaymentAdapter {
  static getPaymentComponent(method: PaymentMethod) {
    const mode = getPaymentMode()

    if (mode === 'SNAP') {
      return this.getSnapComponent(method)
    } else {
      return this.getCoreComponent(method)
    }
  }

  private static getCoreComponent(method: PaymentMethod) {
    switch (method) {
      case 'bank_transfer':
        return import('../core/BankTransferPanel')
      case 'credit_card':
        return import('../core/CardPanel')
      case 'gopay':
        return import('../core/GoPayPanel')
      case 'cstore':
        return import('../core/CStorePanel')
      default:
        throw new Error(`Unknown payment method: ${method}`)
    }
  }

  private static getSnapComponent(_method: PaymentMethod) {
    // For Snap, most methods are handled by hosted interface
    // But we still need to return the SnapPaymentTrigger for consistency
    return import('../snap/SnapPaymentTrigger')
  }

  static shouldUseHostedInterface(_method: PaymentMethod): boolean {
    const mode = getPaymentMode()
    return mode === 'SNAP'
  }

  static getAvailableMethods(): PaymentMethod[] {
    // Return methods available in current mode
    // This could be extended to filter based on environment config
    return ['bank_transfer', 'credit_card', 'gopay', 'cstore']
  }
}