<?php
declare(strict_types=1);

namespace App\Service\Access\OptionalsRoles;

use App\Entity\Access\Access;
use App\Repository\Access\AccessRepository;
use App\Service\Access\OptionalsRolesInterface;
use App\Enum\Access\FunctionEnum;

class CriteriaNotationOptionalRole implements OptionalsRolesInterface {
    public function __construct(
        private AccessRepository $accessRepository
    )
    {}

    /**
     * Return true if the given access is an active teacher and administration has not restricted criteria edition to
     * the admin users.
     *
     * @param Access $access
     * @return bool
     */
    public function support(Access $access): bool
    {
        $isActiveTeacher = $this->accessRepository->hasGotFunctionAtThisDate($access, FunctionEnum::TEACHER(), new \DateTime('now'));
        return $isActiveTeacher && !$access->getOrganization()->getParameters()->getEditCriteriaNotationByAdminOnly();
    }

    public function getRole(): string
    {
        return 'ROLE_CRITERIANOTATION';
    }
}
