package br.gov.sigefp.rh.repository;

import br.gov.sigefp.rh.domain.FamilyAllowanceTable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.time.LocalDate;
import java.util.Optional;
import java.util.UUID;

public interface FamilyAllowanceTableRepository extends JpaRepository<FamilyAllowanceTable, UUID> {

    @Query("SELECT f FROM FamilyAllowanceTable f WHERE f.dependentsCount = :count AND f.validFrom <= :date AND (f.validTo IS NULL OR f.validTo >= :date)")
    Optional<FamilyAllowanceTable> findByDependentsAndDate(@Param("count") Integer count,
            @Param("date") LocalDate date);
}
