import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { MongooseModule } from '@nestjs/mongoose';
import { APP_GUARD } from '@nestjs/core';
import { GameConfigModule } from './game-config/game-config.module';
import { AuthModule } from './auth/auth.module';
import { JwtAuthGuard } from './auth/guards/jwt-auth.guard';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    MongooseModule.forRoot(process.env.DB_DSN as string, {
      dbName: process.env.DB_DATABASE,
      user: process.env.DB_USER,
      pass: process.env.DB_PASS,
    }),
    AuthModule,
    GameConfigModule,
  ],
  providers: [
    // Register guard through DI — Reflector works correctly in all environments
    { provide: APP_GUARD, useClass: JwtAuthGuard },
  ],
})
export class AppModule {}
