package es.uv.saic.domain;

import java.math.BigInteger;
import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface InstanciaTascaVerRepository extends JpaRepository<InstanciaTascaVer, InstanciaTascaVerPK> {


	@Query(value=("SELECT * FROM tasquesi_ver WHERE id_tascai = ?1 AND data_mod = ?2"), nativeQuery=true)
	public InstanciaTascaVer findById(BigInteger idInstanciaTasca, Date dataMod);

	@Query(value=("SELECT * FROM tasquesi_ver WHERE id_tascai = ?1 ORDER BY data_mod DESC"), nativeQuery=true)
	public List<InstanciaTascaVer> findByIdInstanciaTasca(BigInteger idInstanciaTasca);

	@Transactional
    @Modifying(flushAutomatically = true, clearAutomatically = true)
	@Query(value=("DELETE FROM tasquesi_ver WHERE id_tascai IN(SELECT id_tascai FROM tasquesi WHERE id_instancia = ?1)"), nativeQuery=true)
	public void deleteByIdInstancia(BigInteger idInstancia);

}
