package it.enea.cruise.service.data;

import java.util.Date;
import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import it.enea.cruise.model.data.DataConsumption;

public interface DataInterface extends JpaRepository<DataConsumption, Long> {

	@Query("SELECT dc FROM dataConsumption dc "
			+ "WHERE dc.userid = :userid "
			+ "AND dc.timestamp >= :startDate "
			+ "AND dc.timestamp < :endDate "
			+ "AND dc.communityid = :communityid "
			+ "ORDER BY dc.timestamp ASC")
	List<DataConsumption> findAllByUserIdAndStartDateAndEndDate(
			@Param(value = "userid") Long userid,
			@Param(value = "startDate") Date startDate, 
			@Param(value = "endDate") Date endDate,
			@Param(value = "communityid") Integer communityId);

	@Query(value = "SELECT * from vw_counterreadingusers "
			+ "WHERE userid = :userid LIMIT 100"
			//+ "AND timestamp >= :startDate "
			//+ "AND timestamp < :endDate"
			, nativeQuery = true)
	List<Object> findAllByUserIdAndStartDateAndEndDateNative(
			@Param(value = "userid") Long userid
			//,
			//@Param(value = "startDate") Date startDate, 
			//@Param(value = "endDate") Date endDate
			);
	
	List<DataConsumption> findAllByUserid(Long userid);
	
	List<DataConsumption> findAll();
	
	long count();

}
