import { minValidator } from './min';
import { maxValidator } from './max';
export var ValidatorsName;
(function (ValidatorsName) {
    ValidatorsName["min"] = "min";
    ValidatorsName["max"] = "max";
})(ValidatorsName || (ValidatorsName = {}));
export function getValidator(list) {
    return (list || [])
        .map(v => {
        if (typeof v === 'string') {
            return validatorFactory(v, null);
        }
        else {
            return validatorFactory(v.name, v.options);
        }
    })
        .reduce(combineValidator, defaultValidator);
}
export function combineValidator(v1, v2) {
    let combined;
    combined = { validate: (x) => {
            const res1 = v1.validate(x);
            const res2 = v2.validate(x);
            return Object.assign({}, res1, res2);
        } };
    return combined;
}
export function validatorFactory(name, options) {
    switch (name) {
        case (ValidatorsName.max):
            return maxValidator(options.max);
        case (ValidatorsName.min):
            return minValidator(options.min);
        default:
            return defaultValidator;
    }
}
const defaultValidator = {
    validate: (_x) => null
};
