import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';

/**
 * Shared JWT Passport Strategy.
 * Register as a provider in each service module that uses JwtAuthGuard.
 *
 * Usage in module:
 *   providers: [JwtStrategy, ...]
 */
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
  constructor() {
    super({
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      ignoreExpiration: false,
      secretOrKey: process.env.JWT_ACCESS_SECRET || 'dev-access-secret',
    });
  }

  async validate(payload: { sub: string; role: string; kycLevel: number; type: string }) {
    return { sub: payload.sub, role: payload.role, kycLevel: payload.kycLevel };
  }
}
