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

import com.its.op.entity.its.road.TbRoadTraf;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
public interface TbRoadTrafRepository extends JpaRepository<TbRoadTraf, Long>, JpaSpecificationExecutor<TbRoadTraf> {

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

    @Query("select p from TbRoadTraf p")
    List<TbRoadTraf> findAllTraf();

    @Query("select p from TbRoadTraf p inner join fetch p.road road inner join fetch road.fromNode fnode inner join fetch road.toNode tnode where p.roadId = :roadId")
    Optional<TbRoadTraf> findById(@Param("roadId") Long roadId);

}
