package com.rjconsultores.ventaboletos.dao.hibernate;

import java.util.Date;
import java.util.List;

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.ConfRestricaoCanalVentaDAO;
import com.rjconsultores.ventaboletos.entidad.ConfRestricaoCanalVenta;

@Repository("confRestricaoCanalVentaDAO")
public class ConfRestricaoCanalVentaHibernateDAO extends GenericHibernateDAO<ConfRestricaoCanalVenta, Long> implements ConfRestricaoCanalVentaDAO {

	@Autowired
	public ConfRestricaoCanalVentaHibernateDAO(@Qualifier("sessionFactory") SessionFactory factory) {
		setSessionFactory(factory);
	}
	
	@Override
	public Boolean inativarListConfRestricaoCanalVenta(List<Integer> idsConfRestricaoCanalVenta, Integer usuarioId) {
		if(idsConfRestricaoCanalVenta.isEmpty()) {
			return false;
		}
		StringBuilder sb = new StringBuilder();
		sb.append(" UPDATE ConfRestricaoCanalVenta SET activo=0, ");
		sb.append(" usuarioId=:usuarioId, ");
		sb.append(" fecmodif=:data" );
		sb.append(" where confRestricaoCanalVentaId in (");
		sb.append(idsConfRestricaoCanalVenta.toString().substring(1, idsConfRestricaoCanalVenta.toString().length() - 1)).append(" ) ");
		Query queryConfRestricaoCanalVenta = getSession().createQuery(sb.toString());
		queryConfRestricaoCanalVenta.setInteger("usuarioId", usuarioId);		
		queryConfRestricaoCanalVenta.setDate("data", new Date());
		
		return queryConfRestricaoCanalVenta.executeUpdate()>1?true:false;
		
		
	}
}
