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_PricingCategoriaDAO;
import com.rjconsultores.ventaboletos.entidad.Categoria;
import com.rjconsultores.ventaboletos.entidad.GP_Pricing;
import com.rjconsultores.ventaboletos.entidad.GP_PricingCategoria;

@Repository("gp_pricingCategoriaDAO")
public class GP_PricingCategoriaHibernateDAO extends GenericHibernateDAO<GP_PricingCategoria, Integer>
		implements GP_PricingCategoriaDAO {

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

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

		return c.list();
	}

	public Boolean obtenerPricingCategoria(GP_Pricing pricing, Categoria categoria) {
		Criteria c = getSession().createCriteria(getPersistentClass());
		c.add(Restrictions.eq(ACTIVO, GP_Pricing.ATIVO));
		c.add(Restrictions.eq("pricing", pricing));
		c.add(Restrictions.eq("categoria", categoria));

		if (c.list().size() > 0) {
			return true;
		} else {
			return false;
		}
	}
	
	@Override
	public List<GP_PricingCategoria> obtenerTodoPorPricing(GP_Pricing pricing) {
		Criteria c = getSession().createCriteria(getPersistentClass());
		c.add(Restrictions.eq("pricing.pricingId", pricing.getPricingId()));

		return c.list();
	}
}
