<?php
session_start();

function requireRole(array $roles) {
  $role = $_SESSION['role'] ?? 'guest';
  if (!in_array($role, $roles)) {
    header('Location: /login/index.php');
    exit;
  }
}

function hasPermission(string $perm): bool {
  $role = $_SESSION['role'] ?? 'guest';
  if ($role === 'master' || $role === 'admin') return true;
  return isset($_SESSION['permissions'][$perm]) && $_SESSION['permissions'][$perm] === 'full';
}
