package com.its.api.its.repository.vms;

import com.its.api.its.model.entity.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 where p.vmsTypeCd = :vmsTypeCd")
    List<TbVmsSymbLib> findAllSymbolImage(@Param("vmsTypeCd") String vmsTypeCd);

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

}
