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 { BillingModule } from '../billing/billing.module';
import { DocumentsModule } from '../billing/documents/documents.module';
import { FirstMileModule } from '../first-mile/first-mile.module';
import { LastMileModule } from '../last-mile/last-mile.module';
import { BookingContractService } from './booking-contract.service';
import { BookingInvoiceService } from './booking-invoice.service';
// import { BookingPaymentController } from './booking-payment.controller';
// import { BookingPaymentService } from './booking-payment.service';
import { BookingPricingService } from './booking-pricing.service';
import { BookingReferenceDataService } from './booking-reference-data.service';
import { BookingLifecycleNotifierService } from './booking-lifecycle-notifier.service';
import { BookingTransitionService } from './booking-transition.service';
import { NotificationsModule } from '../notifications/notifications.module';
import { NotificationInboxModule } from '../notification-inbox/notification-inbox.module';
import { BookingsController } from './bookings.controller';
// import { PayController } from './pay.controller';
import { BookingsRepository } from './bookings.repository';
import { ConsolidationService } from './consolidation.service';
import { ContainerValidationService } from './container-validation.service';
import { BookingsService } from './bookings.service';
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 { CustomerTruckAssignment } from './entities/customer-truck-assignment.entity';
import { CustomerTruckContainer } from './entities/customer-truck-container.entity';
import { CustomerTruckAssignmentsRepository } from './customer-truck-assignments.repository';
import { CustomerTruckService } from './customer-truck.service';
import { ContainerReceiptService } from './container-receipt.service';
import { ContractPdfService } from '../../contracts/contract-pdf.service';
import { ContractsModule } from '../contracts/contracts.module';
import { BookingContainerAllocation } from "./entities/booking-container-allocation.entity";
import { ContractPricingScheduleBuilder } from "../../contracts/contract-pricing-schedule.builder";
import { ContractRateScheduleBuilder } from "../../contracts/contract-rate-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 { TrainSchedulingModule } from "../train-scheduling/train-scheduling.module";
import { VehiclesModule } from "../vehicles/vehicles.module";

@Module({
  imports: [
    TypeOrmModule.forFeature([
      Booking,
      BookingContainer,
      BookingCargoModifier,
      BookingDocumentReview,
      BookingRateSnapshot,
      BookingReviewNote,
      BookingContractSignature,
      BookingContainerAllocation,
      CustomerTruckAssignment,
      CustomerTruckContainer,
    ]),
    BillingModule,
    DocumentsModule,
    NotificationsModule,
    NotificationInboxModule,
    forwardRef(() => FirstMileModule),
    forwardRef(() => LastMileModule),
    forwardRef(() => TrainSchedulingModule),
    forwardRef(() => ContractsModule),
    forwardRef(() => ContractsModule),
    FilesModule,
    MinioModule,
    VehiclesModule,
    CompaniesModule,
    // CustomersModule,
    RuleEngineModule,
    FileUploadSettingsModule,
    SignaturesModule,
    ExchangeModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService): ExchangeOptions =>
        config.get<ExchangeOptions>("app.cbeExchange") ?? {},
    }),
  ],
  controllers: [BookingsController],
  providers: [
    BookingsService,
    BookingsRepository,
    ConsolidationService,
    ContainerValidationService,
    BookingReferenceDataService,
    BookingPricingService,
    BookingLifecycleNotifierService,
    BookingTransitionService,
    BookingContractService,
    BookingInvoiceService,
    ContractTemplateResolver,
    ContractViewModelBuilder,
    ContractPricingScheduleBuilder,
    ContractRateScheduleBuilder,
    ContractRendererService,
    ContractPdfService,
    CustomerTruckAssignmentsRepository,
    CustomerTruckService,
    ContainerReceiptService,
  ],
  exports: [
    BookingsService,
    BookingsRepository,
    BookingPricingService,
    BookingInvoiceService,
    BookingLifecycleNotifierService,
    BookingTransitionService,
    ConsolidationService,
    CustomerTruckService,
    ContainerReceiptService,
  ],
})
export class BookingsModule { }
