<?php

namespace App\Appointment\Repository;

use App\Appointment\Entity\DateOverride;
use App\Doctor\Entity\Doctor;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    public function findByUuid(string $uuid): ?DateOverride
    {
        return $this->findOneBy(['uuid' => $uuid]);
    }

    /** @return DateOverride[] */
    public function findByDoctor(Doctor $doctor): array
    {
        return $this->findBy(['doctor' => $doctor], ['date' => 'ASC']);
    }

    public function save(DateOverride $entity, bool $flush = true): void
    {
        $this->getEntityManager()->persist($entity);
        if ($flush) $this->getEntityManager()->flush();
    }

    public function remove(DateOverride $entity, bool $flush = true): void
    {
        $this->getEntityManager()->remove($entity);
        if ($flush) $this->getEntityManager()->flush();
    }
}
