import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';
import { JwtStrategy } from './infrastructure/strategies/jwt.strategy';

// Domain entities
import { Settlement } from './domain/entities/settlement.entity';
import { Refund } from './domain/entities/refund.entity';
import { BreakageRecord } from './domain/entities/breakage-record.entity';
import { JournalEntry } from './domain/entities/journal-entry.entity';
import { Report } from './domain/entities/report.entity';

// Domain repository interfaces (symbols)
import { SETTLEMENT_REPOSITORY } from './domain/repositories/settlement.repository.interface';
import { REFUND_REPOSITORY } from './domain/repositories/refund.repository.interface';
import { BREAKAGE_REPOSITORY } from './domain/repositories/breakage.repository.interface';
import { JOURNAL_ENTRY_REPOSITORY } from './domain/repositories/journal-entry.repository.interface';
import { REPORT_REPOSITORY } from './domain/repositories/report.repository.interface';

// Infrastructure persistence implementations
import { SettlementRepository } from './infrastructure/persistence/settlement.repository';
import { RefundRepository } from './infrastructure/persistence/refund.repository';
import { BreakageRepository } from './infrastructure/persistence/breakage.repository';
import { JournalEntryRepository } from './infrastructure/persistence/journal-entry.repository';
import { ReportRepository } from './infrastructure/persistence/report.repository';

// Application services
import { SettlementService } from './application/services/settlement.service';
import { RefundService } from './application/services/refund.service';
import { BreakageService } from './application/services/breakage.service';
import { AdminFinanceService } from './application/services/admin-finance.service';
import { AdminReportsService } from './application/services/admin-reports.service';

// Interface controllers
import { ClearingController } from './interface/http/controllers/clearing.controller';
import { AdminFinanceController } from './interface/http/controllers/admin-finance.controller';
import { AdminReportsController } from './interface/http/controllers/admin-reports.controller';

@Module({
  imports: [
    TypeOrmModule.forFeature([Settlement, Refund, BreakageRecord, JournalEntry, Report]),
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.register({ secret: process.env.JWT_ACCESS_SECRET || 'dev-access-secret' }),
  ],
  controllers: [ClearingController, AdminFinanceController, AdminReportsController],
  providers: [
    JwtStrategy,
    // Repository DI bindings (interface -> implementation)
    { provide: SETTLEMENT_REPOSITORY, useClass: SettlementRepository },
    { provide: REFUND_REPOSITORY, useClass: RefundRepository },
    { provide: BREAKAGE_REPOSITORY, useClass: BreakageRepository },
    { provide: JOURNAL_ENTRY_REPOSITORY, useClass: JournalEntryRepository },
    { provide: REPORT_REPOSITORY, useClass: ReportRepository },

    // Application services
    SettlementService,
    RefundService,
    BreakageService,
    AdminFinanceService,
    AdminReportsService,
  ],
  exports: [SettlementService, RefundService, BreakageService],
})
export class ClearingModule {}
