import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { BookingsController } from '../controllers/bookings.controller';

// Import domain ports
import { BOOKING_REPOSITORY } from '@domain/ports/out/booking.repository';
import { RATE_QUOTE_REPOSITORY } from '@domain/ports/out/rate-quote.repository';
import { USER_REPOSITORY } from '@domain/ports/out/user.repository';
import { SHIPMENT_COUNTER_PORT } from '@domain/ports/out/shipment-counter.port';
import { TypeOrmBookingRepository } from '../../infrastructure/persistence/typeorm/repositories/typeorm-booking.repository';
import { TypeOrmRateQuoteRepository } from '../../infrastructure/persistence/typeorm/repositories/typeorm-rate-quote.repository';
import { TypeOrmUserRepository } from '../../infrastructure/persistence/typeorm/repositories/typeorm-user.repository';
import { TypeOrmShipmentCounterRepository } from '../../infrastructure/persistence/typeorm/repositories/shipment-counter.repository';

// Import ORM entities
import { BookingOrmEntity } from '../../infrastructure/persistence/typeorm/entities/booking.orm-entity';
import { ContainerOrmEntity } from '../../infrastructure/persistence/typeorm/entities/container.orm-entity';
import { RateQuoteOrmEntity } from '../../infrastructure/persistence/typeorm/entities/rate-quote.orm-entity';
import { UserOrmEntity } from '../../infrastructure/persistence/typeorm/entities/user.orm-entity';
import { CsvBookingOrmEntity } from '../../infrastructure/persistence/typeorm/entities/csv-booking.orm-entity';

// Import services and domain
import { BookingService } from '@domain/services/booking.service';
import { BookingAutomationService } from '../services/booking-automation.service';
import { ExportService } from '../services/export.service';
import { FuzzySearchService } from '../services/fuzzy-search.service';

// Import infrastructure modules
import { EmailModule } from '../../infrastructure/email/email.module';
import { PdfModule } from '../../infrastructure/pdf/pdf.module';
import { StorageModule } from '../../infrastructure/storage/storage.module';
import { AuditModule } from '../audit/audit.module';
import { NotificationsModule } from '../notifications/notifications.module';
import { WebhooksModule } from '../webhooks/webhooks.module';
import { SubscriptionsModule } from '../subscriptions/subscriptions.module';

/**
 * Bookings Module
 *
 * Handles booking management functionality:
 * - Create bookings from rate quotes
 * - View booking details
 * - List user/organization bookings
 * - Update booking status
 * - Post-booking automation (emails, PDFs)
 */
@Module({
  imports: [
    TypeOrmModule.forFeature([
      BookingOrmEntity,
      ContainerOrmEntity,
      RateQuoteOrmEntity,
      UserOrmEntity,
      CsvBookingOrmEntity,
    ]),
    EmailModule,
    PdfModule,
    StorageModule,
    AuditModule,
    NotificationsModule,
    WebhooksModule,
    SubscriptionsModule,
  ],
  controllers: [BookingsController],
  providers: [
    BookingService,
    BookingAutomationService,
    ExportService,
    FuzzySearchService,
    {
      provide: BOOKING_REPOSITORY,
      useClass: TypeOrmBookingRepository,
    },
    {
      provide: RATE_QUOTE_REPOSITORY,
      useClass: TypeOrmRateQuoteRepository,
    },
    {
      provide: USER_REPOSITORY,
      useClass: TypeOrmUserRepository,
    },
    {
      provide: SHIPMENT_COUNTER_PORT,
      useClass: TypeOrmShipmentCounterRepository,
    },
  ],
  exports: [BOOKING_REPOSITORY],
})
export class BookingsModule {}
