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

import com.its.op.entity.its.vms.TbVmsIfscRltnIfsc;
import com.its.op.entity.its.vms.TbVmsIfscRltnIfscKey;
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 java.util.List;

@Repository
public interface TbVmsIfscRltnIfscRepository extends JpaRepository<TbVmsIfscRltnIfsc, TbVmsIfscRltnIfscKey>, JpaSpecificationExecutor<TbVmsIfscRltnIfsc> {

    @Query("select p from TbVmsIfscRltnIfsc p inner join fetch p.ifsc ifsc")
    List<TbVmsIfscRltnIfsc> findAll();

    @Query("select p from TbVmsIfscRltnIfsc p inner join fetch p.ifsc ifsc")
    List<TbVmsIfscRltnIfsc> findDataAll();

    @Query("select p from TbVmsIfscRltnIfsc p inner join fetch p.ifsc where p.vmsIfscId = :vmsIfscId")
    List<TbVmsIfscRltnIfsc> findDataById(@Param("vmsIfscId") Long vmsIfscId);

    @Query("select count(p.vmsIfscId) from TbVmsIfscRltnIfsc p where p.vmsIfscId = :vmsIfscId")
    Integer findUsageCountByVmsIfscId(@Param("vmsIfscId") Long vmsIfscId);

    @Modifying
    @Query("delete from TbVmsIfscRltnIfsc p where p.vmsIfscId = :vmsIfscId")
    void deleteDataById(@Param("vmsIfscId") Long vmsIfscId);

    @Query(value = "select p.vmsIfscId from TbVmsIfscRltnIfsc p where p.ifscId in :ids")
    List<Long> findVmsIfscIdByIfscId(@Param("ids") List<Long> ids);

}
