package com.izouma.nineth.repo.rewardpoints;

import com.izouma.nineth.domain.UserIntegralChangeLog;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

public interface UserIntegralChangeLogRepo  extends JpaRepository<UserIntegralChangeLog, Long>, JpaSpecificationExecutor<UserIntegralChangeLog> {

    @Query("select sum(uic.integral) from UserIntegralChangeLog uic where uic.userId = ?1 ")
    Long totalAvailableIntegral(Long userId);

    @Query("select sum(abs(uic.integral)) from UserIntegralChangeLog uic where uic.userId = ?1 and uic.flag = com.izouma.nineth.enums.IntegralFlag.DEBIT")
    Long totalConsumeIntegral(Long userId);

}
