package com.rjconsultores.ventaboletos.dao.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
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_PricingClasseTarifariaDAO;
import com.rjconsultores.ventaboletos.entidad.GP_PricingClasseTarifaria;

@Repository("gp_pricingClasseTarifariaDAO")
public class GP_PricingClasseTarifariaHibernateDAO extends GenericHibernateDAO<GP_PricingClasseTarifaria, Integer>
		implements GP_PricingClasseTarifariaDAO {

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

	@SuppressWarnings("unchecked")
	@Override
	public List<GP_PricingClasseTarifaria> obtenerTodos() {
		Criteria c = getSession().createCriteria(getPersistentClass());
		c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));

		return c.list();
	}

	public Boolean validacionSigla(String sigla) {

		StringBuffer hql = new StringBuffer();
		hql.append("   FROM GP_PricingClasseTarifaria pct ");
		hql.append("   WHERE pct.sigla = :sigla ");
		hql.append("         AND pct.activo = :activo ");

		Query query = getSession().createQuery(hql.toString());
		query.setParameter("activo", Boolean.TRUE);
		query.setParameter("sigla", sigla);

		if (query.list().isEmpty())
			return true;
		else
			return false;
	}

}
