const require_utils_validation_validateString = require('./validateString.cjs');
const require_services_organization_service = require('../../services/organization.service.cjs');

//#region src/utils/validation/validateTag.ts
const defaultFieldsToCheck = ["name"];
const KEY_MIN_LENGTH = 4;
const KEY_MAX_LENGTH = 20;
const NAME_MIN_LENGTH = 4;
const NAME_MAX_LENGTH = 50;
/**
* Validates an tag object.
* @param tag The tag object to validate.
* @returns An object containing the validation errors for each field.
*/
const validateTag = async (tag, fieldsToCheck = defaultFieldsToCheck) => {
	const errors = {};
	const fieldsToValidate = new Set(fieldsToCheck);
	for (const field of fieldsToValidate) {
		const value = tag[field];
		errors[field] = [];
		if (field === "key") {
			const nameErrors = require_utils_validation_validateString.validateString(value, "Key", KEY_MIN_LENGTH, KEY_MAX_LENGTH);
			if (nameErrors.length > 0) errors[field] = nameErrors;
		}
		if (field === "name") {
			const nameErrors = require_utils_validation_validateString.validateString(value, "Name", NAME_MIN_LENGTH, NAME_MAX_LENGTH);
			if (nameErrors.length > 0) errors[field] = nameErrors;
		}
		if (field === "organizationId") {
			const organizationErrors = [];
			if (typeof value !== "string") organizationErrors.push("Organization id must be a string");
			if (!value) organizationErrors.push("Organization id is required");
			if (!await require_services_organization_service.getOrganizationById(field)) organizationErrors.push("Organization not found");
			if (organizationErrors.length > 0) errors[field] = organizationErrors;
		}
		if (errors[field].length === 0) delete errors[field];
	}
	return errors;
};

//#endregion
exports.KEY_MAX_LENGTH = KEY_MAX_LENGTH;
exports.KEY_MIN_LENGTH = KEY_MIN_LENGTH;
exports.NAME_MAX_LENGTH = NAME_MAX_LENGTH;
exports.NAME_MIN_LENGTH = NAME_MIN_LENGTH;
exports.validateTag = validateTag;
//# sourceMappingURL=validateTag.cjs.map