package com.its.op.dao.repository.its.vms;

import com.its.op.entity.its.vms.TbVmsSymbLib;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TbVmsSymbLibRepository extends JpaRepository<TbVmsSymbLib, Integer>, JpaSpecificationExecutor<TbVmsSymbLib> {

    @Query("SELECT p from TbVmsSymbLib p order by p.symbLibNmbr")
    List<TbVmsSymbLib> findAll();

    @Query("SELECT p from TbVmsSymbLib p where p.symbType = :symbType order by p.symbLibNmbr")
    List<TbVmsSymbLib> findAllSymbolImage(@Param("symbType") String symbType);

    @Query(value = "SELECT NVL(MAX(SYMB_LIB_NMBR), :minVal-1)+1 AS NEWID FROM TB_VMS_SYMB_LIB WHERE SYMB_LIB_NMBR BETWEEN :minVal AND :maxVal", nativeQuery = true)
    Integer getNewSymbolId(@Param("minVal") Integer minVal, @Param("maxVal") Integer maxVal);

}
