<?php

declare(strict_types=1);

namespace App\Service\ServiceIterator;

use App\Doctrine\Access\AdditionalExtension\AdditionalAccessExtensionInterface;
use Doctrine\ORM\QueryBuilder;

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

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