<?php

declare(strict_types=1);

namespace App\Module\Absence\Infrastructure\Doctrine;

use App\Module\Absence\Domain\Entity\AbsenceBalance;
use App\Module\Absence\Domain\Enum\AbsenceType;
use App\Module\Absence\Domain\Repository\AbsenceBalanceRepositoryInterface;
use App\Shared\Domain\Contract\UserInterface;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

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

    public function findById(int $id): ?AbsenceBalance
    {
        return $this->find($id);
    }

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