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_PricingCorridaDAO;
import com.rjconsultores.ventaboletos.entidad.CorridaCtrl;
import com.rjconsultores.ventaboletos.entidad.GP_Pricing;
import com.rjconsultores.ventaboletos.entidad.GP_PricingCorrida;

@Repository("gp_pricingCorridaDAO")
public class GP_PricingCorridaHibernateDAO extends GenericHibernateDAO<GP_PricingCorrida, Integer>
		implements GP_PricingCorridaDAO {

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

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

		return c.list();
	}

	public Boolean obtenerPricingCorrida(GP_Pricing pricing, CorridaCtrl corrida) {
		Criteria c = getSession().createCriteria(getPersistentClass());
		c.add(Restrictions.eq(ACTIVO, GP_Pricing.ATIVO));
		c.add(Restrictions.eq("pricing", pricing));
		c.add(Restrictions.eq("corridaCtrl", corrida));

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

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

		return c.list();
	}
}
