<?php

namespace App\Domain\Services;

use App\Config\RolesConfig;

class RbacService
{
    public function can(int $roleId, string $permission): bool
    {
        $permissions = RolesConfig::permissionsForRoleId($roleId);
        if (in_array('*', $permissions, true) || in_array($permission, $permissions, true)) {
            return true;
        }

        [$prefix] = explode(':', $permission, 2);
        return in_array($prefix . ':*', $permissions, true);
    }
}
