package no.valg.valgnatt.database.dao;

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

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import no.valg.valgnatt.database.hibernate.Rapport;
import no.valg.valgnatt.database.hibernate.Rapport_;

import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class RapportDao extends BaseDao<Rapport, String> {

    public List<Rapport> hentRapportKjoringer(Date dato) {
        if (dato == null) {
            return list();
        }
        Session session = sessionFactory.getCurrentSession();
        CriteriaBuilder cb = session.getCriteriaBuilder();
        CriteriaQuery<Rapport> cq = cb.createQuery(Rapport.class);
        Root<Rapport> root = cq.from(Rapport.class);
        cq.select(root)
                .where(cb.greaterThan(root.get(Rapport_.opprettetTid), dato));
        return session.createQuery(cq).getResultList();
        
    }

}
