"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.assertReturnOfBuilder = exports.validateMaxChoicesLength = exports.validateMaxOptionsLength = exports.validateDefaultPermission = exports.validateDescription = exports.validateName = exports.validateRequiredParameters = void 0;
const tslib_1 = require("tslib");
const is_1 = tslib_1.__importDefault(require("@sindresorhus/is"));
const ow_1 = tslib_1.__importDefault(require("ow"));
function validateRequiredParameters(name, description, options) {
    // Assert name matches all conditions
    validateName(name);
    // Assert description conditions
    validateDescription(description);
    // Assert options conditions
    validateMaxOptionsLength(options);
}
exports.validateRequiredParameters = validateRequiredParameters;
const namePredicate = ow_1.default.string.lowercase
    .minLength(1)
    .maxLength(32)
    .addValidator({
    message: (value, label) => `Expected ${label} to match "^[\\p{L}\\p{N}_-]+$", got ${value} instead`,
    validator: (value) => /^[\p{L}\p{N}_-]+$/u.test(value),
});
function validateName(name) {
    ow_1.default(name, 'name', namePredicate);
}
exports.validateName = validateName;
const descriptionPredicate = ow_1.default.string.minLength(1).maxLength(100);
function validateDescription(description) {
    ow_1.default(description, 'description', descriptionPredicate);
}
exports.validateDescription = validateDescription;
const defaultPermissionPredicate = ow_1.default.boolean;
function validateDefaultPermission(value) {
    ow_1.default(value, 'default_permission', defaultPermissionPredicate);
}
exports.validateDefaultPermission = validateDefaultPermission;
const maxArrayLengthPredicate = ow_1.default.array.maxLength(25);
function validateMaxOptionsLength(options) {
    ow_1.default(options, 'options', maxArrayLengthPredicate);
}
exports.validateMaxOptionsLength = validateMaxOptionsLength;
function validateMaxChoicesLength(choices) {
    ow_1.default(choices, 'choices', maxArrayLengthPredicate);
}
exports.validateMaxChoicesLength = validateMaxChoicesLength;
function assertReturnOfBuilder(input, ExpectedInstanceOf) {
    const instanceName = ExpectedInstanceOf.name;
    if (is_1.default.nullOrUndefined(input)) {
        throw new TypeError(`Expected to receive a ${instanceName} builder, got ${input === null ? 'null' : 'undefined'} instead.`);
    }
    if (is_1.default.primitive(input)) {
        throw new TypeError(`Expected to receive a ${instanceName} builder, got a primitive (${typeof input}) instead.`);
    }
    if (!(input instanceof ExpectedInstanceOf)) {
        const casted = input;
        const constructorName = is_1.default.function_(input) ? input.name : casted.constructor.name;
        const stringTag = Reflect.get(casted, Symbol.toStringTag);
        const fullResultName = stringTag ? `${constructorName} [${stringTag}]` : constructorName;
        throw new TypeError(`Expected to receive a ${instanceName} builder, got ${fullResultName} instead.`);
    }
}
exports.assertReturnOfBuilder = assertReturnOfBuilder;
//# sourceMappingURL=Assertions.js.map