<?php

namespace LaraBB\User\UI\Web\Handlers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use LaraBB\User\Actions\Admin\UpdateAction;
use LaraBB\User\UI\Web\Requests\Update;

/**
 * Class UpdateHandler
 * @package LaraBB\User\UI\Web\Handlers\Admin
 */
class UpdateHandler extends Controller
{
    /**
     * UpdateHandler constructor.
     * @param UpdateAction $updateAction
     */
    public function __construct(private readonly UpdateAction $updateAction)
    {
    }

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