package com.izouma.nineth.repo;

import com.izouma.nineth.domain.ShowCollection;
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 javax.validation.constraints.NotNull;
import java.util.Collection;
import java.util.List;

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

    @Query("update ShowCollection t set t.del = true where t.collectionId = ?1")
    @Modifying
    @Transactional
    void softDeleteCollection(Long collectionId);

    @Transactional
    @Modifying
    void deleteAllByCollectionId(@NotNull Long collectionId);

    List<ShowCollection> findAllByShowroomId(Long showroomId);

    List<ShowCollection> findAllByShowroomIdOrderBySort(Long showroomId);

    List<ShowCollection> findAllByShowroomIdIn(Collection<Long> showroomId);

    @Transactional
    @Modifying
    void deleteAllByShowroomId(@NotNull Long showroomId);

    @Transactional
    @Modifying
    void deleteAllByIdIn(Collection<Long> ids);

}