<?php

declare(strict_types=1);

namespace App\Controller\User;

use App\CustomResponse as Response;
use Fig\Http\Message\StatusCodeInterface;
use Psr\Http\Message\ServerRequestInterface as Request;

final class Login extends Base
{
    public function __invoke(Request $request, Response $response): Response
    {
        $input = (array) $request->getParsedBody();
        $jwtData = $this->getUserService()->login($input);
      
//          `User` (`id`, `fecha`, `name`, `email`, `password`, `field1`, `field2`, `field3`, `field4`, `field5`)
        $message = [
            'token' => 'Bearer ' . $jwtData['token'],
            'fk' => $jwtData['id'],
            'name' => $jwtData['name'],
            'email' => $jwtData['email'],
            'field1' => $jwtData['field1'],
            'field2' => $jwtData['field2'],
            'field3' => $jwtData['field3'],
            'field4' => $jwtData['field4'],
            'field5' => $jwtData['field5'],
        ];

        return $response->withJson($message, StatusCodeInterface::STATUS_CREATED);
    }
}
