<?php

namespace LaraBB\Thread\UI\Web\Handlers;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\RedirectResponse;
use LaraBB\Thread\Actions\CreateAction;
use LaraBB\Thread\UI\Web\Requests\Create;

/**
 * Class CreateHandler
 * @package LaraBB\Thread\UI\Web\Handlers
 */
class CreateHandler extends Controller
{
    /**
     * CreateHandler constructor.
     * @param CreateAction $createAction
     * @param Factory $view
     */
    public function __construct(private readonly CreateAction $createAction, private readonly Factory $view)
    {

    }

    /**
     * @param Create $request
     * @return Application|Factory|View|RedirectResponse
     */
    public function __invoke(Create $request): View|Factory|RedirectResponse|Application
    {
        $data = $this->createAction->run($request);

        return $this->view->make('thread::create-edit', [
            'forum'  => $data['forum'],
            'groups' => $data['groups'],
            'users'  => $data['users']
        ]);
    }
}
