/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rjconsultores.ventaboletos.dao.hibernate;

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

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
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.PeriodoVacacionalDAO;
import com.rjconsultores.ventaboletos.entidad.PeriodoVacacional;

/**
 *
 * @author Rafius
 */
@Repository("periodoVacacionalDAO")
public class PeriodoVacacionalHibernateDAO extends GenericHibernateDAO<PeriodoVacacional, Integer>
        implements PeriodoVacacionalDAO {

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

    }

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

        return c.list();
    }

    @Override
    public List<PeriodoVacacional> buscar(Date dataInicio, Date dataFim) {
        Criteria c = getSession().createCriteria(getPersistentClass());
        c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));

        c.add(Restrictions.eq("fecinicio", dataInicio));
        c.add(Restrictions.eq("fecfinal", dataFim));

        return c.list();
    }

    @Override
    public List<PeriodoVacacional> buscarFechaTraslapa(PeriodoVacacional periodoVacacional) {
    	
		Criteria c = this.getSession().createCriteria(PeriodoVacacional.class);
		c.add(Restrictions.eq(ACTIVO, Boolean.TRUE));
		c.add(Restrictions.ge("fecfinal", periodoVacacional.getFecinicio()));
		c.add(Restrictions.le("fecinicio", periodoVacacional.getFecfinal()));
		
		
		return c.list();
    }
}
