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

import com.its.op.entity.its.vms.TbVmsIfscTraf;
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 TbVmsIfscTrafRepository extends JpaRepository<TbVmsIfscTraf, Long>, JpaSpecificationExecutor<TbVmsIfscTraf> {

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

    @Query("select p from TbVmsIfscTraf p inner join fetch p.vmsIfsc ifsc " +
           " where p.vmsIfscId in (select s.vmsIfscId from TbVmsRltnIfsc s where s.vmsCtlrNmbr = :vmsCtlrNmbr)")
    List<TbVmsIfscTraf> findAllByVms(@Param("vmsCtlrNmbr") Long vmsCtlrNmbr);

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

}
