const require_utils_ensureMongoDocumentToObject = require('../ensureMongoDocumentToObject.cjs');

//#region src/utils/mapper/dictionary.ts
/**
* Maps a dictionary to an API response.
* If the version is not provided, the latest version is used.
*
* @param dictionary - The dictionary to map.
* @param projectId - The ID of the project the dictionary belongs to.
* @returns The dictionary mapped to an API response.
*/
const mapDictionaryToAPI = (dictionary, version) => {
	const dictionaryObject = require_utils_ensureMongoDocumentToObject.ensureMongoDocumentToObject(dictionary);
	const versionList = [...dictionaryObject.content.keys() ?? []];
	let returnedVersion = version;
	if (!returnedVersion) returnedVersion = versionList[versionList.length - 1];
	const content = dictionaryObject.content.get(returnedVersion)?.content ?? null;
	return {
		...dictionaryObject,
		content,
		version: returnedVersion,
		localId: `${dictionaryObject.key}::remote::${dictionaryObject.id}`,
		versionList
	};
};

//#endregion
exports.mapDictionaryToAPI = mapDictionaryToAPI;
//# sourceMappingURL=dictionary.cjs.map