package com.izouma.dingdong.repo;


import com.izouma.dingdong.domain.OrderRefundApply;
import com.izouma.dingdong.enums.RefundStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;

public interface OrderRefundApplyRepo extends JpaRepository<OrderRefundApply, Long>, JpaSpecificationExecutor<OrderRefundApply> {

    Optional<OrderRefundApply> findByOrderIdAndStatus(Long orderId, RefundStatus status);

    //商家退款申请
    List<OrderRefundApply> findAllByMerchantId(Long merchantId);

    //显示上报退款申请
    List<OrderRefundApply> findAllByReportIsTrue();

    @Query("update OrderRefundApply t set t.enabled = false where t.id = ?1")
    @Modifying
    @Transactional
    void deleteById(Long id);

    OrderRefundApply findByOrderId(Long orderId);
}