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

import com.its.api.its.model.entity.vms.TbVmsIfscCmtrGrad;
import com.its.api.its.model.entity.vms.TbVmsIfscCmtrGradKey;
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 org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface TbVmsIfscCmtrGradRepository extends JpaRepository<TbVmsIfscCmtrGrad, TbVmsIfscCmtrGradKey>, JpaSpecificationExecutor<TbVmsIfscCmtrGrad> {

    @Modifying
    @Query(value = "delete from TB_VMS_IFSC_CMTR_GRAD", nativeQuery = true)
    void deleteDataAll() throws Exception;

    @Modifying
    @Query("delete from TbVmsIfscCmtrGrad p where p.vmsIfscId = :vmsIfscId")
    void deleteDataById(@Param("vmsIfscId") Long vmsIfscId);

     @Query("select p from TbVmsIfscCmtrGrad p where p.vmsIfscId = :vmsIfscId")
     List<TbVmsIfscCmtrGrad> findDataById(@Param("vmsIfscId") Long vmsIfscId);

    @Modifying
    @Query(value =
            "insert into TB_VMS_IFSC_CMTR_GRAD(VMS_IFSC_ID, CMTR_GRAD_CD, LWSTSPED, HGHSSPED) select vms_ifsc_id, :cmtrGradCd, :lwstsped, :hghssped from TB_VMS_IFSC ",
            nativeQuery = true)
    void insertDataAll(@Param("cmtrGradCd") String cmtrGradCd, @Param("lwstsped") Integer lwstsped, @Param("hghssped") Integer hghssped);

}
