<?php
declare(strict_types=1);

namespace App\Service\ServiceIterator;

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

class OptionalsRolesIterator {

    public function __construct(private iterable $optionalsRoles)
    { }

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