package br.gov.sigefp.rh.repository;

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

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Repository
public interface MonthlyAttendanceSheetRepository extends JpaRepository<MonthlyAttendanceSheet, UUID> {

    Optional<MonthlyAttendanceSheet> findByOrgUnitIdAndMonthAndYear(UUID orgUnitId, Integer month, Integer year);

    List<MonthlyAttendanceSheet> findByMonthAndYear(Integer month, Integer year);

    List<MonthlyAttendanceSheet> findByStatus(AttendanceSheetStatus status);

    @Query("SELECT s FROM MonthlyAttendanceSheet s WHERE s.orgUnitId = :orgUnitId ORDER BY s.year DESC, s.month DESC")
    List<MonthlyAttendanceSheet> findByOrgUnitId(UUID orgUnitId);
}
