package br.gov.sigefp.rh.repository;

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

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

@Repository
public interface AbsenceRepository extends JpaRepository<Absence, UUID> {

        @Query("SELECT a FROM Absence a WHERE a.agent.id = :agentId " +
                        "AND a.startDate <= :endDate AND a.endDate >= :startDate")
        List<Absence> findByAgentIdAndDateRange(@Param("agentId") UUID agentId,
                        @Param("startDate") LocalDate startDate,
                        @Param("endDate") LocalDate endDate);

        @Query("SELECT a FROM Absence a WHERE a.agent.id IN :agentIds " +
                        "AND a.startDate <= :endDate AND a.endDate >= :startDate")
        List<Absence> findByAgentIdInAndDateRange(@Param("agentIds") List<UUID> agentIds,
                        @Param("startDate") LocalDate startDate,
                        @Param("endDate") LocalDate endDate);

        List<Absence> findByAgentId(UUID agentId);

        org.springframework.data.domain.Page<Absence> findByAgentId(UUID agentId,
                        org.springframework.data.domain.Pageable pageable);
}
