//#region extensions/feishu/src/state/message-bindings.ts
const MAX = 5e4;
const TTL_MS = 1440 * 6e4;
const byMessageId = /* @__PURE__ */ new Map();
function prune(now) {
	for (const [k, v] of byMessageId) if (now - v.at > TTL_MS) byMessageId.delete(k);
	if (byMessageId.size <= MAX) return;
	const extra = byMessageId.size - MAX;
	let i = 0;
	for (const k of byMessageId.keys()) {
		byMessageId.delete(k);
		i++;
		if (i >= extra) break;
	}
}
function recordFeishuMessageBinding(binding) {
	const messageId = binding.messageId.trim();
	if (!messageId) return;
	const now = Date.now();
	prune(now);
	byMessageId.set(messageId, {
		binding,
		at: now
	});
}
function getFeishuBindingByMessageId(messageId) {
	const key = messageId.trim();
	if (!key) return null;
	const now = Date.now();
	const hit = byMessageId.get(key);
	if (!hit) return null;
	if (now - hit.at > TTL_MS) {
		byMessageId.delete(key);
		return null;
	}
	return hit.binding;
}
//#endregion
export { getFeishuBindingByMessageId, recordFeishuMessageBinding };

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