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

import com.its.op.entity.its.link.TbLink;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.springframework.data.jpa.repository.*;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.QueryHint;
import java.util.List;

@Repository
public interface TbLinkRepository extends JpaRepository<TbLink, Long> , JpaSpecificationExecutor<TbLink> {

    @Query("select p from TbLink p inner join fetch p.fromNode fnode inner join fetch p.toNode tnode")
    List<TbLink> findAll();

    @Query("select distinct p from TbLink p inner join fetch p.fromNode fnode inner join fetch p.toNode tnode where p.delYn = 'N'")
    List<TbLink> findAllList();

    @Query("select p from TbLink p inner join fetch p.fromNode fnode inner join fetch p.toNode tnode where p.delYn = 'N' and p.roadName is not null and p.roadName <> '-' and p.areaCd = 'LAT001'")
    List<TbLink> findLocalRoadLinkAll();

    @Query("select count(p.linkId) from TbLink p where p.delYn = 'N'")
    Integer findAllCount();

    @Modifying
    @Query("update TbLink p set p.paraId = :paraId")
    Integer updateParamAll(@Param("paraId") Long paraId);

    @Modifying
    @Query("update TbLink p set p.paraId = :paraId where p.linkId in :linkIds")
    Integer updateParamIds(@Param("paraId") Long paramId, @Param("linkIds") List<Long> linkIds);

}
