<?php

namespace App\Api\Controller;

use App\Document\User;
use Doctrine\ODM\MongoDB\DocumentManager;
use App\Api\Controller\AbstractRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Attribute\CurrentUser;

#[Rest\Route(path: '/api/users', name: 'api_users_')]
class UserRestController extends AbstractRestController
{
    #[Rest\Post('/login', name: 'login')]
    public function login(DocumentManager $dm, #[CurrentUser] ?User $user): Response
    {
        return $this->json([
            'user' => $user ? $user->getId() : null,
        ]);
    }
}