<?php

namespace App\Domain\Import\Stages;

use App\Domain\Import\MarkdownSplitter;

class SplitMarkdown
{
    public function __construct(private readonly MarkdownSplitter $splitter)
    {
    }

    public function handle(array $payload, \Closure $next): array
    {
        $markdown = (string) ($payload['markdown'] ?? '');
        $payload['blocks'] = $this->splitter->split($markdown);
        $payload['is_valid'] = $this->splitter->validate($payload['blocks']);

        return $next($payload);
    }
}
