package com.crm.ucard.dao.repository;

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

import javax.persistence.LockModeType;
import java.util.List;

@Repository
public interface CardMerchantUserRepository extends BaseRepository<CardMerchantUserTable> {

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardMerchantUserTable findByUniqueId(String uniqueId);

    CardMerchantUserTable getByUniqueId(String uniqueId);

    CardMerchantUserTable getByEmailAndCardCategory(String email, Integer cardCategory);

    CardMerchantUserTable getByMobileAndCardCategory(String mobile, Integer cardCategory);

    CardMerchantUserTable findByCId(Long cId);

    CardMerchantUserTable findByCIdAndCardCategory(Long cId, Integer cardCategory);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardMerchantUserTable findFirstByCustomIdAndCardCategory(Long customId, Integer cardCategory);

    CardMerchantUserTable getFirstByCustomId(Long customId);
    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardMerchantUserTable findFirstByCustomId(Long customId);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CardMerchantUserTable findFirstById(Long cardId);

    /**
     * 查询邮箱是否已存在
     */
    boolean existsByEmail(String email);

    List<CardMerchantUserTable> findAllByAuthStatus(Integer authStatus);
}
