import { Module } from "@nestjs/common";
import { JwtModule } from "@nestjs/jwt";
import { PassportModule } from "@nestjs/passport";
import { SequelizeModule } from "@nestjs/sequelize";
import { PasswordReset } from "src/database/models/password_reset.model";
import { UserVerification } from "src/database/models/user_verification.model";
import { AppConfigService } from "../../share/app-config.service";
import { UsersModule } from "../users/users.module";
import { AuthController } from "./auth.controller";
import { AuthService } from "./auth.service";
import { JwtStrategy } from "./strategies/jwt.strategy";

@Module({
  imports: [
    PassportModule.register({ defaultStrategy: "jwt" }),
    JwtModule.registerAsync({
      useFactory: (appConfigService: AppConfigService) => ({
        privateKey: appConfigService.jwt().privateKey,
        publicKey: appConfigService.jwt().publicKey,
        signOptions: {
          algorithm: "RS256",
          expiresIn: appConfigService.jwt().expirationTime,
        },
        verifyOptions: {
          algorithms: ["RS256"],
        },
      }),
      inject: [AppConfigService],
    }),
    SequelizeModule.forFeature([
      UserVerification,
      PasswordReset,
    ]),
    UsersModule,
  ],
  controllers: [AuthController],
  providers: [
    AuthService, 
    JwtStrategy
  ],
  exports: [JwtModule, AuthService],
})
export class AuthModule {}
