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_PricingClaseDAO;
import com.rjconsultores.ventaboletos.entidad.ClaseServicio;
import com.rjconsultores.ventaboletos.entidad.GP_Pricing;
import com.rjconsultores.ventaboletos.entidad.GP_PricingClase;

@Repository("gp_pricingClaseDAO")
public class GP_PricingClaseHibernateDAO extends GenericHibernateDAO<GP_PricingClase, Integer>
		implements GP_PricingClaseDAO {

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

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

		return c.list();
	}

	public Boolean obtenerPricingClase(GP_Pricing pricing, ClaseServicio claseServicio) {
		Criteria c = getSession().createCriteria(getPersistentClass());
		c.add(Restrictions.eq(ACTIVO, GP_Pricing.ATIVO));
		c.add(Restrictions.eq("pricing", pricing));
		c.add(Restrictions.eq("claseServicio", claseServicio));

		if (c.list().size() > 0) {
			return true;
		} else {
			return false;
		}
	}

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

		return c.list();
	}
	
	
}
