import { Global, Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';

import { ApprovalRulesController } from './controllers/approval-rules.controller';
import { CargoTypesController } from './controllers/cargo-types.controller';
import { ContainerTypesController } from './controllers/container-types.controller';
import { PriorityConfigsController } from './controllers/priority-configs.controller';
import { RatesController } from './controllers/rates.controller';
import { ServiceTypesController } from './controllers/service-types.controller';
import { ShippingLinesController } from './controllers/shipping-lines.controller';
import { WeightLimitRulesController } from './controllers/weight-limit-rules.controller';
import { YardsController } from './controllers/yards.controller';

import { ApprovalRule } from './entities/approval-rule.entity';
import { CargoType } from './entities/cargo-type.entity';
import { ContainerType } from './entities/container-type.entity';
import { PriorityConfig } from './entities/priority-config.entity';
import { Rate } from './entities/rate.entity';
import { ServiceType } from './entities/service-type.entity';
import { ShippingLine } from './entities/shipping-line.entity';
import { WeightLimitRule } from './entities/weight-limit-rule.entity';
import { Yard } from './entities/yard.entity';

import { APPROVAL_RULES_REPOSITORY } from './interfaces/approval-rules.repository.interface';
import { CARGO_TYPES_REPOSITORY } from './interfaces/cargo-types.repository.interface';
import { CONTAINER_TYPES_REPOSITORY } from './interfaces/container-types.repository.interface';
import { PRIORITY_CONFIGS_REPOSITORY } from './interfaces/priority-configs.repository.interface';
import { RATES_REPOSITORY } from './interfaces/rates.repository.interface';
import { SERVICE_TYPES_REPOSITORY } from './interfaces/service-types.repository.interface';
import { SHIPPING_LINES_REPOSITORY } from './interfaces/shipping-lines.repository.interface';
import { WEIGHT_LIMIT_RULES_REPOSITORY } from './interfaces/weight-limit-rules.repository.interface';
import { YARDS_REPOSITORY } from './interfaces/yards.repository.interface';

import { ApprovalRulesRepository } from './repositories/approval-rules.repository';
import { CargoTypesRepository } from './repositories/cargo-types.repository';
import { ContainerTypesRepository } from './repositories/container-types.repository';
import { PriorityConfigsRepository } from './repositories/priority-configs.repository';
import { RatesRepository } from './repositories/rates.repository';
import { ServiceTypesRepository } from './repositories/service-types.repository';
import { ShippingLinesRepository } from './repositories/shipping-lines.repository';
import { WeightLimitRulesRepository } from './repositories/weight-limit-rules.repository';
import { YardsRepository } from './repositories/yards.repository';

import { ApprovalRulesService } from './services/approval-rules.service';
import { DisplayOrderService } from './services/display-order.service';
import { CargoTypesService } from './services/cargo-types.service';
import { ContainerTypesService } from './services/container-types.service';
import { PriorityConfigsService } from './services/priority-configs.service';
import { RatesService } from './services/rates.service';
import { ServiceTypesService } from './services/service-types.service';
import { ShippingLinesService } from './services/shipping-lines.service';
import { WeightLimitRulesService } from './services/weight-limit-rules.service';
import { YardsService } from './services/yards.service';

import { RuleEngineService } from './rule-engine.service';

import { BookingApprovalStep } from '../bookings/entities/booking-approval-step.entity';
import { BookingCargoModifier } from '../bookings/entities/booking-cargo-modifier.entity';
import { BookingContainer } from '../bookings/entities/booking-container.entity';
import { BookingRateSnapshot } from '../bookings/entities/booking-rate-snapshot.entity';

@Global()
@Module({
  imports: [
    TypeOrmModule.forFeature([
      CargoType,
      ContainerType,
      PriorityConfig,
      ServiceType,
      WeightLimitRule,
      Yard,
      ShippingLine,
      Rate,
      ApprovalRule,
      BookingContainer,
      BookingCargoModifier,
      BookingApprovalStep,
      BookingRateSnapshot,
    ]),
  ],
  controllers: [
    CargoTypesController,
    ContainerTypesController,
    PriorityConfigsController,
    ServiceTypesController,
    WeightLimitRulesController,
    YardsController,
    ShippingLinesController,
    RatesController,
    ApprovalRulesController,
  ],
  providers: [
    CargoTypesRepository,
    { provide: CARGO_TYPES_REPOSITORY, useExisting: CargoTypesRepository },
    ContainerTypesRepository,
    { provide: CONTAINER_TYPES_REPOSITORY, useExisting: ContainerTypesRepository },
    PriorityConfigsRepository,
    { provide: PRIORITY_CONFIGS_REPOSITORY, useExisting: PriorityConfigsRepository },
    ServiceTypesRepository,
    { provide: SERVICE_TYPES_REPOSITORY, useExisting: ServiceTypesRepository },
    WeightLimitRulesRepository,
    { provide: WEIGHT_LIMIT_RULES_REPOSITORY, useExisting: WeightLimitRulesRepository },
    YardsRepository,
    { provide: YARDS_REPOSITORY, useExisting: YardsRepository },
    ShippingLinesRepository,
    { provide: SHIPPING_LINES_REPOSITORY, useExisting: ShippingLinesRepository },
    RatesRepository,
    { provide: RATES_REPOSITORY, useExisting: RatesRepository },
    ApprovalRulesRepository,
    { provide: APPROVAL_RULES_REPOSITORY, useExisting: ApprovalRulesRepository },
    CargoTypesService,
    ContainerTypesService,
    PriorityConfigsService,
    ServiceTypesService,
    WeightLimitRulesService,
    YardsService,
    ShippingLinesService,
    RatesService,
    ApprovalRulesService,
    DisplayOrderService,
    RuleEngineService,
  ],
  exports: [
    RuleEngineService,
    CargoTypesService,
    ServiceTypesService,
    ContainerTypesService,
    WeightLimitRulesService,
    PriorityConfigsService,
    YardsService,
    ShippingLinesService,
    RatesService,
    ApprovalRulesService,
    CARGO_TYPES_REPOSITORY,
    CONTAINER_TYPES_REPOSITORY,
    SERVICE_TYPES_REPOSITORY,
    SHIPPING_LINES_REPOSITORY,
    YARDS_REPOSITORY,
  ],
})
export class RuleEngineModule {}
