<?php

namespace LaraBB\Post\UI\Web\Handlers;

use App\Http\Controllers\Controller;
use Exception;
use Illuminate\Http\RedirectResponse;
use LaraBB\Post\Actions\DestroyAction;
use LaraBB\Post\UI\Web\Requests\Destroy;

/**
 * Class DestroyHandler
 * @package LaraBB\Post\UI\Web\Handlers
 */
class DestroyHandler extends Controller
{
    /**
     * DestroyHandler constructor.
     * @param DestroyAction $destroyAction
     */
    public function __construct(private readonly DestroyAction $destroyAction)
    {

    }

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