package com.rjconsultores.ventaboletos.dao.hibernate;

import java.util.List;

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.ReservaEspecialClienteDAO;
import com.rjconsultores.ventaboletos.entidad.ReservaEspecialCliente;

@Repository("reservaEspecialClienteDAO")
public class ReservaEspecialClienteHibernateDAO extends GenericHibernateDAO<ReservaEspecialCliente, Integer>
		implements ReservaEspecialClienteDAO {

	private static final String FIELD_ACTIVO = "activo";

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

	@Override
	public List<ReservaEspecialCliente> bucarReservaEspecialByClienteId(Long clienteId) {
		Criteria c = getCriteriaClienteActivo();
		c.add(Restrictions.eq("clienteId", clienteId));
		c.addOrder(Order.asc("reservaEspecialClienteId"));

		return c.list();
	}



	private Criteria getCriteriaClienteActivo() {
		Criteria criteria = getSession().createCriteria(getPersistentClass());
		criteria.add(Restrictions.eq(FIELD_ACTIVO, Boolean.TRUE));
		return criteria;
	}

	@Override
	public List<ReservaEspecialCliente> bucarReservaEspecialByCorridaId(Long corridaId) {
		Criteria c = getCriteriaClienteActivo();
		c.add(Restrictions.eq("corridaId", corridaId));
		c.addOrder(Order.asc("reservaEspecialClienteId"));
		return c.list();
	}
}
