import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule } from '@nestjs/config';
import { CsvBookingsController } from '../controllers/csv-bookings.controller';
import { CsvBookingActionsController } from '../controllers/csv-booking-actions.controller';
import { CsvBookingService } from '../services/csv-booking.service';
import { CsvBookingOrmEntity } from '../../infrastructure/persistence/typeorm/entities/csv-booking.orm-entity';
import { TypeOrmCsvBookingRepository } from '../../infrastructure/persistence/typeorm/repositories/csv-booking.repository';
import { TypeOrmShipmentCounterRepository } from '../../infrastructure/persistence/typeorm/repositories/shipment-counter.repository';
import { SHIPMENT_COUNTER_PORT } from '@domain/ports/out/shipment-counter.port';
import { ORGANIZATION_REPOSITORY } from '@domain/ports/out/organization.repository';
import { OrganizationOrmEntity } from '../../infrastructure/persistence/typeorm/entities/organization.orm-entity';
import { TypeOrmOrganizationRepository } from '../../infrastructure/persistence/typeorm/repositories/typeorm-organization.repository';
import { USER_REPOSITORY } from '@domain/ports/out/user.repository';
import { UserOrmEntity } from '../../infrastructure/persistence/typeorm/entities/user.orm-entity';
import { TypeOrmUserRepository } from '../../infrastructure/persistence/typeorm/repositories/typeorm-user.repository';
import { NotificationsModule } from '../notifications/notifications.module';
import { EmailModule } from '../../infrastructure/email/email.module';
import { StorageModule } from '../../infrastructure/storage/storage.module';
import { SubscriptionsModule } from '../subscriptions/subscriptions.module';
import { StripeModule } from '../../infrastructure/stripe/stripe.module';

/**
 * CSV Bookings Module
 *
 * Handles CSV-based booking workflow with carrier email confirmations
 */
@Module({
  imports: [
    TypeOrmModule.forFeature([CsvBookingOrmEntity, OrganizationOrmEntity, UserOrmEntity]),
    ConfigModule,
    NotificationsModule,
    EmailModule,
    StorageModule,
    SubscriptionsModule,
    StripeModule,
  ],
  controllers: [CsvBookingsController, CsvBookingActionsController],
  providers: [
    CsvBookingService,
    TypeOrmCsvBookingRepository,
    {
      provide: SHIPMENT_COUNTER_PORT,
      useClass: TypeOrmShipmentCounterRepository,
    },
    {
      provide: ORGANIZATION_REPOSITORY,
      useClass: TypeOrmOrganizationRepository,
    },
    {
      provide: USER_REPOSITORY,
      useClass: TypeOrmUserRepository,
    },
  ],
  exports: [CsvBookingService, TypeOrmCsvBookingRepository],
})
export class CsvBookingsModule {}
