'use strict';

var extend = require('cloneextend').extend;

/**
 * Represents a strategy that validates the configuration (post loading).
 *
 * @class
 */
function ValidateClientConfigStrategy () {
}

ValidateClientConfigStrategy.prototype.process = function (config, callback) {
  var newError = function (err) {
    callback(new Error(err));
  };

  if (!config) {
    return newError("Configuration not instantiated.");
  }

  var client = config.client;

  if (!client) {
    return newError("Client cannot be empty.");
  }

  var apiKey = client.apiKey;

  if (!apiKey) {
    return newError("API key cannot be empty.");
  } if (!apiKey.id || !apiKey.secret) {
    return newError("API key ID and secret is required.");
  }

  var application = config.application;

  if (!application) {
    return newError("Application cannot be empty.");
  }

  if (application.href && application.href.indexOf('/applications/') === -1) {
    return newError("Application HREF '" + application.href + "' is not a valid Stormpath Application HREF.");
  }

  callback(null, config);
};

module.exports = ValidateClientConfigStrategy;

@@ -1039,16 +1039,250 @@
 );%0A  %7D%0A%0A
+  var web = config.web;%0A%0A  if (web.spa && web.spa.enabled && web.spa.view === null) %7B%0A    return newError(%22SPA mode is enabled but web.spa.view isn't set. This needs to be the absolute path to the file that you want to serve.%22);%0A  %7D%0A%0A
   callba

add validation to ensure that web.spa.enabled isn't set without a web.spa.view