import { Module } from "@nestjs/common";
import { OrdersController } from "./orders.controller.js";
import { CheckoutController } from "./controllers/checkout.controller.js";
import { IntegrationsModule } from "@bff/integrations/integrations.module.js";
import { MappingsModule } from "@bff/modules/id-mappings/mappings.module.js";
import { UsersModule } from "@bff/modules/users/users.module.js";
import { CoreConfigModule } from "@bff/core/config/config.module.js";
import { ServicesModule } from "@bff/modules/services/services.module.js";
import { CacheModule } from "@bff/infra/cache/cache.module.js";
import { VerificationModule } from "@bff/modules/verification/verification.module.js";
import { NotificationsModule } from "@bff/modules/notifications/notifications.module.js";
import { WorkflowModule } from "@bff/modules/shared/workflow/index.js";

// Validators (modular, composable)
import {
  UserMappingValidator,
  PaymentValidator,
  SkuValidator,
  SimOrderValidator,
  InternetOrderValidator,
  OrderCompositeValidator,
} from "./validators/index.js";

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

// Clean modular fulfillment services
import { OrderFulfillmentValidator } from "./services/order-fulfillment-validator.service.js";
import { OrderFulfillmentOrchestrator } from "./services/order-fulfillment-orchestrator.service.js";
import { OrderFulfillmentErrorService } from "./services/order-fulfillment-error.service.js";
import { SimFulfillmentService } from "./services/sim-fulfillment.service.js";
import { FulfillmentSideEffectsService } from "./services/fulfillment-side-effects.service.js";
import { FulfillmentContextMapper } from "./services/fulfillment-context-mapper.service.js";
import { FulfillmentStepExecutors } from "./services/fulfillment-step-executors.service.js";
import { FulfillmentStepFactory } from "./services/fulfillment-step-factory.service.js";
import { ProvisioningQueueService } from "./queue/provisioning.queue.js";
import { ProvisioningProcessor } from "./queue/provisioning.processor.js";
import { SalesforceOrderFieldConfigModule } from "@bff/integrations/salesforce/config/salesforce-order-field-config.module.js";

@Module({
  imports: [
    IntegrationsModule,
    MappingsModule,
    UsersModule,
    CoreConfigModule,
    ServicesModule,
    CacheModule,
    VerificationModule,
    NotificationsModule,
    SalesforceOrderFieldConfigModule,
    WorkflowModule,
  ],
  controllers: [OrdersController, CheckoutController],
  providers: [
    // Validators (modular, composable)
    UserMappingValidator,
    PaymentValidator,
    SkuValidator,
    SimOrderValidator,
    InternetOrderValidator,
    OrderCompositeValidator,

    // Shared services (legacy - PaymentValidatorService used by OrderFulfillmentValidator)
    PaymentValidatorService,
    OrderEventsService,

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

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