<?php

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

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

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