import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { APP_GUARD } from '@nestjs/core';
import { ThrottlerModule } from '@nestjs/throttler';
import { AdminModule } from './admin/admin.module';
import { AnnouncementsModule } from './announcements/announcements.module';
import { AuditModule } from './audit/audit.module';
import { EstateAccessGuard } from './auth/estate-access.guard';
import { JwtAuthGuard } from './auth/jwt-auth.guard';
import { RolesGuard } from './auth/roles.guard';
import { AuthModule } from './auth/auth.module';
import { CheckinModule } from './checkin/checkin.module';
import { DatabaseModule } from './database/database.module';
import { EstatesModule } from './estates/estates.module';
import { FeatureAccessGuard } from './features/feature-access.guard';
import { FeatureAccessModule } from './features/feature-access.module';
import { GatesModule } from './gates/gates.module';
import { GuardsModule } from './guards/guards.module';
import { IncidentsModule } from './incidents/incidents.module';
import { IntegrationConfigModule } from './integrations/integration-config.module';
import { NotificationsModule } from './notifications/notifications.module';
import { OfflineModule } from './offline/offline.module';
import { OnboardingModule } from './onboarding/onboarding.module';
import { PaymentGatewayModule } from './payments/payment-gateway.module';
import { ProfileModule } from './profile/profile.module';
import { ResidentsModule } from './residents/residents.module';
import { RequestsModule } from './requests/requests.module';
import { SandboxModule } from './sandbox/sandbox.module';
import { VisitorsModule } from './visitors/visitors.module';
import { AppController } from './app.controller';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    ThrottlerModule.forRoot([
      {
        name: 'short',
        ttl: 60000, // 1 minute
        limit: 10 // 10 requests per minute (default)
      },
      {
        name: 'auth',
        ttl: 60000, // 1 minute
        limit: 5 // 5 requests per minute for auth endpoints
      }
    ]),
    DatabaseModule,
    IntegrationConfigModule,
    AuditModule,
    AnnouncementsModule,
    AdminModule,
    AuthModule,
    EstatesModule,
    FeatureAccessModule,
    GatesModule,
    GuardsModule,
    ResidentsModule,
    VisitorsModule,
    CheckinModule,
    OfflineModule,
    OnboardingModule,
    IncidentsModule,
    NotificationsModule,
    PaymentGatewayModule,
    ProfileModule,
    RequestsModule,
    SandboxModule
  ],
  controllers: [AppController],
  providers: [
    {
      provide: APP_GUARD,
      useClass: JwtAuthGuard
    },
    {
      provide: APP_GUARD,
      useClass: EstateAccessGuard
    },
    {
      provide: APP_GUARD,
      useClass: RolesGuard
    },
    {
      provide: APP_GUARD,
      useClass: FeatureAccessGuard
    }
  ]
})
export class AppModule {}
