package com.loan.system.repository;

import com.loan.system.domain.entity.ApprovalRecord;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface ApprovalRepository extends JpaRepository<ApprovalRecord,Long> {
    List<ApprovalRecord> findByCaseIdAndIsDelete(Long id, Boolean isDelete);

    ApprovalRecord findByCaseIdAndIsDeleteAndStepNameAndApproverId(Long caseId, Boolean isDelete, String stepName,Long approverId);

    @Modifying
    @Transactional
    @Query(value = "UPDATE approval_record SET decision = ?1, update_time = ?5, comments = ?6 WHERE case_id = ?2 AND step_name = ?3 AND is_delete = ?4 AND approver_id = ?7", nativeQuery = true)
    void updateDecisionByCaseIdAndStepNameAndIsDeleteAndApproverId(String decision, Long caseId, String stepName, Boolean isDelete,String updateTime,String  comments, Long approverId);

}
