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

import com.its.op.entity.its.ifsc.TbIfscRltnLink;
import com.its.op.entity.its.ifsc.TbIfscRltnLinkKey;
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 TbIfscLinkRltnRepository extends JpaRepository<TbIfscRltnLink, TbIfscRltnLinkKey>, JpaSpecificationExecutor<TbIfscRltnLink> {

    @Query(value = "select p from TbIfscRltnLink p inner join fetch p.link m inner join fetch m.fromNode inner join fetch m.toNode")
    List<TbIfscRltnLink> findAll();

    @Query(value = "select p from TbIfscRltnLink p inner join fetch p.link m inner join fetch m.fromNode inner join fetch m.toNode where p.ifscId = :ifscId")
    List<TbIfscRltnLink> findLinkRltnById(@Param("ifscId") Long ifscId);

    @Query(value = "select p.ifscId from TbIfscRltnLink p where p.linkId = :linkId")
    List<Long> findIfscIdByLinkId(@Param("linkId") Long linkId);

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