/*
 * 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.SecretariaDAO;
import com.rjconsultores.ventaboletos.entidad.Secretaria;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.MatchMode;
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 Administrador
 */
@Repository("secretariaDAO")
public class SecretariaHibernateDAO extends GenericHibernateDAO<Secretaria, Integer>
        implements SecretariaDAO {

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

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

        return c.list();
    }

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

        c.add(Restrictions.eq("descsecretaria", descsecretaria));
        c.add(Restrictions.eq("cvesecretaria", cvesecretaria));

        return c.list();
    }

    public List<Secretaria> buscar(String descsecretaria) {
        Criteria c = getSession().createCriteria(getPersistentClass());

        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
        c.add(Restrictions.eq("descsecretaria", descsecretaria));

        return c.list();
    }

	@Override
	public Secretaria buscarSecretariaVoucherRod(Short formaPagoId) {
		Criteria c = getSession().createCriteria(getPersistentClass());

        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
        c.add(Restrictions.eq("indVoucherRod", Boolean.TRUE));
        c.add(Restrictions.eq("formaPago.formapagoId", formaPagoId));

        List<Secretaria> result = c.list();
        return result.isEmpty() ? null : (Secretaria)result.get(0);
	}

	@Override
	public List<Secretaria> buscaLike(String descsecretaria) {
		Criteria c = getSession().createCriteria(getPersistentClass());

		c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
		c.add(Restrictions.like("descsecretaria", descsecretaria, MatchMode.START));

		return c.list();
	}
}
