"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var lodash_1 = __importDefault(require("lodash"));
function validate(validatorsMap) {
    return new Promise(function (resolve, reject) {
        var result = Promise.resolve();
        var errors = {};
        // iterate by all keys except null values
        lodash_1.default.forOwn(lodash_1.default.omitBy(validatorsMap, lodash_1.default.isNull), function (validator, key) {
            result = result.then(function () {
                return validator.catch(function (error) {
                    errors[key] = error;
                    return Promise.resolve();
                });
            });
        });
        result.then(function () {
            if (lodash_1.default.isEmpty(errors)) {
                resolve();
            }
            else {
                reject(errors); //FIXME Promise rejected with non-Error
            }
        });
    });
}
exports.validate = validate;
function stripErrors(errors) {
    return lodash_1.default.reduce(errors, function (acc, errorDetails, errorFieldName) {
        if (lodash_1.default.isString(errorDetails.message)) {
            acc[errorFieldName] = errorDetails.message;
        }
        else {
            acc[errorFieldName] = stripErrors(errorDetails);
        }
        return acc;
    }, {});
}
exports.stripErrors = stripErrors;
//# sourceMappingURL=ValidationUtils.js.map