package br.gov.sigefp.rh.repository;

import br.gov.sigefp.rh.domain.AttendanceRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

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

@Repository
public interface AttendanceRecordRepository extends JpaRepository<AttendanceRecord, UUID> {

    List<AttendanceRecord> findBySheetId(UUID sheetId);

    @Query("SELECT r FROM AttendanceRecord r WHERE r.agent.id = :agentId AND r.date BETWEEN :startDate AND :endDate")
    List<AttendanceRecord> findByAgentIdAndDateRange(UUID agentId, LocalDate startDate, LocalDate endDate);

    @Query("SELECT r FROM AttendanceRecord r WHERE r.agent.id IN :agentIds AND r.date BETWEEN :startDate AND :endDate")
    List<AttendanceRecord> findByAgentIdInAndDateRange(List<UUID> agentIds, LocalDate startDate, LocalDate endDate);

    @Modifying
    @Query("DELETE FROM AttendanceRecord r WHERE r.sheet.id = :sheetId")
    void deleteBySheetId(UUID sheetId);
}
