51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { BaseDecoder } from '../base/base.decoder.js';
|
|
import { InvoiceFormat } from '../../interfaces/common.js';
|
|
import { FormatDetector } from '../utils/format.detector.js';
|
|
|
|
// Import specific decoders
|
|
// import { XRechnungDecoder } from '../ubl/xrechnung/xrechnung.decoder.js';
|
|
import { FacturXDecoder } from '../cii/facturx/facturx.decoder.js';
|
|
// import { ZUGFeRDDecoder } from '../cii/zugferd/zugferd.decoder.js';
|
|
|
|
/**
|
|
* Factory to create the appropriate decoder based on the XML format
|
|
*/
|
|
export class DecoderFactory {
|
|
/**
|
|
* Creates a decoder for the specified XML content
|
|
* @param xml XML content to decode
|
|
* @returns Appropriate decoder instance
|
|
*/
|
|
public static createDecoder(xml: string): BaseDecoder {
|
|
const format = FormatDetector.detectFormat(xml);
|
|
|
|
switch (format) {
|
|
case InvoiceFormat.UBL:
|
|
// return new UBLDecoder(xml);
|
|
throw new Error('UBL decoder not yet implemented');
|
|
|
|
case InvoiceFormat.XRECHNUNG:
|
|
// return new XRechnungDecoder(xml);
|
|
throw new Error('XRechnung decoder not yet implemented');
|
|
|
|
case InvoiceFormat.CII:
|
|
// For now, use Factur-X decoder for generic CII
|
|
return new FacturXDecoder(xml);
|
|
|
|
case InvoiceFormat.ZUGFERD:
|
|
// For now, use Factur-X decoder for ZUGFeRD
|
|
return new FacturXDecoder(xml);
|
|
|
|
case InvoiceFormat.FACTURX:
|
|
return new FacturXDecoder(xml);
|
|
|
|
case InvoiceFormat.FATTURAPA:
|
|
// return new FatturaPADecoder(xml);
|
|
throw new Error('FatturaPA decoder not yet implemented');
|
|
|
|
default:
|
|
throw new Error(`Unsupported invoice format: ${format}`);
|
|
}
|
|
}
|
|
}
|