package com.engine.salary.formlua.func.compare;


import com.engine.salary.formlua.entity.parameter.DataType;
import com.engine.salary.formlua.util.ExcelParamUtil;

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

public class CommonOper {

    public static List<Object[]> operDivMultiList(Object obj1,Object obj2,String oper){
        List<Object[]> resultList=new ArrayList<>();
        if( (obj1 instanceof Object[] && !(obj2 instanceof Object[])) || (obj2 instanceof Object[] && !(obj1 instanceof Object[])) ){
            Object[] arrayParam;
            Object param;
            boolean firstArray=false;
            if(obj1 instanceof Object[]){
                arrayParam=(Object[])obj1;
                param=obj2;
                firstArray=true;
            }else {
                arrayParam=(Object[])obj2;
                param=obj1;
            }
            for (int i=0;i<arrayParam.length;i++){
                Object[] excuteArray=new Object[2];
                if(firstArray){
                    excuteArray[0]=arrayParam[i];
                    excuteArray[1]=param;
                }else{
                    excuteArray[1]=arrayParam[i];
                    excuteArray[0]=param;
                }
                resultList.add(excuteArray);
            }
        }else{
            throw new RuntimeException("'"+oper+"'不支持操作两个数组参数");
        }
        return resultList;
    }

    public static List<Object[]> operAddReduceList(Object obj1,Object obj2){
        List<Object[]> resultList=new ArrayList<>();
        Object[] param1=(Object[])obj1;
        Object[] param2=(Object[])obj2;
        if(param1.length!=param2.length){
            throw new RuntimeException("参数列表长度不一致");
        }
        for (int i=0;i<param1.length;i++){
            Object[] excuteArray=new Object[2];
            if(param1[i] instanceof DataType){
                DataType dataType=(DataType)param1[i];
                excuteArray[0]= ExcelParamUtil.getParamContent(dataType,"");
            }else{
                excuteArray[0]=param1[i];
            }

            if(param2[i] instanceof DataType){
                DataType dataType=(DataType)param2[i];
                excuteArray[1]=ExcelParamUtil.getParamContent(dataType,"");
            }else{
                excuteArray[1]=param2[i];
            }
            resultList.add(excuteArray);
        }

        return resultList;
    }

}
