<?php
namespace App\Core;

final class ACL
{
    public static array $map = [

        'superadmin' => [
            '/superadmin',
            '/owner',
            '/admin',
        ],

        'conference_chair' => [
            '/admin',
        ],

        'reviewer' => [
            '/review',
        ],

        'author' => [
            '/author',
        ],
    ];

    public static function check(string $uri): void
    {
        if (!isset($_SESSION['user'])) {
            redirect('login');
        }

        $role = $_SESSION['user']['role'] ?? '';
        $allowed = self::$map[$role] ?? [];

        foreach ($allowed as $prefix) {
            if (str_starts_with($uri, $prefix)) {
                return;
            }
        }

        http_response_code(403);
        exit('Access denied by ACL');
    }
}
