<?php

// Pipeline for processing Instagram post descriptions

namespace App\Browser\Jobs\InstagramRepost\DescriptionPipeline;

class InstagramDescriptionPipeline
{
    /**
     * @var array of IInstagramDescriptionPipelineStep
     */
    private array $steps;

    /**
     * InstagramDescriptionPipeline constructor.
     *
     * @param array $steps
     */
    public function __construct(array $steps)
    {
        $this->steps = $steps;
    }

    /**
     * Process the description through the pipeline.
     *
     * @param string $description
     * @return string
     */
    public function process(string $description): string
    {
        foreach ($this->steps as $step) {
            if (!$step instanceof IInstagramDescriptionPipelineStep) {
                throw new \InvalidArgumentException('All steps must implement IInstagramDescriptionPipelineStep interface.');
            }

            $description = $step->process($description);
        }

        return $description;
    }
}
