<?php

declare(strict_types=1);

namespace App\Framework\LiveComponents\FormBuilder;

/**
 * Result eines Form Submits
 */
final readonly class SubmitResult
{
    public function __construct(
        public bool $success,
        public string $message,
        public ?string $redirectUrl = null,
        public array $data = []
    ) {
    }

    public static function success(
        string $message,
        ?string $redirectUrl = null,
        array $data = []
    ): self {
        return new self(
            success: true,
            message: $message,
            redirectUrl: $redirectUrl,
            data: $data
        );
    }

    public static function failure(string $message, array $data = []): self
    {
        return new self(
            success: false,
            message: $message,
            data: $data
        );
    }

    public function hasRedirect(): bool
    {
        return $this->redirectUrl !== null;
    }
}
