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

import com.its.api.its.model.entity.road.TbRoadIfscRltn;
import com.its.api.its.model.entity.road.TbRoadIfscRltnKey;
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<TbRoadIfscRltn, TbRoadIfscRltnKey>, JpaSpecificationExecutor<TbRoadIfscRltn> {

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

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