package com.izouma.nineth.repo;

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

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

    @Query("update Showroom t set t.likes = t.likes + ?2 where t.id = ?1")
    @Modifying
    @Transactional
    void addLike(Long id, int num);

    Optional<Showroom> findByUserIdAndAssetId(Long userId, Long assetId);

    Optional<Showroom> findByAssetId(Long assetId);

    @Query("update Showroom t set t.share = t.share + ?2 where t.id = ?1")
    @Modifying
    @Transactional
    void addShare(Long id, int num);
}