import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { PrismaModule } from '../prisma/prisma.module';
import { UsersModule } from '../users/users.module';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { JwtAuthGuard } from './guards/jwt-auth.guard';
import { RefreshTokenGuard } from './guards/refresh-token.guard';
import { JwtStrategy } from './strategies/jwt.strategy';
import { RefreshTokenStrategy } from './strategies/refresh-token.strategy';

@Module({
  imports: [
    ConfigModule,
    PassportModule,
    JwtModule.registerAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => ({
        secret: configService.get<string>('JWT_ACCESS_SECRET') || 'access-secret',
        signOptions: { expiresIn: configService.get<string>('JWT_ACCESS_EXPIRES', '15m') },
      }),
    }),
    PrismaModule,
    UsersModule,
  ],
  providers: [AuthService, JwtStrategy, RefreshTokenStrategy, JwtAuthGuard, RefreshTokenGuard],
  controllers: [AuthController],
  exports: [JwtAuthGuard, RefreshTokenGuard, AuthService],
})
export class AuthModule {}
