import * as yup from 'yup';

export default function (base: yup.StringSchema, validators: any[]) {
    return validators.reduce((schema, rule) => {
        if (!rule?.test || typeof rule.test !== 'function') {
            throw new Error(
                `[buildYupChain]: Валидатор "${rule?.name}" не содержит корректного test()`,
            );
        }
        return schema.test(rule.name, rule.message, rule.test);
    }, base);
}
