import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';

// ─── Domain Entities ───
import { AmlAlert } from './domain/entities/aml-alert.entity';
import { OfacScreening } from './domain/entities/ofac-screening.entity';
import { TravelRuleRecord } from './domain/entities/travel-rule-record.entity';
import { SarReport } from './domain/entities/sar-report.entity';
import { Dispute } from './domain/entities/dispute.entity';
import { AuditLog } from './domain/entities/audit-log.entity';
import { InsuranceClaim } from './domain/entities/insurance-claim.entity';

// ─── Domain Repository Interfaces (Symbols) ───
import { AML_ALERT_REPOSITORY } from './domain/repositories/aml-alert.repository.interface';
import { OFAC_SCREENING_REPOSITORY } from './domain/repositories/ofac-screening.repository.interface';
import { SAR_REPORT_REPOSITORY } from './domain/repositories/sar-report.repository.interface';
import { TRAVEL_RULE_REPOSITORY } from './domain/repositories/travel-rule.repository.interface';
import { DISPUTE_REPOSITORY } from './domain/repositories/dispute.repository.interface';
import { INSURANCE_CLAIM_REPOSITORY } from './domain/repositories/insurance-claim.repository.interface';
import { AUDIT_LOG_REPOSITORY } from './domain/repositories/audit-log.repository.interface';

// ─── Infrastructure Persistence (Concrete Implementations) ───
import { AmlAlertRepository } from './infrastructure/persistence/aml-alert.repository';
import { OfacScreeningRepository } from './infrastructure/persistence/ofac-screening.repository';
import { SarReportRepository } from './infrastructure/persistence/sar-report.repository';
import { TravelRuleRepository } from './infrastructure/persistence/travel-rule.repository';
import { DisputeRepository } from './infrastructure/persistence/dispute.repository';
import { InsuranceClaimRepository } from './infrastructure/persistence/insurance-claim.repository';
import { AuditLogRepository } from './infrastructure/persistence/audit-log.repository';

// ─── Domain Ports ───
import { AUDIT_LOGGER_SERVICE } from './domain/ports/audit-logger.interface';

// ─── Infrastructure Services ───
import { AuditLoggerService } from './infrastructure/services/audit-logger.service';

// ─── Application Services ───
import { AmlService } from './application/services/aml.service';
import { OfacService } from './application/services/ofac.service';
import { TravelRuleService } from './application/services/travel-rule.service';
import { SarService } from './application/services/sar.service';
import { AdminRiskService } from './application/services/admin-risk.service';
import { AdminComplianceService } from './application/services/admin-compliance.service';
import { AdminDisputeService } from './application/services/admin-dispute.service';
import { AdminInsuranceService } from './application/services/admin-insurance.service';

// ─── Interface Controllers ───
import { ComplianceController } from './interface/http/controllers/compliance.controller';
import { AdminRiskController } from './interface/http/controllers/admin-risk.controller';
import { AdminComplianceController } from './interface/http/controllers/admin-compliance.controller';
import { AdminDisputeController } from './interface/http/controllers/admin-dispute.controller';
import { AdminInsuranceController } from './interface/http/controllers/admin-insurance.controller';

@Module({
  imports: [
    TypeOrmModule.forFeature([
      AmlAlert,
      OfacScreening,
      TravelRuleRecord,
      SarReport,
      Dispute,
      AuditLog,
      InsuranceClaim,
    ]),
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.register({ secret: process.env.JWT_ACCESS_SECRET || 'dev-access-secret' }),
  ],
  controllers: [
    ComplianceController,
    AdminRiskController,
    AdminComplianceController,
    AdminDisputeController,
    AdminInsuranceController,
  ],
  providers: [
    // ─── Repository DI bindings (interface → implementation) ───
    { provide: AML_ALERT_REPOSITORY, useClass: AmlAlertRepository },
    { provide: OFAC_SCREENING_REPOSITORY, useClass: OfacScreeningRepository },
    { provide: SAR_REPORT_REPOSITORY, useClass: SarReportRepository },
    { provide: TRAVEL_RULE_REPOSITORY, useClass: TravelRuleRepository },
    { provide: DISPUTE_REPOSITORY, useClass: DisputeRepository },
    { provide: INSURANCE_CLAIM_REPOSITORY, useClass: InsuranceClaimRepository },
    { provide: AUDIT_LOG_REPOSITORY, useClass: AuditLogRepository },

    // ─── Infrastructure services ───
    { provide: AUDIT_LOGGER_SERVICE, useClass: AuditLoggerService },

    // ─── Application services ───
    AmlService,
    OfacService,
    TravelRuleService,
    SarService,
    AdminRiskService,
    AdminComplianceService,
    AdminDisputeService,
    AdminInsuranceService,
  ],
  exports: [
    // Export application services for potential use by other modules
    AmlService,
    OfacService,
    TravelRuleService,
    SarService,
    AdminRiskService,
    AdminComplianceService,
    AdminDisputeService,
    AdminInsuranceService,

    // Export infrastructure service symbols for DI in other modules
    AUDIT_LOGGER_SERVICE,
  ],
})
export class ComplianceModule {}
