/**
 * @fileOverview A hash containing global required environmental values.
 *
 */
var os = require('os');

var config = require('config');
var helpers = require('nodeon-helpers');
// var log = require('logg').getLogger('app.core.globals');

var globals = module.exports = {};

/** @type {?Object} Application Boot options */
globals.bootOpts = null;

/**
 * The supported environments
 *
 * @enum {string}
 */
globals.Environments = {
  DEVELOPMENT: 'development',
  DEV_API: 'dev_api',
  HEROKU: 'heroku',
  HEROKUDEV: 'heroku_dev',
};

/**
 * The roles this application can assume.
 *
 * @enum {string}
 */
globals.Roles = {
  API: 'api',
  WEBSITE: 'website',
};

/** @enum {string} Websocket namespaces */
globals.WebsocketNamespace = {
  ROOT: '/',
  WEBSITE: '/website',
  API: '/api',
};


/** @type {boolean} If application runs directly from shell, gets set on app */
globals.isStandAlone = true;

/** @type {string} a unique identifier string for this node process. */
globals.serverId = os.hostname() + '-' + process.pid + '-' +
  helpers.generateRandomString(6);

/**
 * Returns the current environemnt based on shell enviornment variable NODE_ENV
 * defaults to development.
 *
 * @return {app.core.globals.Environments} One of the supported environments.
 */
globals.getEnvironment = function() {
  var env = process.env.NODE_ENV || globals.Environments.DEVELOPMENT;

  for (var envIter in globals.Environments) {
    if (env === globals.Environments[envIter]) {
      return env;
    }
  }

  return globals.Environments.DEVELOPMENT;
};

/**
 * Matches the environment to a role.
 *
 * @param {app.core.globals.Environments=} optEnv optionally define an environment.
 * @return {app.core.globals.Roles} The current role.
 */
globals.getRole = function(optEnv) {
  var role = null;

  switch(optEnv || globals.getEnvironment()) {
  case globals.Environments.DEVELOPMENT:
    role = globals.Roles.WEB;
    break;
  case globals.Environments.DEV_API:
    role = globals.Roles.API;
    break;
  default:
    role = globals.Roles.WEB;
    break;
  }

  return role;
};

/**
 * The current environment canonicalized based on supported envs.
 * @type {app.core.globals.Environments}
 */
globals.env = globals.getEnvironment();

globals.role = globals.getRole(globals.env);

/** @type {boolean} If we are on development environment */
globals.isDev = [
  globals.Environments.DEVELOPMENT,
].indexOf(globals.env) >= 0;

/** @type {boolean} If the server is running in API mode */
globals.isApi = globals.role === globals.Roles.API;

/** @type {boolean} Determines if we are on heroku. */
globals.isHeroku = false;
if ([
  globals.Environments.HEROKUDEV,
  globals.Environments.HEROKU,
].indexOf(globals.env) >= 0) {
  globals.isHeroku = true;
}

/** @type {Object} Global variables available to views */
globals.viewGlobals = {
  ga: config.ga,
  env: globals.env,
};

/**
 * Get the Role from websocket namespace.
 *
 * @param {app.core.globals.WebsocketNamespace} namespace The websocket namespace.
 * @return {app.core.globals.Roles} The role.
 */
globals.getRoleFromNS = function (namespace) {
  var role;
  switch(namespace) {
  case globals.WebsocketNamespace.WEBSITE:
    role = globals.Roles.WEBSITE;
    break;
  case globals.WebsocketNamespace.API:
    role = globals.Roles.API;
    break;
  default:
    role = globals.Roles.WEBSITE;
    break;
  }

  return role;
};

@@ -1552,535 +1552,8 @@
 %7D;%0A%0A
-/**%0A * Matches the environment to a role.%0A *%0A * @param %7Bapp.core.globals.Environments=%7D optEnv optionally define an environment.%0A * @return %7Bapp.core.globals.Roles%7D The current role.%0A */%0Aglobals.getRole = function(optEnv) %7B%0A  var role = null;%0A%0A  switch(optEnv %7C%7C globals.getEnvironment()) %7B%0A  case globals.Environments.DEVELOPMENT:%0A    role = globals.Roles.WEB;%0A    break;%0A  case globals.Environments.DEV_API:%0A    role = globals.Roles.API;%0A    break;%0A  default:%0A    role = globals.Roles.WEB;%0A    break;%0A  %7D%0A%0A  return role;%0A%7D;%0A%0A
 /**%0A
@@ -1618,16 +1618,16 @@
 d envs.%0A
+
  * @type
@@ -1708,54 +1708,8 @@
 );%0A%0A
-globals.role = globals.getRole(globals.env);%0A%0A
 /** 
@@ -1818,16 +1818,16 @@
 OPMENT,%0A
+
 %5D.indexO
@@ -1852,121 +1852,8 @@
 0;%0A%0A
-/** @type %7Bboolean%7D If the server is running in API mode */%0Aglobals.isApi = globals.role === globals.Roles.API;%0A%0A
 /** 

remove unused code