import { BaseValidator } from '../base/base.validator.js';
import { InvoiceFormat } from '../../interfaces/common.js';
import { FormatDetector } from '../utils/format.detector.js';

// Import specific validators
// import { UBLValidator } from '../ubl/ubl.validator.js';
// import { XRechnungValidator } from '../ubl/xrechnung/xrechnung.validator.js';
import { FacturXValidator } from '../cii/facturx/facturx.validator.js';
import { ZUGFeRDValidator } from '../cii/zugferd/zugferd.validator.js';

/**
 * Factory to create the appropriate validator based on the XML format
 */
export class ValidatorFactory {
  /**
   * Creates a validator for the specified XML content
   * @param xml XML content to validate
   * @returns Appropriate validator instance
   */
  public static createValidator(xml: string): BaseValidator {
    const format = FormatDetector.detectFormat(xml);

    switch (format) {
      case InvoiceFormat.UBL:
        // return new UBLValidator(xml);
        throw new Error('UBL validator not yet implemented');

      case InvoiceFormat.XRECHNUNG:
        // return new XRechnungValidator(xml);
        throw new Error('XRechnung validator not yet implemented');

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

      case InvoiceFormat.ZUGFERD:
        // Use dedicated ZUGFeRD validator
        return new ZUGFeRDValidator(xml);

      case InvoiceFormat.FACTURX:
        return new FacturXValidator(xml);

      case InvoiceFormat.FATTURAPA:
        // return new FatturaPAValidator(xml);
        throw new Error('FatturaPA validator not yet implemented');

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