<?php
declare(strict_types=1);

namespace App\Service\ServiceIterator;

use App\Entity\Access\Access;
use App\Service\Access\OptionalsRolesInterface;

class OptionalsRolesIterator {

    /**
     * @param iterable<OptionalsRolesInterface> $optionalsRoles
     */
    public function __construct(readonly private iterable $optionalsRoles)
    { }

    /**
     * @param Access $access
     * @return list<string>
     */
    public function getOptionalsRoles(Access $access):array {
        $roles = [];
        /** @var OptionalsRolesInterface $optionalsRoles */
        foreach ($this->optionalsRoles as $optionalsRoles){
            if($optionalsRoles->support($access)) {
                $roles[] = $optionalsRoles->getRole();
            }
        }
        return $roles;
    }
}
