package br.gov.sigefp.budget.repository;

import br.gov.sigefp.budget.domain.FiscalYear;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

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

@Repository
public interface FiscalYearRepository extends JpaRepository<FiscalYear, UUID> {
    
    Optional<FiscalYear> findByYear(Integer year);
    
    boolean existsByYear(Integer year);
    
    @Query("SELECT fy FROM FiscalYear fy WHERE fy.status = 'OPEN' ORDER BY fy.year DESC")
    Optional<FiscalYear> findCurrentFiscalYear();
}

