<?php

namespace LaraBB\User\UI\Web\Handlers;

use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use LaraBB\User\Actions\LoginAction;
use LaraBB\User\UI\Web\Requests\Login;

/**
 * Class LoginHandler
 * @package LaraBB\User\UI\Web\Handlers
 */
class LoginHandler extends Controller
{
    /**
     * LoginHandler constructor.
     * @param LoginAction $loginAction
     */
    public function __construct(private readonly LoginAction $loginAction)
    {
    }

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