import { Module } from "@nestjs/common";
import { OrdersController } from "./orders.controller";
import { CheckoutController } from "./controllers/checkout.controller";
import { IntegrationsModule } from "@bff/integrations/integrations.module";
import { MappingsModule } from "@bff/modules/id-mappings/mappings.module";
import { UsersModule } from "@bff/modules/users/users.module";
import { CoreConfigModule } from "@bff/core/config/config.module";
import { DatabaseModule } from "@bff/core/database/database.module";
import { CatalogModule } from "@bff/modules/catalog/catalog.module";
import { CacheModule } from "@bff/infra/cache/cache.module";

// Clean modular order services
import { OrderValidator } from "./services/order-validator.service";
import { OrderBuilder } from "./services/order-builder.service";
import { OrderItemBuilder } from "./services/order-item-builder.service";
import { OrderPricebookService } from "./services/order-pricebook.service";
import { OrderOrchestrator } from "./services/order-orchestrator.service";
import { PaymentValidatorService } from "./services/payment-validator.service";
import { CheckoutService } from "./services/checkout.service";
import { OrderEventsService } from "./services/order-events.service";
import { OrdersCacheService } from "./services/orders-cache.service";

// Clean modular fulfillment services
import { OrderFulfillmentValidator } from "./services/order-fulfillment-validator.service";
import { OrderFulfillmentOrchestrator } from "./services/order-fulfillment-orchestrator.service";
import { OrderFulfillmentErrorService } from "./services/order-fulfillment-error.service";
import { SimFulfillmentService } from "./services/sim-fulfillment.service";
import { ProvisioningQueueService } from "./queue/provisioning.queue";
import { ProvisioningProcessor } from "./queue/provisioning.processor";
import { OrderFieldConfigModule } from "./config/order-field-config.module";

@Module({
  imports: [
    IntegrationsModule,
    MappingsModule,
    UsersModule,
    CoreConfigModule,
    DatabaseModule,
    CatalogModule,
    CacheModule,
    OrderFieldConfigModule,
  ],
  controllers: [OrdersController, CheckoutController],
  providers: [
    // Shared services
    PaymentValidatorService,
    OrderEventsService,

    // Order creation services (modular)
    OrderValidator,
    OrderBuilder,
    OrderItemBuilder,
    OrderPricebookService,
    OrderOrchestrator,
    OrdersCacheService,
    CheckoutService,

    // Order fulfillment services (modular)
    OrderFulfillmentValidator,
    OrderFulfillmentOrchestrator,
    OrderFulfillmentErrorService,
    SimFulfillmentService,
    // Async provisioning queue
    ProvisioningQueueService,
    ProvisioningProcessor,
  ],
  exports: [OrderOrchestrator, CheckoutService, ProvisioningQueueService, OrdersCacheService],
})
export class OrdersModule {}
