package com.rjconsultores.ventaboletos.dao.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
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.GP_PricingAsientoDAO;
import com.rjconsultores.ventaboletos.entidad.GP_Pricing;
import com.rjconsultores.ventaboletos.entidad.GP_PricingAsiento;
import com.rjconsultores.ventaboletos.entidad.Pricing;

@Repository("gp_pricingAsientoDAO")
public class GP_PricingAsientoHibernateDAO extends GenericHibernateDAO<GP_PricingAsiento, Integer>
		implements GP_PricingAsientoDAO {

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

	@Override
	public List<GP_PricingAsiento> obtenerTodos() {
		Criteria c = getSession().createCriteria(getPersistentClass());
		c.add(Restrictions.eq(ACTIVO, Pricing.ATIVO));

		return c.list();
	}

	public List<GP_PricingAsiento> obtenerPricingCategoria(GP_Pricing pricing, Integer asiento) {
		Criteria c = getSession().createCriteria(getPersistentClass());
		c.add(Restrictions.eq(ACTIVO, Pricing.ATIVO));
		c.add(Restrictions.eq("pricing", pricing));
		c.add(Restrictions.eq("numeasiento", asiento.toString()));

		return c.list();
	}

	@Override
	public List<GP_PricingAsiento> obtenerTodoPorPricing(GP_Pricing pricing) {
		Criteria c = getSession().createCriteria(getPersistentClass());
		c.add(Restrictions.eq("pricing.pricingId", pricing.getPricingId()));

		return c.list();
	}
}
