//#region src/utilities/maintenanceEngine/CrudBrowserUtilities.js
const RESERVED_PATH_PARAMETERS = ["version", "udp-api-version"];
const getPrimaryKeyValues = (properties, entityValue) => {
	return (properties?.filter((property) => property?.extendedProperties?.identifier))?.reduce((keyValues, property) => {
		if (entityValue && entityValue[property["name"]] !== null) keyValues.push(entityValue[property["name"]]);
		return keyValues;
	}, []);
};
const getPathObject = (pathParameters, primaryKeyValues) => {
	const primaryKeyParameters = pathParameters.filter((parameter) => parameter.name !== RESERVED_PATH_PARAMETERS);
	const pathObject = {};
	if (primaryKeyParameters.length && primaryKeyValues.length) primaryKeyParameters.forEach((pkp, index) => {
		pathObject[`{${pkp.name}}`] = primaryKeyValues[index];
	});
	return pathObject;
};
const findTermByType = (fieldType, term) => {
	if (fieldType.toLowerCase() === term) return fieldType.toLowerCase();
	else return "";
};
const getModelProperties = (model, componentsObj) => {
	let modelPropertiesObj = null;
	if (model) {
		modelPropertiesObj = model.properties;
		if (!modelPropertiesObj) {
			const refKeys = [];
			if (model["allOf"]?.length) model["allOf"].forEach((reference) => {
				if (reference["$ref"]) {
					const refString = reference["$ref"];
					if (refString) {
						const lastIndex = refString.lastIndexOf("/");
						const referenceModel = refString.substring(lastIndex + 1);
						refKeys.push(referenceModel);
					}
				}
			});
			refKeys.forEach((key) => {
				const abstractModel = componentsObj[key];
				if (modelPropertiesObj && abstractModel?.properties) modelPropertiesObj = {
					...modelPropertiesObj,
					...abstractModel.properties
				};
				else modelPropertiesObj = abstractModel?.properties;
			});
		}
	}
	return modelPropertiesObj;
};
const getEntityAttributes = (catalog, entityName) => {
	if (!catalog) return [];
	const catalogObjectList = catalog?.ctlg?.catalogObjectList;
	const componentsObj = catalog?.ctlg?.components;
	const entity = catalogObjectList?.find((catalogObject) => catalogObject.catalogObjectName === entityName);
	if (!!componentsObj && Object.keys(componentsObj).length) {
		const model = componentsObj[entityName];
		let modelPropertiesObj = getModelProperties(model, componentsObj);
		if (entity?.properties?.length) entity.properties.forEach((property) => {
			let nullable = true;
			if (modelPropertiesObj) {
				const modelProperty = modelPropertiesObj[property["name"]];
				if (modelProperty) nullable = modelProperty.nullable || false;
			}
			property["nullable"] = nullable;
		});
	}
	return entity ? entity.properties : [];
};
const getPathParametersObj = (pathParametersDefinition, entityData) => {
	if (!pathParametersDefinition || !entityData) return {};
	const pathParametersObj = {};
	for (let param of pathParametersDefinition) pathParametersObj[param.name] = entityData[param.name];
	return pathParametersObj;
};
//#endregion
export { findTermByType, getEntityAttributes, getPathObject, getPathParametersObj, getPrimaryKeyValues };

//# sourceMappingURL=CrudBrowserUtilities.mjs.map