var assert = require('assert');
var types = require('./Types.js');

// isArray assertion
// assert.isArray(value, message)

module.exports = assert;

var isArray = assert.isArray = function (value, message) {
    if (!types.isArray(value)) {
        assert.fail(types.typeOf(value), 'array', message, '==', isArray);
    }
};

// isBoolean assertion
// assert.isBoolean(value, message)

var isBoolean = assert.isBoolean = function (value, message) {
    if (!types.isBoolean(value)) {
        assert.fail(types.typeOf(value), 'boolean', message, '==', isBoolean);
    }
};

// isDate assertion
// assert.isDate(value, message)

var isDate = assert.isDate = function (value, message) {
    if (!types.isDate(value)) {
        assert.fail(types.typeOf(value), 'date', message, '==', isDate);
    }
};

// isFunction assertion
// assert.isFunction(value, message)

var isFunction = assert.isFunction = function (value, message) {
    if (!types.isFunction(value)) {
        assert.fail(types.typeOf(value), 'function', message, '==', isFunction);
    }
};

// isInstanceOf assertion
// assert.isInstanceOf(obj1, obj2, message)

var isInstanceOf = assert.isInstanceOf = function (obj1, obj2, message) {
    if (!types.isInstanceOf(obj1, obj2)) {
        assert.fail('not a instanceof', 'instanceof', message, '==', isInstanceOf);
    }
};

// isNull assertion
// assert.isNull(value, message)

var isNull = assert.isNull = function (value, message) {
    if (!types.isNull(value)) {
        assert.fail(types.typeOf(value), 'null', message, '==', isNull);
    }
};

// isNumber assertion
// assert.isNumber(value, message)

var isNumber = assert.isNumber = function (value, message) {
    if (!types.isNumber(value)) {
        assert.fail(types.typeOf(value), 'number', message, '==', isNumber);
    }
};

// isObject assertion
// assert.isObject(value, message)

var isObject = assert.isObject = function (value, message) {
    if (!types.isObject(value)) {
        assert.fail(types.typeOf(value), 'object', message, '==', isObject);
    }
};

// isRegExp assertion
// assert.isRegExp(value, message)

var isRegExp = assert.isRegExp = function (value, message) {
    if (!types.isRegExp(value)) {
        assert.fail(types.typeOf(value), 'regexp', message, '==', isRegExp);
    }
};

// isString assertion
// assert.isString(value, message)

var isString = assert.isString = function (value, message) {
    if (!types.isString(value)) {
        assert.fail(types.typeOf(value), 'string', message, '==', isString);
    }
};

// isUndefined assertion
// assert.isUndefined(value, message)

var isUndefined = assert.isUndefined = function (value, message) {
    if (!types.isUndefined(value)) {
        assert.fail(types.typeOf(value), 'undefined', message, '==', isUndefined);
    }
};

var guard = assert.guard = function (value, types, message) {
    var lastError, i, l;

    for (i = 0, l = types.length; i < l; i++) {
        try {
            types[i](value, message);
            return;
        } catch (e) {
            lastError = e;
        }
    }

    throw lastError;
};

/*var guardNot = assert.guardNot = function(value, types, message){
    
};*/
