import { ensureMongoDocumentToObject } from "../ensureMongoDocumentToObject.mjs";

//#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 = 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
export { mapDictionaryToAPI };
//# sourceMappingURL=dictionary.mjs.map