/**
 * CFDI Module
 *
 * Módulo para gestión de Comprobantes Fiscales Digitales por Internet (CFDI)
 * Incluye timbrado, cancelación y complementos de pago
 */

import { Router } from 'express';
import { DataSource } from 'typeorm';
import { CfdiCertificate } from './entities/cfdi-certificate.entity.js';
import { CfdiInvoice } from './entities/cfdi-invoice.entity.js';
import { CfdiCancellation } from './entities/cfdi-cancellation.entity.js';
import { CfdiLog } from './entities/cfdi-log.entity.js';
import { CfdiPaymentComplement } from './entities/cfdi-payment-complement.entity.js';
import { CfdiPacConfiguration } from './entities/cfdi-pac-configuration.entity.js';
import { CfdiStampQueue } from './entities/cfdi-stamp-queue.entity.js';
import cfdiRoutes from './cfdi.routes.js';

export interface CfdiModuleOptions {
  dataSource: DataSource;
  basePath?: string;
}

export class CfdiModule {
  public router: Router;

  constructor(options: CfdiModuleOptions) {
    const { basePath = '/cfdi' } = options;

    this.router = Router();

    // Mount CFDI routes under the base path
    this.router.use(basePath, cfdiRoutes);
  }

  /**
   * Get all entities for this module (for TypeORM configuration)
   */
  static getEntities() {
    return [
      CfdiCertificate,
      CfdiInvoice,
      CfdiCancellation,
      CfdiLog,
      CfdiPaymentComplement,
      CfdiPacConfiguration,
      CfdiStampQueue,
    ];
  }
}

export default CfdiModule;

// Re-export all module components
export * from './entities/index.js';
export * from './dto/index.js';
export * from './enums/index.js';
export * from './interfaces/index.js';
export * from './services/index.js';
