<?php

namespace App\Domain\Questions\Stages;

use App\Services\AiQuestionStructService;

class NormalizeQuestion
{
    public function __construct(private readonly AiQuestionStructService $service)
    {
    }

    public function handle(array $payload, \Closure $next): array
    {
        $raw = (string) ($payload['raw'] ?? '');
        $fields = $this->service->extractFields($raw);
        $payload = array_merge($payload, $fields);

        return $next($payload);
    }
}
