package com.izouma.wenlvju.repo.performance;

import com.izouma.wenlvju.domain.performance.Arrange;
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 ArrangeRepo extends JpaRepository<Arrange, Long>, JpaSpecificationExecutor<Arrange> {
    @Query("update Arrange t set t.del = true where t.id = ?1")
    @Modifying
    @Transactional
    void softDelete(Long id);

    @Query("update Arrange t set t.quantity = t.quantity + 1 where t.id = ?1")
    @Modifying
    @Transactional
    void plusQuantity(Long id);

    @Query("update Arrange t set t.quantity = t.quantity - 1 where t.id = ?1")
    @Modifying
    @Transactional
    void minusQuantity(Long id);

    List<Arrange> findAllByPerformanceId(Long performanceId);

    Arrange findFirstByPerformanceId(Long performanceId);

    @Query("update Arrange t set t.publish = true where t.performanceId = ?1")
    @Modifying
    @Transactional
    void publish(Long performanceId);
}