<?php

namespace App\Service\SnipParser\Generic;

use App\Service\SnipParser\AbstractParser;
use League\Pipeline\PipelineBuilder;

class GenericParser extends AbstractParser
{
    public function __construct(
        private readonly  UrlReferenceStage     $referenceStage,
        private readonly  IncludeReferenceStage $includeStage,
    ) {}

    public function safeParseView(string $content): string
    {
        $builder = new PipelineBuilder();
        $pipeline = $builder
            ->add(new HtmlEscapeStage())
//            ->add(new ReplaceBlocksStage('<pre>', '</pre>', '```'))
//            ->add(new ReplaceBlocksStage('<code>', '</code>', '``'))
            ->add(new ReplaceStage(PHP_EOL, '<br>'))
            ->add($this->referenceStage)
            ->add($this->includeStage)
            ->build()
        ;

        return $pipeline->process($content);
    }
}