package com.its.api.its.repository.road;

import com.its.api.its.model.entity.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")
    List<TbRoadTraf> findAll();

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

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

}
