package com.its.api.its.repository.atrd;

import com.its.api.its.model.entity.atrd.TbAtrdRoadRltn;
import com.its.api.its.model.entity.atrd.TbAtrdRoadRltnKey;
import org.springframework.data.repository.query.Param;
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.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface TbAtrdRoadRltnRepository extends JpaRepository<TbAtrdRoadRltn, TbAtrdRoadRltnKey>, JpaSpecificationExecutor<TbAtrdRoadRltn> {

    //@Query(value = "select p from TbAtrdRoadRltn p inner join fetch p.road m inner join fetch m.fromNode inner join fetch m.toNode where p.atrdId = :atrdId")
    @Query(value = "select p from TbAtrdRoadRltn p inner join fetch p.road m where p.atrdId = :atrdId")
    List<TbAtrdRoadRltn> findRoadRltnById(@Param("atrdId") String atrdId);

    @Transactional
    @Modifying
    @Query("delete from TbAtrdRoadRltn p where p.atrdId = :atrdId")
    void deleteDataById(@Param("atrdId") String atrdId);

}
