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

//#region src/utils/mapper/project.ts
/**
* Sanitizes the AI configuration by removing the API key and adding a flag.
* @param aiConfig - The AI configuration to sanitize.
* @returns The sanitized AI configuration.
*/
const sanitizeAIConfig = (aiConfig) => {
	if (!aiConfig) return aiConfig;
	const { apiKey, ...rest } = aiConfig;
	return {
		...rest,
		apiKeyConfigured: !!apiKey
	};
};
/**
* Sanitizes the project configuration by removing sensitive data.
* @param configuration - The project configuration to sanitize.
* @returns The sanitized project configuration.
*/
const sanitizeProjectConfiguration = (configuration) => {
	if (!configuration) return configuration;
	return {
		...configuration,
		ai: sanitizeAIConfig(configuration.ai)
	};
};
/**
* Maps a project to an API response.
* @param project - The project to map.
* @param  - Whether the user is an admin of the project.
* @returns The project mapped to an API response.
*/
const mapProjectToAPI = (project) => {
	if (!project) return null;
	const projectObject = ensureMongoDocumentToObject(project);
	if (projectObject.configuration) projectObject.configuration = sanitizeProjectConfiguration(projectObject.configuration);
	return projectObject;
};
/**
* Formats an array of projects for API response. Removes sensitive information.
* @param projects - The array of project objects to format.
* @param user - The user object.
* @param  - Whether the user is an admin of the project.
* @returns The formatted array of user objects.
*/
const mapProjectsToAPI = (projects) => projects.map(mapProjectToAPI).filter(Boolean);

//#endregion
export { mapProjectToAPI, mapProjectsToAPI };
//# sourceMappingURL=project.mjs.map