<?php

declare(strict_types=1);

/*
 * Chill is a software for social workers
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Chill\TicketBundle\Security\Authorization\StoredObjectVoter;

use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\DocStoreBundle\Security\Authorization\StoredObjectRoleEnum;
use Chill\DocStoreBundle\Security\Authorization\StoredObjectVoterInterface;
use Chill\TicketBundle\Repository\MotiveRepository;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

final readonly class MotiveStoredObjectVoter implements StoredObjectVoterInterface
{
    public function __construct(private MotiveRepository $motiveRepository) {}

    public function supports(StoredObjectRoleEnum $attribute, StoredObject $subject): bool
    {
        return null !== $this->motiveRepository->findAssociatedEntityToStoredObject($subject);
    }

    public function voteOnAttribute(StoredObjectRoleEnum $attribute, StoredObject $subject, TokenInterface $token): bool
    {
        return true;
    }
}
