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

import com.its.api.its.model.entity.vms.TbVmsMonitoring;
import com.its.api.its.model.entity.vms.TbVmsMonitoringKey;
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 org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface TbVmsMonitoringRepository extends JpaRepository<TbVmsMonitoring, TbVmsMonitoringKey>, JpaSpecificationExecutor<TbVmsMonitoring> {

    @Query("select p from TbVmsMonitoring p inner join fetch p.vms where p.monitoringType = :monitoringType")
    List<TbVmsMonitoring> findAllMonitoring(@Param("monitoringType") Integer monitoringType);

    @Query("select p from TbVmsMonitoring p inner join fetch p.vms")
    List<TbVmsMonitoring> findAll();

    @Query("select p from TbVmsMonitoring p inner join fetch p.vms where p.monitoringType = :monitoringType and p.monitoringNm = :monitoringNm")
    List<TbVmsMonitoring> findByName(@Param("monitoringType") Integer monitoringType, @Param("monitoringNm") String monitoringNm);

    @Transactional
    @Modifying // select 문이 아님을 나타낸다
    @Query("delete from TbVmsMonitoring p where p.monitoringType = :monitoringType and p.monitoringNm = :monitoringNm")
    void deleteByName(@Param("monitoringType") Integer monitoringType, @Param("monitoringNm") String monitoringNm);

/*
    @Transactional
    @Modifying // select 문이 아님을 나타낸다
    @Query(value = "insert into TB_VMS_MONITORING m values(:mtype, :name, :seq, :nmbr)", nativeQuery = true)
    void insertValue(Integer mtype, String name, Integer seq, Long nmbr);
*/

}
