package br.gov.sigefp.treasury.repository;

import br.gov.sigefp.treasury.domain.PaymentAuthorization;
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.util.List;
import java.util.UUID;

@Repository
public interface PaymentAuthorizationRepository extends JpaRepository<PaymentAuthorization, UUID> {
    
    List<PaymentAuthorization> findByPaymentOrderId(UUID paymentOrderId);
    
    List<PaymentAuthorization> findByPaymentBatchId(UUID paymentBatchId);
    
    List<PaymentAuthorization> findByStatus(String status);
    
    List<PaymentAuthorization> findByRequestedBy(UUID requestedBy);
    
    @Query("SELECT pa FROM PaymentAuthorization pa WHERE pa.status = 'PENDING' " +
           "AND pa.currentApprovalLevel <= :maxLevel")
    List<PaymentAuthorization> findPendingApprovals(@Param("maxLevel") Integer maxLevel);
    
    @Query("SELECT pa FROM PaymentAuthorization pa WHERE pa.status = 'PENDING' " +
           "AND pa.currentApprovalLevel = :level")
    List<PaymentAuthorization> findPendingByLevel(@Param("level") Integer level);
}
