import { Module, forwardRef } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ExchangeModule, ExchangeOptions } from '@edr/api-common';

// import { CustomersModule } from '../customers/customers.module';
import { CompaniesModule } from '../companies/companies.module';
import { FilesModule } from '../files/files.module';
import { MinioModule } from '../minio/minio.module';
import { RuleEngineModule } from '../rule-engine/rule-engine.module';
import { FileUploadSettingsModule } from '../file-upload-settings/file-upload-settings.module';
import { SignaturesModule } from '../signatures/signatures.module';
import { BookingContractService } from './booking-contract.service';
import { BookingPaymentService } from './booking-payment.service';
import { BookingPricingService } from './booking-pricing.service';
import { BookingReferenceDataService } from './booking-reference-data.service';
import { BookingTransitionService } from './booking-transition.service';
import { BookingsController } from './bookings.controller';
import { PayController } from './pay.controller';
import { BookingsRepository } from './bookings.repository';
import { ConsolidationService } from './consolidation.service';
import { BookingsService } from './bookings.service';
import { BookingApprovalStep } from './entities/booking-approval-step.entity';
import { BookingCargoModifier } from './entities/booking-cargo-modifier.entity';
import { BookingDocumentReview } from './entities/booking-document-review.entity';
import { BookingContainer } from './entities/booking-container.entity';
import { BookingRateSnapshot } from './entities/booking-rate-snapshot.entity';
import { BookingContractSignature } from './entities/booking-contract-signature.entity';
import { BookingReviewNote } from './entities/booking-review-note.entity';
import { Booking } from './entities/booking.entity';
import { ContractPdfService } from '../../contracts/contract-pdf.service';
import { ContractPricingScheduleBuilder } from '../../contracts/contract-pricing-schedule.builder';
import { ContractRendererService } from '../../contracts/contract-renderer.service';
import { ContractTemplateResolver } from '../../contracts/contract-template.resolver';
import { ContractViewModelBuilder } from '../../contracts/contract-view-model.builder';
import { PaymentModule } from '../payment/payment.module';
import { TrainSchedulingModule } from '../train-scheduling/train-scheduling.module';

@Module({
  imports: [
    TypeOrmModule.forFeature([
      Booking,
      BookingContainer,
      BookingCargoModifier,
      BookingApprovalStep,
      BookingDocumentReview,
      BookingRateSnapshot,
      BookingReviewNote,
      BookingContractSignature,
    ]),
    PaymentModule,
    forwardRef(() => TrainSchedulingModule),
    FilesModule,
    MinioModule,
    CompaniesModule,
    // CustomersModule,
    RuleEngineModule,
    FileUploadSettingsModule,
    SignaturesModule,
    ExchangeModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService): ExchangeOptions =>
        config.get<ExchangeOptions>('app.cbeExchange') ?? {},
    }),
  ],
  controllers: [BookingsController, PayController],
  providers: [
    BookingsService,
    BookingsRepository,
    ConsolidationService,
    BookingReferenceDataService,
    BookingPricingService,
    BookingTransitionService,
    BookingContractService,
    BookingPaymentService,
    ContractTemplateResolver,
    ContractViewModelBuilder,
    ContractPricingScheduleBuilder,
    ContractRendererService,
    ContractPdfService,
  ],
  exports: [BookingsService, BookingsRepository, BookingPricingService],
})
export class BookingsModule {}
