<?php

namespace App\Repository;

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

/**
 * @extends ServiceEntityRepository<BilletBuyer>
 */
class BilletBuyerRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, BilletBuyer::class);
    }

    /**
     * @return BilletBuyer[]
     */
    public function findExpiredPending(\DateTimeImmutable $threshold): array
    {
        return $this->createQueryBuilder('o')
            ->where('o.status = :status')
            ->andWhere('o.createdAt < :threshold')
            ->setParameter('status', BilletBuyer::STATUS_PENDING)
            ->setParameter('threshold', $threshold)
            ->getQuery()
            ->getResult();
    }
}
