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

import { BillingModule } from '../billing/billing.module';
import { DocumentsModule } from '../billing/documents/documents.module';
import { FilesModule } from '../files/files.module';
import { InterchangeDocumentsModule } from '../interchange-documents/interchange-documents.module';
import { LastMileModule } from '../last-mile/last-mile.module';
import { NotificationsModule } from '../notifications/notifications.module';
import { NotificationInboxModule } from '../notification-inbox/notification-inbox.module';
import { SignaturesModule } from '../signatures/signatures.module';
import { WarehouseActivityLog } from './entities/warehouse-activity-log.entity';
import { WarehouseAllocationRule } from './entities/warehouse-allocation-rule.entity';
import { WarehouseFeeRule } from './entities/warehouse-fee-rule.entity';
import { WarehouseInspectionReport } from './entities/warehouse-inspection-report.entity';
import { WarehouseInventory } from './entities/warehouse-inventory.entity';
import { BookingHandover } from './entities/booking-handover.entity';
import { HandoverService } from './handover.service';
import { WarehouseInventoryMovement } from './entities/warehouse-inventory-movement.entity';
import { WarehouseLoading } from './entities/warehouse-loading.entity';
import { WarehouseYard } from './entities/warehouse-yard.entity';
import { WarehouseZone } from './entities/warehouse-zone.entity';
import { Warehouse } from './entities/warehouse.entity';
import { SchedulingReadFacade } from './scheduling-read.facade';
import { WarehouseActivityLogRepository } from './warehouse-activity-log.repository';
import { WarehouseActivityLogService } from './warehouse-activity-log.service';
import { WarehouseDashboardService } from './warehouse-dashboard.service';
import { WarehouseInspectionController } from './warehouse-inspection.controller';
import { WarehouseInspectionRepository } from './warehouse-inspection.repository';
import { WarehouseInspectionService } from './warehouse-inspection.service';
import { WarehouseInventoryController } from './warehouse-inventory.controller';
import { WarehouseInventoryMovementRepository } from './warehouse-inventory-movement.repository';
import { WarehouseInventoryRepository } from './warehouse-inventory.repository';
import { WarehouseInventoryService } from './warehouse-inventory.service';
import { WarehouseLoadingRepository } from './warehouse-loading.repository';
import { WarehouseLoadingsController } from './warehouse-loadings.controller';
import { WarehouseReleaseDocumentService } from './warehouse-release-document.service';
import { WarehouseAllocationRuleRepository } from './warehouse-allocation-rule.repository';
import { WarehouseAllocationService } from './warehouse-allocation.service';
import { WarehouseFeeRuleRepository } from './warehouse-fee-rule.repository';
import { WarehouseFeeService } from './warehouse-fee.service';
import { WarehouseInvoiceController } from './warehouse-invoice.controller';
import { WarehouseInvoiceService } from './warehouse-invoice.service';
import { WarehouseRulesController } from './warehouse-rules.controller';
import { WarehouseSchedulingAdapterService } from './warehouse-scheduling-adapter.service';
import { WarehouseYardsController } from './warehouse-yards.controller';
import { WarehouseYardsRepository } from './warehouse-yards.repository';
import { WarehouseYardsService } from './warehouse-yards.service';
import { WarehouseZonesController } from './warehouse-zones.controller';
import { WarehouseZonesRepository } from './warehouse-zones.repository';
import { WarehouseZonesService } from './warehouse-zones.service';
import { WarehousesController } from './warehouses.controller';
import { WarehousesRepository } from './warehouses.repository';
import { WarehousesService } from './warehouses.service';

@Module({
  imports: [
    TypeOrmModule.forFeature([
      Warehouse,
      WarehouseYard,
      WarehouseZone,
      WarehouseInventory,
      WarehouseInventoryMovement,
      WarehouseActivityLog,
      WarehouseLoading,
      WarehouseInspectionReport,
      WarehouseAllocationRule,
      WarehouseFeeRule,
      BookingHandover,
    ]),
    BillingModule,
    DocumentsModule,
    FilesModule,
    InterchangeDocumentsModule,
    forwardRef(() => LastMileModule),
    NotificationsModule,
    NotificationInboxModule,
    SignaturesModule,
    ExchangeModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService): ExchangeOptions =>
        config.get<ExchangeOptions>('app.cbeExchange') ?? {},
    }),
  ],
  controllers: [
    WarehousesController,
    WarehouseYardsController,
    WarehouseZonesController,
    WarehouseInventoryController,
    WarehouseLoadingsController,
    WarehouseInspectionController,
    WarehouseRulesController,
    WarehouseInvoiceController,
  ],
  providers: [
    WarehousesRepository,
    WarehouseYardsRepository,
    WarehouseZonesRepository,
    WarehouseInventoryRepository,
    WarehouseInventoryMovementRepository,
    WarehouseActivityLogRepository,
    WarehouseLoadingRepository,
    WarehouseInspectionRepository,
    WarehouseAllocationRuleRepository,
    WarehouseFeeRuleRepository,
    WarehousesService,
    WarehouseYardsService,
    WarehouseZonesService,
    WarehouseInventoryService,
    WarehouseActivityLogService,
    WarehouseDashboardService,
    WarehouseInspectionService,
    WarehouseAllocationService,
    WarehouseFeeService,
    WarehouseInvoiceService,
    WarehouseSchedulingAdapterService,
    WarehouseReleaseDocumentService,
    SchedulingReadFacade,
    HandoverService,
  ],
  exports: [
    WarehousesService,
    WarehouseYardsService,
    WarehouseZonesService,
    WarehouseInventoryService,
    WarehouseAllocationService,
    WarehouseFeeService,
    WarehouseSchedulingAdapterService,
    WarehouseReleaseDocumentService,
  ],
})
export class WarehousesModule {}
