package com.rjconsultores.ventaboletos.dao.hibernate;

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

import javax.sql.DataSource;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.rjconsultores.ventaboletos.dao.LogDespesaReceitaDivDAO;
import com.rjconsultores.ventaboletos.entidad.LogDespesaReceitaDiversa;

@Repository("logDespesaReceitaDivDAO")
public class LogDespesaReceitaDivHibernateDAO extends GenericHibernateDAO<LogDespesaReceitaDiversa, Long> implements LogDespesaReceitaDivDAO {
	@Autowired
	private DataSource dataSource;

	@Autowired
	public LogDespesaReceitaDivHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
		setSessionFactory(factory);
	}

	@Override
	public List<LogDespesaReceitaDiversa> obtenerTodos() {
		Criteria c = getSession().createCriteria(getPersistentClass());
		c.addOrder(Order.desc("dataExecucao"));
		
		return (List<LogDespesaReceitaDiversa>) c.list();
	}

	
	public List<LogDespesaReceitaDiversa> obterPorPeriodo(Date inicio, Date fim){
		Criteria c = getSession().createCriteria(getPersistentClass());
		c.add(Restrictions.eq("dataInicio", inicio));
		c.add(Restrictions.eq("dataFim", fim));
		c.addOrder(Order.desc("dataExecucao"));
		
		return (List<LogDespesaReceitaDiversa>) c.list();
	}

	@Override
	public LogDespesaReceitaDiversa suscribir(LogDespesaReceitaDiversa entity) throws RuntimeException {

		entity = super.suscribir(entity);


		return entity;
	}

}
