'use strict';

var _ = require('lodash');
var util = require('util');

var validateDeprecation = function(value, expectation, options) {
  if (!options.deprecated) {
    return;
  }

  var valid = (value instanceof options.deprecated || typeof(value) === typeof(options.deprecated.call()));

  if (valid) {
    var message = util.format('%s should not be of type "%s"', util.inspect(value), options.deprecated.name);

    console.log('DEPRECATION WARNING:', options.deprecationWarning || message);
  }

  return valid;
};

var validate = function(value, expectation, options) {

  // the second part of this check is a workaround to deal with an issue that occurs in node-webkit when
  // using object literals.  https://github.com/sequelize/sequelize/issues/2685
  if (value instanceof expectation || typeof(value) === typeof(expectation.call())) {
    return true;
  }

  throw new Error(util.format('The parameter (value: %s) is no %s.', value, expectation.name));
};

var ParameterValidator = module.exports = {
  check: function(value, expectation, options) {
    options = _.extend({
      deprecated: false,
      index: null,
      method: null,
      optional: false
    }, options || {});

    if (!value && options.optional) {
      return true;
    }

    if (value === undefined) {
      throw new Error('No value has been passed.');
    }

    if (expectation === undefined) {
      throw new Error('No expectation has been passed.');
    }

    return false
      || validateDeprecation(value, expectation, options)
      || validate(value, expectation, options);
  }
};


@@ -190,17 +190,16 @@
 valid = 
-(
 value in
@@ -229,64 +229,8 @@
 ated
- %7C%7C typeof(value) === typeof(options.deprecated.call()))
 ;%0A%0A 
@@ -518,276 +518,42 @@
 ) %7B%0A
-%0A  // the second part of this check is a workaround to deal with an issue that occurs in node-webkit when%0A  // using object literals.  https://github.com/sequelize/sequelize/issues/2685%0A  if (value instanceof expectation %7C%7C typeof(value) === typeof(expectation.call())
+  if (value instanceof expectation
 ) %7B%0A
@@ -1284,13 +1284,12 @@
 ns);%0A  %7D%0A%7D;%0A
-%0A

Revert "Workaround to deal with an issue in node-webkit where the validate function fails on object literals"