package com.izouma.nineth.repo.rewardpoints;

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

import javax.transaction.Transactional;
import java.util.List;

public interface PointActivityAwardRepo extends JpaRepository<PointActivityAward, Long>, JpaSpecificationExecutor<PointActivityAward> {
    /**
     *
     * @param id
     * @return
     */
    @Query("select u from PointActivityAward u where u.activityId = ?1 and u.del = false order by u.orderNum ")
    List<PointActivityAward> selectByActivityId(Long id);

    @Query("update PointActivityAward t set t.stock = t.stock - ?2 where t.id = ?1 ")
    @Modifying
    @Transactional
    void decreaseStock(Long id, int num);

    @Query("update PointActivityAward t set t.del = true where t.id = ?1 ")
    @Modifying
    @Transactional
    void softDelByActivityId(Long activityId);
}
