package com.its.api.its.repository.ifsc;

import com.its.api.its.model.entity.ifsc.TbIfscLinkRltn;
import com.its.api.its.model.entity.ifsc.TbIfscLinkRltnKey;
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<TbIfscLinkRltn, TbIfscLinkRltnKey>, JpaSpecificationExecutor<TbIfscLinkRltn> {

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

    @Query(value = "select p.ifscId from TbIfscLinkRltn p where p.linkId = :linkId")
    List<Long> findIfscIdByLinkId(@org.springframework.data.repository.query.Param("linkId") Long linkId);

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