package com.rjconsultores.ventaboletos.dao.hibernate;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
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.OrgaoCancelacionDAO;
import com.rjconsultores.ventaboletos.entidad.OrgaoCancelacion;
import com.rjconsultores.ventaboletos.entidad.OrgaoConcedente;

@Repository("orgaoCancelacionDAO")
public class OrgaoCancelacionHibernateDAO extends GenericHibernateDAO<OrgaoCancelacion, Integer> implements OrgaoCancelacionDAO {

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

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

        return c.list();
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public List<Integer> obtenerTodosIds() {
    	Criteria c = getSession().createCriteria(getPersistentClass());
    	c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
    	c.setProjection(Projections.property("orgaoCancelacionId"));
    	
    	return c.list();
    }

    @SuppressWarnings("unchecked")
    @Override
    public List<OrgaoCancelacion> buscarPorOrgao(OrgaoConcedente orgaoConcedente) {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.like("orgao", orgaoConcedente));
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));

        return c.list();
    }
    
}
