<?php

namespace App\Security;

use App\Enum\Exceptions as ExceptionsMsg;
use App\Entity\User as AppUser;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use App\Enum\Exceptions;


class UserChecker implements UserCheckerInterface
{
    public function checkPreAuth(UserInterface $user): void
    {
        if (!$user instanceof AppUser) {
            return;
        }
    }

    public function checkPostAuth(UserInterface $user): void
    {
        // Si utilisateur n'existe pas, on ferme.
        if (!$user instanceof AppUser) {
            return;
        }

        // Sinon, on passe à la suite en contrôlant si le compte est actif
        if ($user instanceof AppUser) {
            if (!$user->isVerified()) {
                
                throw new AuthenticationException(ExceptionsMsg::NOT_VERIFIED_USER->value);
            }

        }
    }
} 

?>