import { reactive } from "vue";
import { LS_KEYS } from "@scalar/helpers/object/local-storage";
import { serverSchema } from "@scalar/oas-utils/entities/spec";
import { mutationFactory } from "@scalar/object-utils/mutator-record";
//#region src/store/servers.ts
/** Create storage objects for servers */
function createStoreServers(useLocalStorage) {
	const servers = reactive({});
	return {
		servers,
		serverMutators: mutationFactory(servers, reactive({}), useLocalStorage && LS_KEYS.SERVER)
	};
}
/** Extended mutators and data for servers */
function extendedServerDataFactory({ serverMutators, collections, collectionMutators, requests, requestMutators }) {
	/**
	* Add a server
	* If the collectionUid is included it is added to the collection as well
	*/
	const addServer = (payload, parentUid) => {
		const server = serverSchema.parse(payload);
		if (collections[parentUid]) collectionMutators.edit(parentUid, "servers", [...collections[parentUid].servers, server.uid]);
		else if (requests[parentUid]) requestMutators.edit(parentUid, "servers", [...requests[parentUid].servers, server.uid]);
		serverMutators.add(server);
		return server;
	};
	/** Delete a server */
	const deleteServer = (serverUid, collectionUid) => {
		if (!collections[collectionUid]) return;
		collectionMutators.edit(collectionUid, "servers", collections[collectionUid].servers.filter((uid) => uid !== serverUid));
		serverMutators.delete(serverUid);
	};
	return {
		addServer,
		deleteServer
	};
}
//#endregion
export { createStoreServers, extendedServerDataFactory };

//# sourceMappingURL=servers.js.map