import { Module, forwardRef } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Session } from '@tria-plc/iamapi-common/entities/iam/user/session.entity';

import { BillingModule } from '../billing/billing.module';
import { BookingsModule } from '../bookings/bookings.module';
import { Container } from '../container-management/entities/container.entity';
import { LocomotivesModule } from '../locomotives/locomotives.module';
import { RuleEngineModule } from '../rule-engine/rule-engine.module';
import { FacilityHandlingService } from './facility-handling.service';
import { FacilityHandlingEvent } from './entities/facility-handling-event.entity';
import { Locomotive } from '../locomotives/entities/locomotive.entity';
import { Route } from '../routes/entities/route.entity';
import { TrainSetLocomotive } from '../train-sets/entities/train-set-locomotive.entity';
import { TrainSetWagon } from '../train-sets/entities/train-set-wagon.entity';
import { TrainSet } from '../train-sets/entities/train-set.entity';
import { TrainSetsModule } from '../train-sets/train-sets.module';
import { TrainSchedulesModule } from '../train-schedules/train-schedules.module';
import { WagonType } from '../wagon-types/entities/wagon-type.entity';
import { WagonTypesModule } from '../wagon-types/wagon-types.module';
import { Wagon } from '../wagons/entities/wagon.entity';
import { WarehousesModule } from '../warehouses/warehouses.module';
import { TrainCheckpointEvent } from './entities/train-checkpoint-event.entity';
import { ImportDjiboutiOperation } from './entities/import-djibouti-operation.entity';
import { TrainSchedulingGlobalRules } from './entities/train-scheduling-global-rules.entity';
import { TrainCheckpointEventsRepository } from './train-checkpoint-events.repository';
import { TrainSchedulingController } from './train-scheduling.controller';
import { TrainSchedulingService } from './train-scheduling.service';
import { BookingBatchService } from './booking-batch.service';
import { BookingNotifierService } from './booking-notifier.service';
import { BookingWindowGateway } from './booking-window.gateway';
import { BookingWindowService } from './booking-window.service';
import { IntercityService } from './intercity.service';
import { WsAuthService } from '../notification-inbox/ws-auth.service';
import { BookingJourneyService } from './booking-journey.service';
import { BookingSplitService } from './booking-split.service';
import { RemainderPlacementService } from './remainder-placement.service';
import { BookingBatchOffer } from './entities/booking-batch-offer.entity';
import { WagonMovement } from '../wagons/entities/wagon-movement.entity';
import { NotificationsModule } from '../notifications/notifications.module';
import { NotificationInboxModule } from '../notification-inbox/notification-inbox.module';
import { ContractsModule } from '../contracts/contracts.module';

@Module({
  imports: [
    TypeOrmModule.forFeature([
      FacilityHandlingEvent,
      Locomotive,
      WagonType,
      TrainSet,
      TrainSetWagon,
      TrainSetLocomotive,
      Route,
      Wagon,
      Container,
      TrainSchedulingGlobalRules,
      TrainCheckpointEvent,
      ImportDjiboutiOperation,
      BookingBatchOffer,
      WagonMovement,
      // WsAuthService (booking-window gateway handshake) verifies IAM sessions.
      Session,
    ]),
    forwardRef(() => BookingsModule),
    BillingModule,
    NotificationsModule,
    NotificationInboxModule,
    LocomotivesModule,
    WagonTypesModule,
    TrainSetsModule,
    TrainSchedulesModule,
    forwardRef(() => WarehousesModule),
    RuleEngineModule,
    forwardRef(() => ContractsModule),
  ],
  controllers: [TrainSchedulingController],
  providers: [
    TrainSchedulingService,
    TrainCheckpointEventsRepository,
    BookingBatchService,
    BookingNotifierService,
    BookingWindowGateway,
    WsAuthService,
    BookingWindowService,
    BookingSplitService,
    RemainderPlacementService,
    IntercityService,
    BookingJourneyService,
    FacilityHandlingService,
  ],
  exports: [
    TrainSchedulingService,
    BookingBatchService,
    BookingWindowService,
    BookingNotifierService,
  ],
})
export class TrainSchedulingModule {}
