package com.izouma.wenlvju.repo;

import com.izouma.wenlvju.domain.Setting;
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.Collection;
import java.util.List;
import java.util.Optional;

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

    @Query(nativeQuery = true, value = "SELECT ifnull(max(flag + 1),1) FROM setting")
    int nextSort();

    List<Setting> findAllByFlag(int flag);

    Optional<Setting> findByNameLikeAndFlag(String name, int flag);

    List<Setting> findAllByFlagIn(Collection<Integer> ids);
}