package cn.estsh.i3plus.pojo.lac.sqlpack;

import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.LacEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.lac.bean.*;

import java.util.List;

/**
 * @Description :
 * @Reference :
 * @Author : wei.peng
 * @CreateDate : 19-10-22 下午5:34
 * @Modify:
 **/
public class LacHqlPack {

    private LacHqlPack() {
    }

    /**
     * In 参数封装
     * @param columnName
     * @return
     */
    public static DdlPackBean packHqlInArray(String columnName, Object[] params){
        DdlPackBean ddlPackBean =DdlPackBean.getDdlPackBean();

        // 参数数组 [1,2,3] -> "1,2,3"
        DdlPreparedPack.getInPackArray(params,columnName,ddlPackBean);

        return ddlPackBean;
    }

    /**
     * In 参数封装
     * @param columnName
     * @return
     */
    public static DdlPackBean packHqlInList(String columnName, List params){
        DdlPackBean ddlPackBean =DdlPackBean.getDdlPackBean();

        // 参数数组 [1,2,3] -> "1,2,3"
        DdlPreparedPack.getInPackList(params,columnName,ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacTaskType(LacTaskType bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacLogTaskDetail(LacLogTaskDetail bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(bean);

        DdlPreparedPack.getNumEqualPack(bean.getLogTaskId(),"logTaskId",ddlPackBean);
        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacLogTask(LacLogTask bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bean.getCommandStackRecordId(), "commandStackRecordId", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bean.getTaskId(), "taskId", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bean.getTaskStatus(), "taskStatus", ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacCommandStackTemplate(LacCommandStackTemplate bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getStringEqualPack(bean.getTemplateCode(), "templateCode", ddlPackBean);
        DdlPreparedPack.getStringEqualPack(bean.getTemplateName(), "templateName", ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacCommandStackStep(LacCommandStackStep bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bean.getTemplateId(), "templateId", ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bean.getStepName(), "stepName", ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bean.getStepCode(), "stepCode", ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacCommandStackStepTask(LacCommandStackStepTask bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bean.getTemplateId(), "templateId", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bean.getStepId(), "stepId", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bean.getTaskId(), "taskId", ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bean.getTaskNameRdd(), "taskNameRdd", ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacSuitTask(LacSuitTask bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
        if (bean == null) {
            return ddlPackBean;
        }
        DdlPreparedPack.getStringLikerPack(bean.getTaskName(), "taskName", ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bean.getTaskCode(), "taskCode", ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacSuitTask(LacSuitTask bean, List<Long> idList) {
        DdlPackBean ddlPackBean = packHqlLacSuitTask(bean);

        DdlPreparedPack.getInPackList(idList, "id", ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacSuitTaskParamAdapter(LacSuitTaskParamAdapter bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
        if(bean!=null) {
            DdlPreparedPack.getNumEqualPack(bean.getTaskId(), "taskId", ddlPackBean);
            DdlPreparedPack.getStringLikerPack(bean.getParamName(), "paramName", ddlPackBean);
        }

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacSuitTaskParamAdapter(LacSuitTaskParamAdapter bean, List<Long> taskIdList) {
        DdlPackBean ddlPackBean = packHqlLacSuitTaskParamAdapter(bean);

        DdlPreparedPack.getInPackList(taskIdList, "taskId", ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacSuitTaskParam(LacSuitTaskParam bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
        if (bean == null) {
            return ddlPackBean;
        }
        DdlPreparedPack.getNumEqualPack(bean.getParamType(), "paramType", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bean.getTaskId(), "taskId", ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacSuitTaskParam(LacSuitTaskParam bean, List<Long> taskIdList) {
        DdlPackBean ddlPackBean = packHqlLacSuitTaskParam(bean);

        DdlPreparedPack.getInPackList(taskIdList, "taskId", ddlPackBean);

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacCommandStackType(LacCommandStackType bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacCommandStackRecord(LacCommandStackRecord bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();

        DdlPreparedPack.getNumEqualPack(bean.getStackStatus(), "stackStatus", ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bean.getCommandStackId(), "commandStackId", ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bean.getCommandStackNameRdd(), "commandStackNameRdd", ddlPackBean);
        DdlPreparedPack.timeBuilder(bean.getStackStartTime(), "stackStartTime", ddlPackBean,false, true);


        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacCommandStackStepByTemplateId(Long templateId) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
        DdlPreparedPack.getNumEqualPack(templateId, "templateId", ddlPackBean);
        DdlPreparedPack.getOrderByPack(
                new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()},
                new String[]{"stepSort"},
                ddlPackBean
        );
        return ddlPackBean;
    }

    public static DdlPackBean packHqlNotFinishLacCommandStackRecord() {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean();
        DdlPreparedPack.getNumberSmallerPack(LacEnumUtil.STACK_STATUS.FINISH.getValue(), "stackStatus", ddlPackBean);
        return ddlPackBean;
    }

    public static DdlPackBean packHqlCheckLacTaskCheckMasterOnly(LacTaskCheck lacTaskCheck){
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(lacTaskCheck);
        DdlPreparedPack.getStringEqualPack(lacTaskCheck.getTaskCheckGroup(),"taskCheckGroup",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(lacTaskCheck.getStepId(),"stepId",ddlPackBean);
        DdlPreparedPack.getNumNOEqualPack(lacTaskCheck.getId(),"id",ddlPackBean);
        return ddlPackBean;
    }

    public static DdlPackBean packHqlLacSuitCase(LacSuitCase bean) {
        DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(bean);

        DdlPreparedPack.getStringLikerPack(bean.getSuitCaseNameRdd(),"suitCaseNameRdd",ddlPackBean);
        DdlPreparedPack.getStringLikerPack(bean.getSuitCaseCodeRdd(),"suitCaseCodeRdd",ddlPackBean);
        DdlPreparedPack.getNumEqualPack(bean.getSuitType(),"suitType",ddlPackBean);

        return ddlPackBean;
    }
}
