<?php

namespace App\Controller\Api;

use App\Entity\Utilisateur;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use JMS\Serializer\SerializationContext;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use App\Entity\Post;
use App\Utils\Functions;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\SerializerInterface;

/**
 * Class ApiUtilisateurController
 *
 */
class ApiUtilisateurController extends AbstractController
{

    /**
     * Connexion application
     * @Route("/api/utilisateur/check_token/{token}", methods="GET", name="check_token")
     */
    public function checkTokenAction($token, SerializerInterface $serializer, Request $request) {
        $em = $this->getDoctrine()->getManager();
        $utilisateur = $em->getRepository(Utilisateur::class)->findOneBy(['token_mobilite' => $token]);
        if(is_null($utilisateur)){
            return new JsonResponse(['message' => "Token incorrect"], 403);
        }
        return new JsonResponse(['message' => "Token correct"], 201);
    }
}