import { Module } from '@nestjs/common';
import { APP_GUARD } from '@nestjs/core';
import { ConfigModule } from '@nestjs/config';
import { ThrottlerModule } from '@nestjs/throttler';
import { TrackingModule } from './tracking/tracking.module';
import { HealthModule } from './health/health.module';
import { BeaconModule } from './beacon/beacon.module';
import { WriteKeyGuard } from './auth/write-key.guard';

/**
 * Edge collector app. No TypeORM, no BullMQ root module — the collector owns no
 * database and manages its own dual-redis connections inside {@link RedisRouter}
 * (primary = black redis, spool = local redis). All persistence and enrichment
 * live on the black-side processor/ingest-writer.
 */
@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
      envFilePath: ['.env.local', '.env'],
    }),

    ThrottlerModule.forRoot([
      {
        ttl: 60000, // 1 minute
        limit: 1000, // 1000 requests per minute
      },
    ]),

    TrackingModule,
    HealthModule,
    BeaconModule,
  ],
  providers: [
    {
      provide: APP_GUARD,
      useClass: WriteKeyGuard,
    },
  ],
})
export class AppModule {}
