import { CronModule } from './cron/cron.module';
// Import Modules which has Cron Schedules
// import { CommandsModule } from './commands/commands.module';

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ScheduleModule } from '@nestjs/schedule';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import dbConfiguration from './config/db.config';
import { GlobalExceptionFilter } from './middleware/global-exception.filter';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      load: [dbConfiguration],
    }),
    TypeOrmModule.forRootAsync({
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => {
        const databaseConfig = await configService.get('database');
        return {
          ...databaseConfig,
        };
      },
    }),
    ScheduleModule.forRoot(),
    CronModule,
  ],
  controllers: [AppController],
  providers: [
    {
      provide: AppService,
      useClass: GlobalExceptionFilter,
    },
  ],
})
export class SchedulerModule {}
