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

//#region ../chokidar/dist/esm/api/dist/esm/getIntlayerAPI/organization.mjs
const getOrganizationAPI = (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 ORGANIZATION_API_ROUTE = `${backendURL}/api/organization`;
	/**
	* Retrieves a list of organizations based on filters and pagination.
	* @param filters - Filters and pagination options.
	*/
	const getOrganizations = async (filters, otherOptions = {}) => await fetcher(ORGANIZATION_API_ROUTE, authAPIOptions, otherOptions, {
		cache: "no-store",
		params: filters
	});
	/**
	* Retrieves an organization by its ID.
	* @param organizationId - Organization ID.
	*/
	const getOrganization = async (organizationId, otherOptions = {}) => await fetcher(`${ORGANIZATION_API_ROUTE}/${String(organizationId)}`, authAPIOptions, otherOptions);
	/**
	* Adds a new organization to the database.
	* @param organization - Organization data.
	*/
	const addOrganization = async (organization, otherOptions = {}) => await fetcher(ORGANIZATION_API_ROUTE, authAPIOptions, otherOptions, {
		method: "POST",
		body: organization
	});
	/**
	* Updates an existing organization in the database.
	* @param organization - Updated organization data.
	*/
	const updateOrganization = async (organization, otherOptions = {}) => fetcher(ORGANIZATION_API_ROUTE, authAPIOptions, otherOptions, {
		method: "PUT",
		body: organization
	});
	/**
	* Update members to the organization in the database.
	* @param body - Updated organization members data.
	*/
	const updateOrganizationMembers = async (body, otherOptions = {}) => fetcher(`${ORGANIZATION_API_ROUTE}/members`, authAPIOptions, otherOptions, {
		method: "PUT",
		body
	});
	/**
	* Admin-only: Update members of any organization by ID
	* @param organizationId - Organization ID
	* @param body - Updated organization members data.
	*/
	const updateOrganizationMembersById = async (organizationId, body, otherOptions = {}) => fetcher(`${ORGANIZATION_API_ROUTE}/${organizationId}/members`, authAPIOptions, otherOptions, {
		method: "PUT",
		body
	});
	/**
	* Add member to the organization in the database.
	* @param body - Updated organization members data.
	*/
	const addOrganizationMember = async (body, otherOptions = {}) => fetcher(`${ORGANIZATION_API_ROUTE}/member`, authAPIOptions, otherOptions, {
		method: "POST",
		body
	});
	/**
	* Deletes an organization from the database by its ID.
	* @param organizationId - Organization ID.
	*/
	const deleteOrganization = async (otherOptions = {}) => await fetcher(ORGANIZATION_API_ROUTE, authAPIOptions, otherOptions, { method: "DELETE" });
	/**
	* Select an organization from the database by its ID.
	* @param organizationId - Organization ID.
	*/
	const selectOrganization = async (organizationId, otherOptions = {}) => await fetcher(`${ORGANIZATION_API_ROUTE}/${String(organizationId)}`, authAPIOptions, otherOptions, { method: "PUT" });
	/**
	* Unselect an organization from the database by its ID.
	* @param organizationId - Organization ID.
	*/
	const unselectOrganization = async (otherOptions = {}) => await fetcher(`${ORGANIZATION_API_ROUTE}/logout`, authAPIOptions, otherOptions, { method: "POST" });
	return {
		getOrganizations,
		getOrganization,
		addOrganization,
		addOrganizationMember,
		updateOrganization,
		updateOrganizationMembers,
		updateOrganizationMembersById,
		deleteOrganization,
		selectOrganization,
		unselectOrganization
	};
};

//#endregion
export { getOrganizationAPI };
//# sourceMappingURL=organization.mjs.map