<?php

namespace App\Repository;

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

/**
 * @extends ServiceEntityRepository<ProductBlocked>
 *
 * @method ProductBlocked|null find($id, $lockMode = null, $lockVersion = null)
 * @method ProductBlocked|null findOneBy(array $criteria, array $orderBy = null)
 * @method ProductBlocked[]    findAll()
 * @method ProductBlocked[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class ProductBlockedRepository extends ServiceEntityRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, ProductBlocked::class);
    }

    /**
     * @return ProductBlocked[]
     */
    public function findBetweenDates(\DateTimeInterface $start, \DateTimeInterface $end): array
    {
        return $this->createQueryBuilder('pb')
            ->where('pb.dateStart < :end')
            ->andWhere('pb.dateEnd > :start')
            ->setParameter('start', $start)
            ->setParameter('end', $end)
            ->getQuery()
            ->getResult();
    }

    public function findOverlappingForProduct(\App\Entity\Product $product, \DateTimeInterface $start, \DateTimeInterface $end): array
    {
        return $this->createQueryBuilder('pb')
            ->where('pb.product = :product')
            ->andWhere('pb.dateStart < :end')
            ->andWhere('pb.dateEnd > :start')
            ->setParameter('product', $product)
            ->setParameter('start', $start)
            ->setParameter('end', $end)
            ->getQuery()
            ->getResult();
    }

//    /**
//     * @return ProductBlocked[] Returns an array of ProductBlocked objects
//     */
//    public function findByExampleField($value): array
//    {
//        return $this->createQueryBuilder('p')
//            ->andWhere('p.exampleField = :val')
//            ->setParameter('val', $value)
//            ->orderBy('p.id', 'ASC')
//            ->setMaxResults(10)
//            ->getQuery()
//            ->getResult()
//        ;
//    }

//    public function findOneBySomeField($value): ?ProductBlocked
//    {
//        return $this->createQueryBuilder('p')
//            ->andWhere('p.exampleField = :val')
//            ->setParameter('val', $value)
//            ->getQuery()
//            ->getOneOrNullResult()
//        ;
//    }
}
