package com.its.api.its.repository.cctv;

import com.its.api.its.model.entity.cctv.TbCctvScnr;
import com.its.api.its.model.entity.cctv.TbCctvScnrKey;
import org.springframework.data.repository.query.Param;
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.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface TbCctvScnrRepository extends JpaRepository<TbCctvScnr, TbCctvScnrKey>, JpaSpecificationExecutor<TbCctvScnr> {

    @Query("select p from TbCctvScnr p inner join fetch p.cctv cctv inner join fetch p.pset pset left outer join fetch cctv.state state where cctv.delYn = 'N'")
    List<TbCctvScnr> findAllList();

    @Transactional
    @Modifying
    @Query(value="update tb_cctv_scnr " +
                 "   set ctrl_dt     = :ctrlDt, " +
                 "       ctrl_res_yn = :ctrlResYn " +
                 " where cctv_mngm_nmbr = :nmbr " +
                 "   and strt_hms       = :strtHms " +
                 "   and end_hms        = :endHms", nativeQuery = true)
    Integer updateResult(@Param("nmbr") Long nmbr, @Param("strtHms") String strtHms, @Param("endHms") String endHms, @Param("ctrlDt") String ctrlDt, @Param("ctrlResYn") String ctrlResYn);
}
