/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.dao.hibernate;

import com.rjconsultores.ventaboletos.dao.TipoVentaDAO;
import com.rjconsultores.ventaboletos.entidad.TipoVenta;
import com.rjconsultores.ventaboletos.vo.segurida.PerfilJerarquia;

import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

/**
 *
 * @author Rafius
 */
@Repository("tipoVentaDAO")
public class TipoVentaHibernateDAO extends GenericHibernateDAO<TipoVenta, Integer>
        implements TipoVentaDAO {

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

    @Override
    public List<TipoVenta> obtenerTodos() {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
        c.addOrder(Order.asc("desctipoventa"));

        return c.list();
    }

    public List<TipoVenta> buscar(String desctipoventa) {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
        c.add(Restrictions.eq("desctipoventa", desctipoventa));

        return c.list();
    }

    public TipoVenta obtenerID(Short tipoventaId) {
        Criteria c = getSession().createCriteria(getPersistentClass());

        c.add(Restrictions.eq("tipoventaId", tipoventaId));

        return (TipoVenta) c.uniqueResult();
    }
    
	@SuppressWarnings("unchecked")
	public List<TipoVenta> obterTiposVentaIntegracao() {
		StringBuilder sb = new StringBuilder();
		sb.append(" from TipoVenta x ");
		sb.append(" where x.activo = 1 and x.tipoventaId in (1,12,99)");
		sb.append(" order by x.desctipoventa ");

		Query query = getSession().createQuery(sb.toString());

		return query.list();
    }
}
