//#region extensions/telegram/src/sent-cache.ts
/**
* Sent Message Cache
* 
* Tracks message IDs sent by the bot for:
* - Reaction filtering (don't react to own messages)
* - Message editing/deletion
* - Session context tracking
*/
const DEFAULT_TTL_MS = 1440 * 60 * 1e3;
var SentMessageCache = class {
	cache = /* @__PURE__ */ new Map();
	ttlMs;
	cleanupThreshold;
	constructor(options = {}) {
		this.ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
		this.cleanupThreshold = options.cleanupThreshold ?? 100;
	}
	getChatKey(chatId) {
		return String(chatId);
	}
	/**
	* Record a message ID as sent by the bot
	*/
	record(chatId, messageId) {
		const key = this.getChatKey(chatId);
		let entry = this.cache.get(key);
		if (!entry) {
			entry = {
				messageIds: /* @__PURE__ */ new Set(),
				timestamps: /* @__PURE__ */ new Map()
			};
			this.cache.set(key, entry);
		}
		entry.messageIds.add(messageId);
		entry.timestamps.set(messageId, Date.now());
		if (entry.messageIds.size > this.cleanupThreshold) this.cleanupEntry(entry);
	}
	/**
	* Check if a message was sent by the bot
	*/
	wasSentByBot(chatId, messageId) {
		const key = this.getChatKey(chatId);
		const entry = this.cache.get(key);
		if (!entry) return false;
		this.cleanupEntry(entry);
		return entry.messageIds.has(messageId);
	}
	/**
	* Clean up expired entries in a chat entry
	*/
	cleanupEntry(entry) {
		const now = Date.now();
		for (const [msgId, timestamp] of entry.timestamps) if (now - timestamp > this.ttlMs) {
			entry.messageIds.delete(msgId);
			entry.timestamps.delete(msgId);
		}
	}
	/**
	* Clear all entries for a chat
	*/
	clearChat(chatId) {
		this.cache.delete(this.getChatKey(chatId));
	}
	/**
	* Clear all entries (for testing)
	*/
	clearAll() {
		this.cache.clear();
	}
	/**
	* Get cache statistics
	*/
	getStats() {
		let totalMessages = 0;
		let oldestTimestamp = Infinity;
		let newestTimestamp = 0;
		for (const entry of this.cache.values()) {
			totalMessages += entry.messageIds.size;
			for (const timestamp of entry.timestamps.values()) {
				if (timestamp < oldestTimestamp) oldestTimestamp = timestamp;
				if (timestamp > newestTimestamp) newestTimestamp = timestamp;
			}
		}
		return {
			totalChats: this.cache.size,
			totalMessages,
			oldestMessageAt: oldestTimestamp !== Infinity ? new Date(oldestTimestamp) : void 0,
			newestMessageAt: newestTimestamp > 0 ? new Date(newestTimestamp) : void 0
		};
	}
};
const sentMessageCache = new SentMessageCache({
	ttlMs: DEFAULT_TTL_MS,
	cleanupThreshold: 100
});
//#endregion
export { SentMessageCache, sentMessageCache };

//# sourceMappingURL=sent-cache.js.map