"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validator = void 0;
const Yup = __importStar(require("yup"));
const misc_1 = require("../misc");
const BigNumberSchema_1 = require("./schemas/BigNumberSchema");
const yupValidator = Object.assign(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) {
    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