<?php

namespace App\Controller\Api;

use App\Enum\Role;
use App\Entity\User;
use App\Request\Response200;
use App\Request\Response422;
use OpenApi\Annotations as OA;
use App\Request\Response200Json;
use App\Request\Response200Message;
use App\Request\User\RequestUpdate;
use App\Controller\Api\ApiController;
use App\Request\User\RequestRegister;
use App\Request\User\RequestUserList;
use App\Repository\PositionRepository;
use App\Repository\DepartmentRepository;
use App\Request\User\RequestUpdateByDni;
use Nelmio\ApiDocBundle\Annotation\Model;
use App\Request\User\RequestChangePassword;
use Nelmio\ApiDocBundle\Annotation\Security;
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
use App\Repository\CompanyLocationRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use FOS\RestBundle\Controller\Annotations as Rest;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Repository\CompanyClassificationRepository;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use SymfonyCasts\Bundle\VerifyEmail\VerifyEmailHelperInterface;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;

class UserController extends ApiController implements Role
{
    /**
     * Make login
     *
     * @Route("/api/login", name="api_login")
     * @OA\Tag(name="user")
     * @OA\Response(
     *     response=200,
     *     description="Ok response",
     *     @Model(type=Response200::class)
     * )
     * @OA\Response(
     *     response=422,
     *     description="Error response",
     *     @Model(type=Response422::class)
     * )
     * @OA\RequestBody(
     *      required=true,
     *       @OA\JsonContent(
     *          @OA\Property(
     *              property="username",
     *              type="string"
     *          ),
    *          @OA\Property(
     *              property="password",
     *              type="string"
     *          ),
     *      )
     * )
     *
     * @param UserInterface|null $user
     * @return Response
     */
    public function login (?UserInterface $user, ValidatorInterface $validator): Response
    {
        if (null === $user)
        {
            return $this->json([
                'message' => 'Missing credentials',
            ], Response::HTTP_UNAUTHORIZED);
        }

        return new Response('Invalid api request. Please use json format', Response::HTTP_NOT_FOUND);
    }
}
