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

import com.its.op.entity.its.road.TbRoadRltnIfsc;
import com.its.op.entity.its.road.TbRoadRltnIfscKey;
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.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface TbRoadIfscRltnRepository extends JpaRepository<TbRoadRltnIfsc, TbRoadRltnIfscKey>, JpaSpecificationExecutor<TbRoadRltnIfsc> {

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

    @Query("select p from TbRoadRltnIfsc p inner join fetch p.ifsc m inner join fetch m.fromNode fnode inner join fetch m.toNode tnode where p.roadId = :roadId")
    List<TbRoadRltnIfsc> findIfscRltnById(@Param("roadId") Long roadId);

    @Transactional
    @Modifying
    @Query("delete from TbRoadRltnIfsc p where p.roadId = :roadId")
    void deleteDataById(@Param("roadId") Long roadId);
}
