package com.dacrt.SBIABackend.repository;

import java.util.Optional;

import javax.transaction.Transactional;

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 com.dacrt.SBIABackend.entity.Instrumentriskfactors;
import com.dacrt.SBIABackend.entity.Instruments;

public interface InstrumentriskfactorsRepository extends JpaRepository<Instrumentriskfactors,Integer>,JpaSpecificationExecutor<Instrumentriskfactors>{

	@Transactional
	@Modifying
	@Query(" DELETE FROM Instrumentriskfactors e where e.instrumentid = ?1 ")
	void deleteInstrumentriskfactorsbyid(Integer id);
	
	@Transactional
	@Modifying
	@Query(" DELETE FROM Instrumentriskfactors e where e.instrumentid = ?1 and e.riskfactorid= ?2")
	void deleteInstrumentrosFactores(Integer idIntrumento, Integer idFactor);
	
	@Query(" SELECT count(id) FROM Instrumentriskfactors e where e.instrumentid = ?1 and e.riskfactorid= ?2")
	int existeInstrumentrosFactores(Integer idIntrumento, Integer idFactor);
	
	@Query(" SELECT e FROM Instrumentriskfactors e where e.instrumentid = ?1 and e.riskfactorid= ?2")
	Optional<Instrumentriskfactors> findInstrumeFactores(Integer idIntrumento, Integer idFactor);
}
