<?php

declare(strict_types=1);

namespace App\Repository;

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

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

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