<?php

namespace App\Framework\View\Processing;

use App\Framework\View\DOMTemplateParser;
use App\Framework\View\DomWrapper;
use App\Framework\View\ProcessorResolver;
use App\Framework\View\RenderContext;

final class DomProcessingPipeline
{
    public function __construct(
        private readonly array $processors,
        private ProcessorResolver $resolver,
    )
    {
    }

    public function process(RenderContext $context, string $html): DomWrapper
    {
        $parser = new DOMTemplateParser();
        $dom = $parser->parseToWrapper($html);

        foreach($this->processors as $processorClass) {
            $processor = $this->resolver->resolve($processorClass);

            $dom = $processor->process($dom, $context);
        }
        return $dom;
    }
}
