import { Module } from "@nestjs/common";
import { FreebitModule } from "@bff/integrations/freebit/freebit.module.js";
import { WhmcsModule } from "@bff/integrations/whmcs/whmcs.module.js";
import { SalesforceModule } from "@bff/integrations/salesforce/salesforce.module.js";
import { MappingsModule } from "@bff/modules/id-mappings/mappings.module.js";
import { SftpModule } from "@bff/integrations/sftp/sftp.module.js";
import { SecurityModule } from "@bff/core/security/security.module.js";
import { SimUsageStoreService } from "../sim-usage-store.service.js";
import { SubscriptionsOrchestrator } from "../subscriptions-orchestrator.service.js";
import { SharedSubscriptionsModule } from "../shared/index.js";
// SimController is registered in SubscriptionsModule to ensure route order

// Import SIM management services - organized by responsibility
import { SimOrchestrator } from "./services/sim-orchestrator.service.js";
import { SimValidationService } from "./services/sim-validation.service.js";
// Query services (read operations)
import { SimDetailsService } from "./services/queries/sim-details.service.js";
import { SimUsageService } from "./services/queries/sim-usage.service.js";
import { SimBillingService } from "./services/queries/sim-billing.service.js";
import { SimTopUpPricingService } from "./services/queries/sim-topup-pricing.service.js";
// Mutation services (write operations)
import { SimTopUpService } from "./services/mutations/sim-topup.service.js";
import { SimPlanService } from "./services/mutations/sim-plan.service.js";
import { SimCancellationService } from "./services/mutations/sim-cancellation.service.js";
import { EsimManagementService } from "./services/mutations/esim-management.service.js";
// Support services (utilities)
import { SimCallHistoryService } from "./services/support/sim-call-history.service.js";
import { SimCallHistoryParserService } from "./services/support/sim-call-history-parser.service.js";
import { SimCallHistoryFormatterService } from "./services/support/sim-call-history-formatter.service.js";
import { SimNotificationService } from "./services/support/sim-notification.service.js";
import { SimScheduleService } from "./services/support/sim-schedule.service.js";
// Queue services
import { SimManagementQueueService } from "./queue/sim-management.queue.js";
import { SimManagementProcessor } from "./queue/sim-management.processor.js";
import { ServicesModule } from "@bff/modules/services/services.module.js";
import { NotificationsModule } from "@bff/modules/notifications/notifications.module.js";
import { VoiceOptionsModule, VoiceOptionsService } from "@bff/modules/voice-options/index.js";
import { WorkflowModule } from "@bff/modules/shared/workflow/index.js";

@Module({
  imports: [
    FreebitModule,
    WhmcsModule,
    SalesforceModule,
    MappingsModule,
    ServicesModule,
    SftpModule,
    NotificationsModule,
    SecurityModule,
    VoiceOptionsModule,
    WorkflowModule,
    SharedSubscriptionsModule,
  ],
  // SimController is registered in SubscriptionsModule to ensure route order
  // (more specific routes like :id/sim must be registered before :id)
  controllers: [],
  providers: [
    // Core services that the SIM services depend on
    SimUsageStoreService,
    SubscriptionsOrchestrator,

    // SIM management services
    SimValidationService,
    SimNotificationService,
    SimDetailsService,
    SimUsageService,
    SimTopUpService,
    SimTopUpPricingService,
    SimPlanService,
    SimCancellationService,
    EsimManagementService,
    SimOrchestrator,
    SimBillingService,
    SimScheduleService,
    SimManagementQueueService,
    SimManagementProcessor,
    // Call history services (split for maintainability)
    SimCallHistoryParserService,
    SimCallHistoryFormatterService,
    SimCallHistoryService,
    // Backwards compatibility alias: SimVoiceOptionsService -> VoiceOptionsService
    {
      provide: "SimVoiceOptionsService",
      useExisting: VoiceOptionsService,
    },
  ],
  exports: [
    SimOrchestrator,
    // Export individual services in case they're needed elsewhere
    SimDetailsService,
    SimUsageService,
    SimTopUpService,
    SimTopUpPricingService,
    SimPlanService,
    SimCancellationService,
    EsimManagementService,
    SimValidationService,
    SimNotificationService,
    SimBillingService,
    SimScheduleService,
    SimManagementQueueService,
    SimCallHistoryService,
    // VoiceOptionsService is exported from VoiceOptionsModule
    // Backwards compatibility: re-export the token
    "SimVoiceOptionsService",
  ],
})
export class SimManagementModule {}
