package com.crm.ucard.dao.repository;

import com.crm.rely.backend.core.pojo.table.ucard.CardApplyTable;
import com.crm.rely.backend.dao.repository.BaseRepository;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.stereotype.Repository;

import javax.persistence.LockModeType;

@Repository
public interface CardApplyRepository extends BaseRepository<CardApplyTable> {

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardApplyTable findByOrderNo(String orderNo);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardApplyTable findFirstById(Long id);

    CardApplyTable getByOrderNo(String orderNo);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardApplyTable getByCardNo(String cardNo);

    CardApplyTable getByMerchantOrderNo(String cardMerchantOrderNo);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardApplyTable findFirstByHolderMerchantOrderNoOrderByAddTimeDesc(String holderMerchantOrderNo);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardApplyTable getBySerial(String serial);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardApplyTable getByRefundSerial(String refundSerial);

    CardApplyTable getFirstByUniqueIdAndCardTypeIdAndHolderStatus(String uniqueId, Integer cardTypeId, String holderStatus);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardApplyTable getByCardNoAndStatus(String cardNo, String status);
}
