<?php

namespace LaraBB\Post\UI\Web\Handlers;

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

/**
 * Class UpdateHandler
 * @package LaraBB\Post\UI\Web\Handlers
 */
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();
    }
}
