import { validateString } from "./validateString.mjs";
import { validateEmail } from "./validateEmail.mjs";
import { validatePhone } from "./validatePhone.mjs";

//#region src/utils/validation/validateUser.ts
const defaultFieldsToCheck = [
	"name",
	"phone",
	"email",
	"phone"
];
const NAMES_MIN_LENGTH = 4;
const NAMES_MAX_LENGTH = 100;
/**
* Validates an user object.
* @param user The user object to validate.
* @returns An object containing the validation errors for each field.
*/
const validateUser = (user, fieldsToCheck = defaultFieldsToCheck) => {
	const errors = {};
	const fieldsToValidate = new Set(fieldsToCheck);
	const userJson = JSON.parse(JSON.stringify(user));
	for (const field of fieldsToValidate) {
		const value = userJson[field];
		errors[field] = [];
		if (field === "name") {
			const nameErrors = validateString(value, `User ${field}`, NAMES_MIN_LENGTH, NAMES_MAX_LENGTH);
			if (nameErrors.length > 0) errors[field] = nameErrors;
		}
		if (field === "email") {
			const emailErrors = validateEmail(value, "User Email");
			if (emailErrors.length > 0) errors[field] = emailErrors;
		}
		if (field === "phone") {
			const phoneErrors = validatePhone(value, "User Phone", 8, 20);
			if (phoneErrors.length > 0) errors[field] = phoneErrors;
		}
		if (errors[field].length === 0) delete errors[field];
	}
	return errors;
};

//#endregion
export { NAMES_MAX_LENGTH, NAMES_MIN_LENGTH, validateUser };
//# sourceMappingURL=validateUser.mjs.map