package com.izouma.zhirongip.repo;

import com.izouma.zhirongip.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 javax.validation.constraints.Size;
import java.util.List;
import java.util.Map;

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);

    List<Setting> findAllByFlag(int flag);

    List<Setting> findAllByFlagIn(Iterable<Integer> flags);

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


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