/*
 * 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.MotivoDevolucaoBilheteDAO;
import com.rjconsultores.ventaboletos.entidad.MotivoDevolucaoBilhete;
import java.util.List;
import org.hibernate.Criteria;
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 Bruno Neves
 */
@Repository("motivoDevolucaoBilheteDAO")
public class MotivoDevolucaoBilheteHibernateDAO extends GenericHibernateDAO<MotivoDevolucaoBilhete, Integer>
        implements MotivoDevolucaoBilheteDAO {

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

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

        return c.list();
    }

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

        return c.list();
    }

    public List<MotivoDevolucaoBilhete> obtenerTodosTipoMotivoB() {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
        c.addOrder(Order.asc("descmotivo"));

        return c.list();
    }

    public List<MotivoDevolucaoBilhete> obtenerTodosEspecificos(Integer[] motivos) {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
        c.add(Restrictions.in("motivodevolucaobilheteId", motivos));
        c.addOrder(Order.asc("descmotivo"));

        return c.list();
    }
}
