import { Inject, Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import type { Request } from 'express';
import { Strategy } from 'passport-jwt';
import { AUTHENTICATION_STRATEGY, type IAuthenticationStrategy } from '../../domain/ports';

@Injectable()
export class JwtPassportStrategy extends PassportStrategy(Strategy, 'jwt') {
  constructor(
    @Inject(AUTHENTICATION_STRATEGY)
    private readonly strategy: IAuthenticationStrategy,
  ) {
    super(strategy.getPassportOptions());
  }

  validate(req: Request, payload: Record<string, unknown>): Promise<object> {
    return this.strategy.validate(req, payload);
  }
}
