"use strict";
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const Yup = __importStar(require("yup"));
const misc_1 = require("../misc");
const BigNumberSchema_1 = require("./schemas/BigNumberSchema");
const yupValidator = Object.assign({}, Yup, { bool: Yup.bool, boolean: Yup.boolean, array: Yup.array, string: Yup.string, mixed: Yup.mixed, number: Yup.number, date: Yup.date, bigNumber: () => new BigNumberSchema_1.BigNumberSchema() });
yupValidator.addMethod(Yup.mixed, 'isRequired', function (message) {
    // @ts-ignore FIXME
    return this.required(message).typeError(message);
});
yupValidator.addMethod(yupValidator.string, 'isEthereumAddress', function (message = 'Address is invalid') {
    return this.test('validateIsEthereumAddress', message, function (value) {
        if (!misc_1.utils.isValidAddress(value)) {
            return this.createError({
                message,
            });
        }
        return true;
    });
});
yupValidator.addMethod(yupValidator.string, 'isEmail', function (message) {
    const emailRegex = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z0-9-]+$/i;
    return this.test('validateIsEmail', message, function (value) {
        return !value || emailRegex.test(value)
            ? true
            : this.createError({
                message,
            });
    });
});
yupValidator.addMethod(yupValidator.string, 'isUrl', function (message) {
    const urlRegex = /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[-a-zA-Z0-9@:%._+~#=]{2,256}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/i;
    return this.test('validateIsUrl', message, function (value) {
        return !value || urlRegex.test(value)
            ? true
            : this.createError({
                message,
            });
    });
});
const validator = yupValidator;
exports.validator = validator;
//# sourceMappingURL=index.js.map