<?php

namespace MintyPHP\Module\Bookmarks;

use MintyPHP\Service\Access\AuthorizationDecision;
use MintyPHP\Service\Access\AuthorizationPolicyInterface;

final class BookmarksAuthorizationPolicy implements AuthorizationPolicyInterface
{
    public const ABILITY_USE = 'bookmarks.use';

    public function supports(string $ability): bool
    {
        return $ability === self::ABILITY_USE;
    }

    public function authorize(string $ability, array $context = []): AuthorizationDecision
    {
        $actorUserId = (int) ($context['actor_user_id'] ?? 0);
        if ($actorUserId <= 0) {
            return AuthorizationDecision::deny(403, 'forbidden');
        }

        return AuthorizationDecision::allow();
    }
}
