package com.izouma.nineth.repo;

import com.izouma.nineth.domain.ActivitySurpriseBox;
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;

public interface ActivitySurpriseBoxRepo extends JpaRepository<ActivitySurpriseBox, Long>, JpaSpecificationExecutor<ActivitySurpriseBox> {
    @Query("update ActivitySurpriseBox t set t.del = true where t.id = ?1")
    @Modifying
    @Transactional
    void softDelete(Long id);


    @Query("update ActivitySurpriseBox t set t.grantCount = t.grantCount + ?2 ,  t.boxSum = t.boxSum -  ?2  where t.id = ?1")
    @Modifying
    @Transactional
    void decreaseStockAndIncreaseSale(Long id, Integer num );


}
