import { BaseEncoder } from '../base/base.encoder.js';
import { InvoiceFormat } from '../../interfaces/common.js';
import type { ExportFormat } from '../../interfaces/common.js';

// Import specific encoders
import { XRechnungEncoder } from '../ubl/xrechnung/xrechnung.encoder.js';
import { FacturXEncoder } from '../cii/facturx/facturx.encoder.js';
// import { ZUGFeRDEncoder } from '../cii/zugferd/zugferd.encoder.js';

/**
 * Factory to create the appropriate encoder based on the target format
 */
export class EncoderFactory {
  /**
   * Creates an encoder for the specified format
   * @param format Target format for encoding
   * @returns Appropriate encoder instance
   */
  public static createEncoder(format: ExportFormat | InvoiceFormat): BaseEncoder {
    switch (format.toLowerCase()) {
      case InvoiceFormat.UBL:
      case 'ubl':
        // return new UBLEncoder();
        throw new Error('UBL encoder not yet implemented');

      case InvoiceFormat.XRECHNUNG:
      case 'xrechnung':
        return new XRechnungEncoder();

      case InvoiceFormat.CII:
        // For now, use Factur-X encoder for generic CII
        return new FacturXEncoder();

      case InvoiceFormat.ZUGFERD:
      case 'zugferd':
        // For now, use Factur-X encoder for ZUGFeRD
        return new FacturXEncoder();

      case InvoiceFormat.FACTURX:
      case 'facturx':
        return new FacturXEncoder();

      default:
        throw new Error(`Unsupported invoice format for encoding: ${format}`);
    }
  }
}
