<?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\MainBundle\Security\Authorization;

use Chill\MainBundle\Entity\ExportGeneration;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;

class ExportGenerationVoter extends Voter
{
    public const VIEW = 'view';

    protected function supports(string $attribute, $subject)
    {
        return self::VIEW === $attribute && $subject instanceof ExportGeneration;
    }

    protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token)
    {
        /* @var ExportGeneration $subject */
        return $token->getUser()->getUserIdentifier() === $subject->getCreatedBy()->getUserIdentifier();
    }
}
