import type { CurrentUser, PermissionName } from "@/types/rbac";

export function hasPermission(user: CurrentUser | null | undefined, permission: PermissionName) {
  return Boolean(user?.permissions.includes(permission));
}

export function hasAnyPermission(
  user: CurrentUser | null | undefined,
  permissions: PermissionName[],
) {
  return permissions.some((permission) => hasPermission(user, permission));
}

export function hasAllPermissions(
  user: CurrentUser | null | undefined,
  permissions: PermissionName[],
) {
  return permissions.every((permission) => hasPermission(user, permission));
}
