"use strict";
var os = require('os');

var keys = {};

// arguments needed to simulate the GetDocumentsPath() function
var errArgGetDocumentsPath;
var fileLocationArgGetDocumentsPath;

function Mobile(key) {
  keys.hasOwnProperty(key) || (keys[key] = new Mobile.NativeCall(key));
  return keys[key];
}

Mobile.iAmAMock = true;

Mobile.setGetDocumentsPathReturnValues = function (errArg, fileLocationArg) {
  errArgGetDocumentsPath = errArg;
  fileLocationArgGetDocumentsPath = fileLocationArg;
};

Mobile.GetDocumentsPath = function (cb) {
  setImmediate(function () {
    cb(null, os.tmpdir());
  });
};

Mobile.invokeNative = function (key, arg) {
  keys[key].registerNativeCallback(arg);
};

function invokeCallback(key, args) {
  var localArgs = keys[key].callNativeArguments;
  var cb = localArgs[localArgs.length - 1];
  cb.apply(null, args);
}

Mobile.invokeConnect = function () {
  var len = arguments.length, args = new Array(len);
  for (var i = 0; i < len; i++) { args[i] = arguments[i]; }
  invokeCallback('Connect', args);
};

Mobile.invokeDisconnect = function () {
  var len = arguments.length, args = new Array(len);
  for (var i = 0; i < len; i++) { args[i] = arguments[i]; }
  invokeCallback('Disconnect', args);
};

Mobile.invokeStartBroadcasting = function () {
  var len = arguments.length, args = new Array(len);
  for (var i = 0; i < len; i++) { args[i] = arguments[i]; }
  invokeCallback('StartBroadcasting', args);
};

Mobile.invokeStopBroadcasting = function () {
  var len = arguments.length, args = new Array(len);
  for (var i = 0; i < len; i++) { args[i] = arguments[i]; }
  invokeCallback('StopBroadcasting', args);
};

Mobile.NativeCall = function(key) {
  this.key = key;
  this.registerNativeCallback = null;
  this.callNativeArguments = null;
};

Mobile.NativeCall.prototype = {
  registerToNative: function (cb) {
    this.registerNativeCallback = cb;
  },
  callNative: function () {
    this.callNativeArguments = arguments;
  }
};

module.exports = Mobile;

@@ -10,32 +10,8 @@
 ct%22;
-%0Avar os = require('os');
 %0A%0Ava
@@ -515,65 +515,66 @@
 %7B%0A  
-setImmediate(function () %7B%0A    cb(null, os.tmpdir());%0A  %7D
+cb(errArgGetDocumentsPath, fileLocationArgGetDocumentsPath
 );%0A%7D
@@ -1966,9 +1966,8 @@
  Mobile;
-%0A

Revert "Localhost GetDocumentsPath method update in mockmobile.js - fixes #233"