package com.casic.PgInterface.intelPlan.manager;

import com.casic.PgInterface.core.hibernate.HibernateEntityDao;
import com.casic.PgInterface.intelPlan.domain.PgPile;
import com.casic.PgInterface.intelPlan.dto.PgPileDTO;
import org.hibernate.Criteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class PgPileManager extends HibernateEntityDao<PgPile>{

    public List<PgPileDTO> getPgPileDTOList(){
        Criteria criteria=createCriteria(PgPile.class);
        criteria.add(Restrictions.eq("active",true));
        criteria.addOrder(Order.desc("id"));

        List<PgPile> pgPileList=criteria.list();
        List<PgPileDTO> pgPileDTOList=new ArrayList<>();
        pgPileDTOList=PgPileDTO.ConvertToDTOList(pgPileList);
        if(pgPileDTOList==null||pgPileDTOList.size()==0)
            return null;
        else
            return pgPileDTOList;
    }

}