let JV = require('./jpc_value_define');
let JpcParam = {
    createNew: function(rptTpl) {
        let JpcParamResult = {};
        let me = this;
        if (rptTpl[JV.NODE_DISCRETE_PARAMS]) {
            for (let i = 0; i < rptTpl[JV.NODE_DISCRETE_PARAMS].length; i++) {
                me.createSingle(rptTpl[JV.NODE_DISCRETE_PARAMS][i], JpcParamResult, rptTpl, i);
            }
        }
        return JpcParamResult;
    },
    createSingle: function(paramNode, parentObj, rptTpl, sequence) {
        if (paramNode && paramNode[JV.PROP_ID]) {
            let item = {};
            item[JV.PROP_ID] = paramNode[JV.PROP_ID];
            item[JV.PROP_NAME] = paramNode[JV.PROP_NAME];
            item[JV.PROP_DATA_TYPE] = paramNode[JV.PROP_DATA_TYPE];
            if (paramNode[JV.PROP_DFT_VALUE]) item[JV.PROP_DFT_VALUE] = paramNode[JV.PROP_DFT_VALUE];
            item.DataSeq = sequence;
            parentObj[JV.PROP_ID + "_" + paramNode[JV.PROP_ID]] = item;
        }
    }
};

module.exports = JpcParam;