//#region extensions/feishu/src/state/thread-bindings.ts
const STATE_KEY = Symbol.for("xopc.feishuThreadBindingsState");
function getState() {
	const store = globalThis;
	let st = store[STATE_KEY];
	if (!st) {
		st = { byAccountConversation: /* @__PURE__ */ new Map() };
		store[STATE_KEY] = st;
	}
	return st;
}
function key(accountId, conversationId) {
	return `${accountId}:${conversationId}`;
}
function bindFeishuConversation(params) {
	const now = Date.now();
	const rec = {
		accountId: params.accountId,
		conversationId: params.conversationId,
		parentConversationId: params.parentConversationId,
		targetSessionKey: params.targetSessionKey,
		boundAt: now,
		lastActivityAt: now,
		metadata: params.metadata
	};
	getState().byAccountConversation.set(key(rec.accountId, rec.conversationId), rec);
	return rec;
}
function listBindingsBySessionKey(accountId, targetSessionKey) {
	const out = [];
	for (const rec of getState().byAccountConversation.values()) if (rec.accountId === accountId && rec.targetSessionKey === targetSessionKey) out.push(rec);
	return out;
}
function unbindBySessionKey(accountId, targetSessionKey) {
	const removed = [];
	for (const rec of getState().byAccountConversation.values()) {
		if (rec.accountId !== accountId || rec.targetSessionKey !== targetSessionKey) continue;
		getState().byAccountConversation.delete(key(rec.accountId, rec.conversationId));
		removed.push(rec);
	}
	return removed;
}
//#endregion
export { bindFeishuConversation, listBindingsBySessionKey, unbindBySessionKey };

//# sourceMappingURL=thread-bindings.js.map