<?php

declare(strict_types=1);

namespace App\Framework\Console\Security\Attributes;

use App\Framework\Console\Security\Permission;
use Attribute;

#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
final readonly class RequiresPermission
{
    /**
     * @param Permission|Permission[] $permissions
     * @param PermissionMode $mode
     */
    public function __construct(
        public Permission|array $permissions,
        public PermissionMode $mode = PermissionMode::ANY
    ) {
    }

    public function getPermissions(): array
    {
        return is_array($this->permissions) ? $this->permissions : [$this->permissions];
    }
}
