package com.izouma.awesomeAdmin.repo;

import com.izouma.awesomeAdmin.domain.Menu;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface MenuRepo extends JpaRepository<Menu, Long> {
    List<Menu> findByRootTrue();

    @Where(clause = "enabled = 1")
    List<Menu> findByNameAndRootTrue(String name);

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