<?php

namespace Formatrica\Submission\Pipeline\Stages;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use Formatrica\Submission\Pipeline\Submission_Context;
use Formatrica\Submission\Pipeline\Submission_Stage;

/**
 * The formatrica_submission_request filter — lets extensions rewrite the raw
 * request payload before validation.
 */
final class Filter_Request_Stage implements Submission_Stage
{
    public function handle(Submission_Context $ctx): void
    {
        $filtered_request = apply_filters('formatrica_submission_request', $ctx->request_data, $ctx->form_id, $ctx->form, $ctx->context);

        if (is_array($filtered_request)) {
            $ctx->request_data = $filtered_request;
        }
    }
}
