<?php
declare(strict_types=1);

namespace App\Service\ServiceIterator;

use App\Doctrine\Access\AccessExtensionInterface;
use Doctrine\ORM\QueryBuilder;

class CurrentAccessExtensionIterator {
    /**
     * @param iterable<AccessExtensionInterface> $extensions
     */
    public function __construct(readonly private iterable $extensions)
    { }

    public function addWhere(QueryBuilder $queryBuilder, string $operationName): void {
        /** @var AccessExtensionInterface $extension */
        foreach ($this->extensions as $extension){
            if($extension->support($operationName)) {
                $extension->addWhere($queryBuilder);
                break;
            }
        }
    }
}
