import { prisma } from "./prisma";
import bcrypt from "bcryptjs";

export async function hashPassword(password: string): Promise<string> {
  return bcrypt.hash(password, 12);
}

export async function verifyPassword(password: string, hashed: string): Promise<boolean> {
  return bcrypt.compare(password, hashed);
}

export function requireRole(user: { role: string }, ...allowed: string[]) {
  if (!allowed.includes(user.role)) {
    throw new Error("Forbidden");
  }
}
