import { Module } from "@nestjs/common";
import { ConfigModule, ConfigService } from "@nestjs/config";
import { ScheduleModule } from "@nestjs/schedule";
import { TypeOrmModule, TypeOrmModuleOptions } from "@nestjs/typeorm";
import appConfig from "./config/app.config";
import databaseConfig from "./config/database.config";
import notifierConfig from "./config/notifier.config";
import rabbitmqConfig from "./config/rabbitmq.config";
import telebirrConfig from "./config/telebirr.config";
import waafiConfig from "./config/waafi.config";
import cbeConfig from "./config/cbe.config";
import ebirrConfig from "./config/ebirr.config";
import cardConfig from "./config/card.config";
import dmoneyConfig from "./config/dmoney.config";
import cacConfig from "./config/cac.config";
import { HealthModule } from "./modules/health/health.module";
import { IntentsModule } from "./modules/intents/intents.module";
import { OutboxModule } from "./modules/outbox/outbox.module";
import { ProvidersModule } from "./modules/providers/providers.module";
import { ReconciliationModule } from "./modules/reconciliation/reconciliation.module";
import { WebhooksModule } from "./modules/webhooks/webhooks.module";

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      load: [
        appConfig,
        databaseConfig,
        notifierConfig,
        rabbitmqConfig,
        telebirrConfig,
        waafiConfig,
        cbeConfig,
        ebirrConfig,
        cardConfig,
        dmoneyConfig,
        cacConfig,
      ],
    }),
    TypeOrmModule.forRootAsync({
      inject: [ConfigService],
      useFactory: (config: ConfigService) =>
        config.get<TypeOrmModuleOptions>("database") as TypeOrmModuleOptions,
    }),
    ScheduleModule.forRoot(),
    HealthModule,
    ProvidersModule,
    IntentsModule,
    WebhooksModule,
    OutboxModule,
    ReconciliationModule,
  ],
})
export class AppModule {}
