<?php

declare(strict_types=1);

namespace App\Repository;

use App\Entity\AbsenceBalance;
use App\Entity\User;
use App\Enum\AbsenceType;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    public function findOneForPeriod(User $user, AbsenceType $type, string $period): ?AbsenceBalance
    {
        return $this->findOneBy([
            'user'   => $user,
            'type'   => $type,
            'period' => $period,
        ]);
    }
}
