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';
// [2026-02-17] 新增：预种计划提现限制
import { PrePlantingGuardModule } from './pre-planting/pre-planting-guard.module';

@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,
    // [2026-02-17] 新增：预种计划提现限制
    PrePlantingGuardModule,
  ],
  providers: [
    {
      provide: APP_FILTER,
      useClass: DomainExceptionFilter,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: TransformInterceptor,
    },
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard,
    },
  ],
})
export class AppModule {}
