<?php

declare(strict_types=1);

namespace App\Repository;

use App\Entity\AbsenceBalance;
use App\Enum\AbsenceType;
use App\Shared\Domain\Contract\UserInterface;
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(UserInterface $user, AbsenceType $type, string $period): ?AbsenceBalance
    {
        return $this->findOneBy([
            'user'   => $user,
            'type'   => $type,
            'period' => $period,
        ]);
    }
}
