var angular = require('angular');
require('../modules');

angular
  .module('flowmodulebutton.services')
  .factory('DefaultWorkflowParam', DefaultWorkflowParam);

/**
 * @ngInject
 */
function DefaultWorkflowParam() {
  var param = {};

  var DefaultWorkflowParam = {
    set: set,
    setParam: setParam,
    get: get,
    reset: reset,
    setTempNotion: setTempNotion,
    getTempNotion: getTempNotion
  };

  return DefaultWorkflowParam;

  // 设置其中'key'这个参数的值
  function setParam(key, value) {
    param[key] = value;
  }

  function set(para) {
    param = para
  }

  function get() {
    return param;
  }

  function reset() {
    param = {};
  }

  function setTempNotion(type, notion) {
    if (param.tempNotions) {
      param.tempNotions.forEach(function(tempNotion) {
        if (tempNotion.type === type) {
          tempNotion.content = notion;
        }
      });
    }
  }

  function getTempNotion(type) {
    for (var i = param.tempNotions.length; i--;) {
      if (param.tempNotions[i].type === type) {
        return param.tempNotions[i].content;
      }
    }
  }
}
