package com.crm.globex.dao.repository;

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

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

/**
 * @author: houn
 */
@Repository
public interface CustomLoginFirmOfferRepository extends BaseRepository<CustomLoginFirmOfferTable> {

    boolean existsByLogin(Long login);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CustomLoginFirmOfferTable findFirstByLogin(Long login);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CustomLoginFirmOfferTable findFirstByLoginStatus(Integer loginStatus);

    CustomLoginFirmOfferTable getFirstByCustomIdAndLogin(Long customId, Long login);

    boolean existsByCustomIdAndLogin(Long customId, Long login);

    @Lock(LockModeType.PESSIMISTIC_WRITE)
    CustomLoginFirmOfferTable findFirstByLoginStatusAndValidAndExpirationTimeLessThanAndExpirationTimeIsNotNull(Integer loginStatus, Integer valid, Date time);
}
