package com.its.api.its.repository.vms;

import com.its.api.its.model.entity.vms.TbVmsCmtrInfr;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
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 TbVmsCmtrInfrRepository extends JpaRepository<TbVmsCmtrInfr, Long>, JpaSpecificationExecutor<TbVmsCmtrInfr> {

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

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

}
