import { validateArray } from "./validateArray.mjs";
import { findProjects } from "../../services/project.service.mjs";

//#region src/utils/validation/validateDictionary.ts
const defaultFieldsToCheck = ["projectIds"];
/**
* Validates an dictionary object.
* @param dictionary The dictionary object to validate.
* @returns An object containing the validation errors for each field.
*/
const validateDictionary = async (dictionary, fieldsToCheck = defaultFieldsToCheck) => {
	const errors = {};
	const fieldsToValidate = new Set(fieldsToCheck);
	const dictionaryJSON = JSON.parse(JSON.stringify(dictionary));
	const projects = await findProjects({ _id: dictionary.projectIds });
	for (const field of fieldsToValidate) {
		const value = dictionaryJSON[field];
		errors[field] = [];
		if (field === "projectIds") {
			const projectsErrors = validateArray(value, "Project", "string", (value) => {
				const projectErrors = [];
				if (typeof value !== "string") projectErrors.push("Project id must be a string");
				if (!value) projectErrors.push("Project id is required");
				if (!projects) projectErrors.push("Project not found");
				return projectsErrors;
			});
		}
		if (errors[field].length === 0) delete errors[field];
	}
	return errors;
};

//#endregion
export { validateDictionary };
//# sourceMappingURL=validateDictionary.mjs.map