package com.rjconsultores.ventaboletos.dao.hibernate;

import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.rjconsultores.ventaboletos.dao.PacoteDescontoBilheteDAO;
import com.rjconsultores.ventaboletos.entidad.PacoteDescontoBilhete;

@Repository("pacoteDescontoBilheteDAO")
public class PacoteDescontoBilheteHibernateDAO extends GenericHibernateDAO<PacoteDescontoBilhete, Long> implements PacoteDescontoBilheteDAO {
	
	private static Logger log = LogManager.getLogger(PacoteDescontoBilheteHibernateDAO.class);
	
	@Autowired
	public PacoteDescontoBilheteHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
		setSessionFactory(factory);
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<PacoteDescontoBilhete> obtenerTodos(Integer pacoteId) {
		StringBuilder sb = new StringBuilder();
		sb.append(" from PacoteDescontoBilhete pdb ");
		sb.append(" where pdb.pacote.pacoteId = :pacoteId ");
		sb.append("   and pdb.activo = 1 ");

		Query query = getSession().createQuery(sb.toString());
		query.setInteger("pacoteId", pacoteId);

		return query.list();
	}

}
