<?php

declare(strict_types=1);

namespace App\Framework\Console\Security\Attributes;

enum PermissionMode: string
{
    case ANY = 'any';   // User needs ANY of the specified permissions
    case ALL = 'all';   // User needs ALL of the specified permissions

    public function check(array $userPermissions, array $requiredPermissions): bool
    {
        return match ($this) {
            self::ANY => ! empty(array_intersect($userPermissions, $requiredPermissions)),
            self::ALL => empty(array_diff($requiredPermissions, $userPermissions))
        };
    }
}
