<?php

declare(strict_types=1);

namespace App\Repository;

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

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

    /**
     * @return Observation[]
     */
    public function findByMonth(DateTimeImmutable $from, DateTimeImmutable $to): array
    {
        return $this->createQueryBuilder('o')
            ->andWhere('o.month >= :from')
            ->andWhere('o.month <= :to')
            ->setParameter('from', $from)
            ->setParameter('to', $to)
            ->innerJoin('o.employee', 'e')
            ->addSelect('e')
            ->getQuery()
            ->getResult()
        ;
    }
}
