import { fetcher } from "../fetcher.mjs";
import { built_default } from "../config/dist/esm/built.mjs";

//#region ../@intlayer/chokidar/dist/esm/api/dist/esm/getIntlayerAPI/project.mjs
const getProjectAPI = (authAPIOptions = {}, intlayerConfig) => {
	const backendURL = intlayerConfig?.editor?.backendURL ?? built_default?.editor?.backendURL;
	if (!backendURL) throw new Error("Backend URL is not defined in the Intlayer configuration.");
	const PROJECT_API_ROUTE = `${backendURL}/api/project`;
	/**
	* Retrieves a list of projects based on filters and pagination.
	* @param filters - Filters and pagination options.
	*/
	const getProjects = async (filters, otherOptions = {}) => await fetcher(PROJECT_API_ROUTE, authAPIOptions, otherOptions, {
		cache: "no-store",
		params: filters
	});
	/**
	* Adds a new project to the database.
	* @param project - Project data.
	*/
	const addProject = async (project, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, {
		method: "POST",
		body: project
	});
	/**
	* Updates an existing project in the database.
	* @param project - Updated project data.
	*/
	const updateProject = async (project, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, {
		method: "PUT",
		body: project
	});
	/**
	* Updates project members in the database.
	* @param project - Updated project data.
	*/
	const updateProjectMembers = async (body, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/members`, authAPIOptions, otherOptions, {
		method: "PUT",
		body
	});
	/** Pushes a project configuration to the database.
	* @param projectConfiguration - Project configuration data.
	*/
	const pushProjectConfiguration = async (projectConfiguration, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/configuration`, authAPIOptions, otherOptions, {
		method: "PUT",
		body: projectConfiguration
	});
	/**
	* Deletes a project from the database by its ID.
	* @param id - Project ID.
	*/
	const deleteProject = async (otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}`, authAPIOptions, otherOptions, { method: "DELETE" });
	/**
	* Select a project from the database by its ID.
	* @param projectId - Organization ID.
	*/
	const selectProject = async (projectId, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/${String(projectId)}`, authAPIOptions, otherOptions, { method: "PUT" });
	/**
	* Unselect a project from the database by its ID.
	* @param projectId - Project ID.
	*/
	const unselectProject = async (otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/logout`, authAPIOptions, otherOptions, { method: "POST" });
	/**
	* Add a new access key to a project.
	* @param accessKey - Access key data.
	* @param otherOptions - Fetcher options.
	* @returns The new access key.
	*/
	const addNewAccessKey = async (accessKey, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/access_key`, authAPIOptions, otherOptions, {
		method: "POST",
		body: accessKey
	});
	/**
	* Delete a project access key.
	* @param clientId - Access key client ID.
	* @param otherOptions - Fetcher options.
	* @returns The deleted project.
	*/
	const deleteAccessKey = async (clientId, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/access_key`, authAPIOptions, otherOptions, {
		method: "DELETE",
		body: { clientId }
	});
	/**
	* Refreshes an access key from a project.
	* @param clientId - The ID of the client to refresh.
	* @param projectId - The ID of the project to refresh the access key from.
	* @returns The new access key.
	*/
	const refreshAccessKey = async (clientId, otherOptions = {}) => await fetcher(`${PROJECT_API_ROUTE}/access_key`, authAPIOptions, otherOptions, {
		method: "PATCH",
		body: { clientId }
	});
	return {
		getProjects,
		addProject,
		updateProject,
		updateProjectMembers,
		pushProjectConfiguration,
		deleteProject,
		selectProject,
		unselectProject,
		addNewAccessKey,
		deleteAccessKey,
		refreshAccessKey
	};
};

//#endregion
export { getProjectAPI };
//# sourceMappingURL=project.mjs.map