/**
 * JWT Helper Functions
 * 
 * Purpose: Generate and verify JWT tokens for authentication
 * Centralized token logic for consistency
 */

import jwt from 'jsonwebtoken';
import { appConfig } from '../config/app';
import { AuthPayload } from '../@types';

export function generateToken(payload: AuthPayload): string {
  return jwt.sign(payload, appConfig.jwtSecret, {
    expiresIn: appConfig.jwtExpiresIn,
  });
}

export function verifyToken(token: string): AuthPayload | null {
  try {
    return jwt.verify(token, appConfig.jwtSecret) as AuthPayload;
  } catch (error) {
    return null;
  }
}
