<?php

namespace LaraBB\User\UI\Web\Handlers;

use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use LaraBB\User\Actions\RegisterAction;
use LaraBB\User\UI\Web\Requests\Register\Store;

/**
 * Class RegisterHandler
 * @package LaraBB\User\UI\Web\Handlers
 */
class RegisterHandler extends Controller
{
    /**
     * RegisterHandler constructor.
     * @param RegisterAction $registerAction
     */
    public function __construct(private readonly RegisterAction $registerAction)
    {
    }

    /**
     * @param Store $request
     * @return RedirectResponse
     */
    public function __invoke(Store $request): RedirectResponse
    {
        return $this->registerAction->run($request) ? $request->success() : $request->failed();
    }
}
