import jwt, { type Secret, type SignOptions } from "jsonwebtoken";
import { Role } from "@prisma/client";

const JWT_SECRET: Secret = (process.env.JWT_SECRET || "dev-secret-change-me") as Secret;

export interface JwtPayload {
  userId: string;
  email: string;
  role: Role;
}

export const signJwt = (
  payload: JwtPayload,
  options: SignOptions = { expiresIn: "7d" }
) => {
  return jwt.sign(payload, JWT_SECRET, options);
};

export const verifyJwt = (token: string): JwtPayload => {
  return jwt.verify(token, JWT_SECRET) as JwtPayload;
};
