<?php

namespace App\Domain\Import;

use Illuminate\Pipeline\Pipeline;

class ImportPipeline
{
    public function __construct(private readonly Pipeline $pipeline)
    {
    }

    public function run(string $type, array $payload): array
    {
        $stages = match ($type) {
            'markdown' => [
                \App\Domain\Import\Stages\NormalizeMarkdown::class,
                \App\Domain\Import\Stages\SplitMarkdown::class,
            ],
            'pdf' => [
                \App\Domain\Import\Stages\SplitPdf::class,
            ],
            default => [],
        };

        return $this->pipeline
            ->send($payload)
            ->through($stages)
            ->thenReturn();
    }
}
