import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ScheduleModule } from '@nestjs/schedule';
import { APP_FILTER, APP_INTERCEPTOR, APP_GUARD } from '@nestjs/core';
import { ApiModule } from '@/api/api.module';
import { InfrastructureModule } from '@/infrastructure/infrastructure.module';
import { DomainExceptionFilter } from '@/shared/filters/domain-exception.filter';
import { TransformInterceptor } from '@/shared/interceptors/transform.interceptor';
import { JwtAuthGuard } from '@/shared/guards/jwt-auth.guard';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: [
        `.env.${process.env.NODE_ENV || 'development'}`,
        '.env',
      ],
      // Also load from process.env (system environment variables)
      ignoreEnvFile: false,
    }),
    ScheduleModule.forRoot(),
    InfrastructureModule,
    ApiModule,
  ],
  providers: [
    {
      provide: APP_FILTER,
      useClass: DomainExceptionFilter,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: TransformInterceptor,
    },
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
  ],
})
export class AppModule {}
