<?php

declare(strict_types=1);

namespace App\Framework\View\Processing;

use App\Framework\Template\Processing\ProcessorResolver;
use App\Framework\Template\Processing\StringProcessor;
use App\Framework\View\RenderContext;

final readonly class StringProcessingPipeline
{
    /** @param class-string[] $processors */
    public function __construct(
        private array             $processors,
        private ProcessorResolver $resolver,
    ) {
    }

    public function process(string $html, RenderContext $context): string
    {
        foreach ($this->processors as $processorClass) {
            /** @var StringProcessor $processor */
            $processor = $this->resolver->resolve($processorClass);
            $html = $processor->process($html, $context);
        }

        return $html;
    }
}
