package com.its.api.its.repository.link;

import com.its.api.its.model.entity.link.TbLink;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

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 inner join fetch p.toNode")
    List<TbLink> findAll();

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

    @Query("select p from TbLink p inner join fetch p.fromNode inner join fetch p.toNode 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();

}
