import { Module } from '@nestjs/common';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { AdminSeedService } from './admin-seed.service';
import { JwtStrategy } from './jwt.strategy';
import { User } from '../../entities/user.entity';
import { License } from '../../entities/license.entity';
import { Role } from '../../entities/role.entity';
import { TeamMember } from '../../entities/team-member.entity';

@Module({
  imports: [
    PassportModule.register({ defaultStrategy: 'jwt' }),
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) => ({
        secret: configService.get<string>('JWT_SECRET'),
        signOptions: {
          expiresIn: configService.get<number>('JWT_ACCESS_EXPIRY_SECONDS', 3600),
        },
      }),
      inject: [ConfigService],
    }),
    TypeOrmModule.forFeature([User, License, Role, TeamMember]),
  ],
  controllers: [AuthController],
  providers: [AuthService, AdminSeedService, JwtStrategy],
  exports: [AuthService],
})
export class AuthModule {}
