import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ScheduleModule } from '@nestjs/schedule';
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
import { APP_GUARD } from '@nestjs/core';
import { join } from 'path';

import { PrismaModule } from './common/prisma/prisma.module';
import { AuthModule } from './modules/auth/auth.module';
import { UsersModule } from './modules/users/users.module';
import { LocalitiesModule } from './modules/localities/localities.module';
import { LocationsModule } from './modules/locations/locations.module';
import { SamudayModule } from './modules/samuday/samuday.module';
import { ViharsModule } from './modules/vihars/vihars.module';
import { AllocationsModule } from './modules/allocations/allocations.module';
import { PlacesModule } from './modules/places/places.module';
import { RoutesModule } from './modules/routes/routes.module';
import { StatsModule } from './modules/stats/stats.module';
import { InternalModule } from './modules/internal/internal.module';
import { HealthModule } from './modules/health/health.module';
import { TemplatesModule } from './modules/templates/templates.module';
import { SaintsModule } from './modules/saints/saints.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: [join(process.cwd(), '../../.env'), join(process.cwd(), '.env')],
    }),
    ScheduleModule.forRoot(),
    ThrottlerModule.forRoot([
      { name: 'short', ttl: 1000, limit: 10 },
      { name: 'medium', ttl: 60000, limit: 200 },
      { name: 'login', ttl: 15 * 60 * 1000, limit: 20 },
    ]),
    PrismaModule,

    // Feature modules
    HealthModule,
    AuthModule,
    UsersModule,
    LocalitiesModule,
    LocationsModule,
    SamudayModule,
    ViharsModule,
    AllocationsModule,
    PlacesModule,
    RoutesModule,
    StatsModule,
    InternalModule,
    TemplatesModule,
    SaintsModule,
  ],
  providers: [
    { provide: APP_GUARD, useClass: ThrottlerGuard },
  ],
})
export class AppModule {}
