<?php

namespace App\Repository;

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

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

    public function findActivePromotions(\DateTimeInterface $date): array
    {
        return $this->createQueryBuilder('p')
            ->where('p.dateStart <= :date')
            ->andWhere('p.dateEnd >= :date')
            ->setParameter('date', $date)
            ->getQuery()
            ->getResult();
    }
}
