<?php

namespace App\Auth\Repository;

use App\Auth\Entity\PreRegistration;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

class PreRegistrationRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, PreRegistration::class);
    }

    public function hasPendingForMobile(string $mobile): bool
    {
        return (bool) $this->createQueryBuilder('p')
            ->select('1')
            ->where('p.mobile = :mobile')
            ->andWhere('p.status = :status')
            ->setParameter('mobile', $mobile)
            ->setParameter('status', PreRegistration::STATUS_PENDING)
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult();
    }
}
