import { getPostmanItemAtIndexPath } from "./postman-request-tree.js";
import { getOpenApiMergeKeys, getPostmanMergeKeys } from "./get-merge-key.js";
//#region src/v2/features/command-palette/helpers/postman-request-collisions.ts
/**
* Among the selected Postman request path keys, returns keys whose requests map to the same
* OpenAPI path + HTTP method as another selected request or an existing operation in the base document.
*
* @param itemRoot - Postman collection `item` array
* @param selectedPathKeys - Selected Postman request path keys (JSON index paths)
* @param baseDocument - Optional existing OpenAPI document to check for collisions
*/
var getCollidingPostmanRequestPathKeys = (itemRoot, selectedPathKeys, baseDocument) => {
	const byMergeKey = /* @__PURE__ */ new Map();
	const baseMergeKeys = baseDocument ? getOpenApiMergeKeys(baseDocument) : /* @__PURE__ */ new Set();
	for (const key of selectedPathKeys) {
		let path;
		try {
			path = JSON.parse(key);
		} catch {
			continue;
		}
		const mergeKey = getPostmanMergeKeys(getPostmanItemAtIndexPath(itemRoot, path));
		if (mergeKey === void 0) continue;
		const list = byMergeKey.get(mergeKey) ?? [];
		list.push(key);
		byMergeKey.set(mergeKey, list);
	}
	const colliding = [];
	for (const [mergeKey, keys] of byMergeKey.entries()) if (keys.length > 1 || baseMergeKeys.has(mergeKey)) colliding.push(...keys);
	return colliding;
};
//#endregion
export { getCollidingPostmanRequestPathKeys };

//# sourceMappingURL=postman-request-collisions.js.map