"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateOrganizationNameOrThrow = exports.getOrganizationNameSchema = exports.validateOrganizationName = void 0;
const zod_1 = require("zod");
const errors_1 = require("../types/errors");
const validateOrganizationName = (name) => {
    const trimmedName = name.trim();
    if (trimmedName === '')
        return false;
    const pattern = /^[A-Za-z0-9 _-]+$/;
    return pattern.test(trimmedName);
};
exports.validateOrganizationName = validateOrganizationName;
const getOrganizationNameSchema = () => zod_1.z.string().min(0).refine(exports.validateOrganizationName, {
    message: 'Organization name can be composed only of letters, numbers, spaces, underscores or dashes, and not be empty',
});
exports.getOrganizationNameSchema = getOrganizationNameSchema;
const validateOrganizationNameOrThrow = (name) => {
    const parsedOrganizationName = (0, exports.getOrganizationNameSchema)().safeParse(name);
    if (!parsedOrganizationName.success) {
        const error = parsedOrganizationName.error.errors[0];
        if (error.code === 'custom') {
            throw new errors_1.ParameterError(error.message);
        }
        throw new errors_1.ParameterError(parsedOrganizationName.error.message);
    }
};
exports.validateOrganizationNameOrThrow = validateOrganizationNameOrThrow;
//# sourceMappingURL=organization.js.map