package com.izouma.zhirongip.repo;

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

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

    List<Navigation> findAllByType(NavType type);

    List<Navigation> findAllByParent(Long parent);
}