package es.uv.saic.domain;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;


@Repository
public interface PlantillaRepository extends JpaRepository<Plantilla, Integer> {

	Plantilla findByIdPlantilla(Integer idPlantilla);
	
	@Query(value=("SELECT * FROM plantilles WHERE "
			+ "id_plantilla IN(SELECT CAST(codi_evidencia AS INTEGER) FROM tasques WHERE tipus = 11 AND codi_evidencia IS NOT NULL) "
			+ "AND id_plantilla = ?1"), nativeQuery=true)
	List<Plantilla> findUsedByIdPlantilla(Integer idPlantilla);
	
	@Query(value=("SELECT * FROM plantilles WHERE "
			+ "versio = ?1 AND codi = ?2 AND ambit = ?3"), nativeQuery=true)
	Plantilla findByVersioCodiAmbit(Integer versio, String codi, String ambit);
	
}