import { Module } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { JwtModule } from '@nestjs/jwt';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { HealthController } from '../api/controllers/health.controller';
import { LeaderboardController } from '../api/controllers/leaderboard.controller';
import { LeaderboardPublicController } from '../api/controllers/leaderboard-public.controller';
import { LeaderboardConfigController } from '../api/controllers/leaderboard-config.controller';
import { VirtualAccountController } from '../api/controllers/virtual-account.controller';
import { JwtStrategy } from '../api/strategies/jwt.strategy';
import { ApplicationModule } from './application.module';
import { DomainModule } from './domain.module';
import { InfrastructureModule } from './infrastructure.module';

@Module({
  imports: [
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        secret: configService.get<string>('JWT_SECRET'),
        signOptions: {
          expiresIn: configService.get<string>('JWT_ACCESS_EXPIRES_IN', '2h'),
        },
      }),
      inject: [ConfigService],
    }),
    ApplicationModule,
    DomainModule,
    InfrastructureModule,
  ],
  controllers: [
    HealthController,
    LeaderboardController,
    LeaderboardPublicController,
    LeaderboardConfigController,
    VirtualAccountController,
  ],
  providers: [
    JwtStrategy,
  ],
})
export class ApiModule {}
