<?php

declare(strict_types=1);

namespace App\Application\Auth;

use App\Framework\Attributes\Route;
use App\Framework\Auth\Auth;
use App\Framework\CommandBus\CommandBus;
use App\Framework\Http\Method;
use App\Framework\Router\Result\ViewResult;

final readonly class ShowLogin
{
    public function __construct(
        private CommandBus $commandBus,
    ) {
    }

    #[Auth]
    #[Route('/login')]
    public function __invoke(): ViewResult
    {
        return new ViewResult('loginform');

    }

    #[Auth]
    #[Route('/login', Method::POST)]
    public function login(LoginRequest $request): void
    {
        $login = new LoginUser($request->email, $request->password);

        $this->commandBus->dispatch($login);

        dd($request);
        // TODO: Return proper response

    }
}
