package com.izouma.dingdong.repo.backstage;

import com.izouma.dingdong.domain.backstage.Priority;
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;

public interface PriorityRepo extends JpaRepository<Priority, Long>, JpaSpecificationExecutor<Priority> {
    @Query("update Priority t set t.enabled = false where t.id = ?1")
    @Modifying
    @Transactional
    void deleteById(Long id);

//    List<Priority> findAllByTypeOrderByLevel(Integer type);

    Priority findByTypeAndLevel(Integer type, Integer level);

    @Query("select max(p.level) from Priority p where p.type = ?1")
    Integer findByTypeAndLevelMax(Integer type);

}