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.domain.PgSection;
import com.casic.PgInterface.intelPlan.dto.PgLineType;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.stereotype.Service;

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

@Service
public class PgSectionManager extends HibernateEntityDao<PgSection>{

    public PgSection getPgSectionByRoadAndLine(String lineName,Long roadId){

        Criteria criteria=createCriteria(PgSection.class);
        criteria.add(Restrictions.eq("lineName",lineName));
        criteria.add(Restrictions.eq("roadId",roadId));
        criteria.add(Restrictions.eq("active",true));

        List<PgSection> pgSectionList=criteria.list();
        if(pgSectionList==null||pgSectionList.size()==0)
            return null;
        else
            return pgSectionList.get(0);
    }

    public List<PgLineType> getLineType(){

        List<PgLineType> pgLineTypeList=new ArrayList<>();
        String sql="select distinct linename from pg_section where active = 1";

        List<Object> objList=this.getSession().createSQLQuery(sql).list();
        for(Object object : objList)
        {
            PgLineType pgLineType=new PgLineType();
            pgLineType.setLineType(String.valueOf(object));
            pgLineTypeList.add(pgLineType);
        }

        return pgLineTypeList;
    }

}