import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { JwtModule } from '@nestjs/jwt';
import { PassportModule } from '@nestjs/passport';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { AuthController } from './auth.controller';
import { AuthService } from './auth.service';
import { PasswordResetService } from './password-reset.service';
import { MFAService } from './mfa.service';
import { SessionService } from './session.service';
import { DeviceTrustService } from './device-trust.service';
import { BiometricAuthService } from './biometric-auth.service';
import { JwtStrategy } from './strategies/jwt.strategy';
import { LocalStrategy } from './strategies/local.strategy';
import { CommonModule } from '../../common/common.module';
import { WebAuthnCredential } from './entities/webauthn-credential.entity';
import {
  User,
  DeviceRegistry,
  RefreshToken,
  PasswordResetToken,
  Family,
  FamilyMember,
} from '../../database/entities';

@Module({
  imports: [
    TypeOrmModule.forFeature([
      User,
      DeviceRegistry,
      RefreshToken,
      PasswordResetToken,
      Family,
      FamilyMember,
      WebAuthnCredential,
    ]),
    PassportModule,
    CommonModule,
    JwtModule.registerAsync({
      imports: [ConfigModule],
      useFactory: (configService: ConfigService) => ({
        secret: configService.get<string>('JWT_SECRET'),
        signOptions: {
          expiresIn: configService.get<string>('JWT_EXPIRATION', '1h'),
        },
      }),
      inject: [ConfigService],
    }),
  ],
  controllers: [AuthController],
  providers: [
    AuthService,
    PasswordResetService,
    MFAService,
    SessionService,
    DeviceTrustService,
    BiometricAuthService,
    JwtStrategy,
    LocalStrategy,
  ],
  exports: [
    AuthService,
    PasswordResetService,
    MFAService,
    SessionService,
    DeviceTrustService,
    BiometricAuthService,
  ],
})
export class AuthModule {}
