import _ from 'lodash';

const defaultArgs = {
  default: ['message', 'data'],
  methodNotAllowed: ['message', 'data', 'allow'],
  unauthorized: ['message', 'scheme', 'attributes'],
  create: ['statusCode', 'message', 'data'],
  wrap: ['error', 'statusCode', 'message']
}

/**
 * This function gets a boom function and arguments in new format and return
 * a wrapped boom function
 */
function getWrappedFunc(funcName, func, ...args) {
  const funcDefaultArgs = defaultArgs[funcName] || defaultArgs['default'];
  const allArgs = funcDefaultArgs.concat(args);

  return function(...allArgs) {
    let result =  func.call(null, ...allArgs);
    for (var i = 0; i < args.length; i++) {
      let currArgVal = allArgs[i + funcDefaultArgs.length];
      const argDef = args[i];
      // Check if we need to use the defaults
      if (currArgVal === undefined){
        // Run the function from the args def
        if (_.isFunction(argDef.default)) {
          result.output.payload[argDef.name] = argDef.default();
        // Add the default value to result
        } else if (argDef.default) {
          result.output.payload[argDef.name] = argDef.default;
        }
        // Add the passed value to result
      } else {
        result.output.payload[argDef.name] = currArgVal;
      }
    }
    return result;
  };
}

export {
  getWrappedFunc
}

@@ -581,24 +581,86 @@
 .allArgs) %7B%0A
+    const boomArgs = _.take(allArgs, funcDefaultArgs.length);%0A
     let resu
@@ -684,19 +684,20 @@
 ull, ...
-all
+boom
 Args);%0A 

Improve calling of the internal boom function - call with the correct args (Fix problem with internal errors)