package com.crm.manager.dao.repository;

import com.crm.rely.backend.dao.repository.BaseRepository;
import com.crm.rely.backend.model.pojo.table.MarketEmailRecordTable;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

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

/**
 * @author: houn
 */
@Repository
public interface MarketEmailRecordRepository extends BaseRepository<MarketEmailRecordTable> {

    MarketEmailRecordTable getFirstById(Long id);

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

    List<MarketEmailRecordTable> findAllByEmailIdAndStatus(Long emailId, Integer status);

    List<MarketEmailRecordTable> findAllByEmailIdAndStatusAndIdIn(Long emailId, Integer status, List<Long> ids);

    List<MarketEmailRecordTable> getAllByEmailIdAndStatus(Long emailId, Integer status);

    @Query(value = "select * from market_email_record where status=?1 limit ?2", nativeQuery = true)
    List<MarketEmailRecordTable> selectLimitByStatus(Integer status, Integer limit);
}
