<?php

declare(strict_types=1);

namespace Builder\Core\Foundation\Support;

use Builder\Core\Foundation\Enums\ToastType;

/**
 * Flash a toast payload onto a redirect — frontend AdminLayout reads it
 * from `page.props.flash.toast` and fires a Sonner toast.
 *
 * Replaces the previous `RedirectResponse::withToast()` macro: keeping it
 * a plain static method lets PHPStan resolve the signature without
 * Macroable reflection gymnastics, and reads identically at the call site.
 *
 *   return redirect()->route('x')->with(Toast::flash(ToastType::Success, $msg));
 */
final class Toast
{
    /** @return array{toast: array{type: string, message: string}} */
    public static function flash(ToastType $type, string $message): array
    {
        return ['toast' => ['type' => $type->value, 'message' => $message]];
    }
}
