import { createLogger } from "../../utils/logger/index.js";
import { init_logger } from "../../utils/logger.js";
//#region src/voice/tts/status-tracker.ts
init_logger();
const log = createLogger("TTS:StatusTracker");
const MAX_RECENT_ENTRIES = 20;
var TtsStatusTrackerImpl = class {
	recentEntries = [];
	totalCalls = 0;
	totalSuccesses = 0;
	totalFailures = 0;
	recordAttempt(entry) {
		this.recentEntries.push(entry);
		this.totalCalls += 1;
		if (entry.success) this.totalSuccesses += 1;
		else this.totalFailures += 1;
		if (this.recentEntries.length > MAX_RECENT_ENTRIES) this.recentEntries.shift();
		log.debug({
			success: entry.success,
			provider: entry.provider,
			latencyMs: entry.latencyMs,
			totalCalls: this.totalCalls
		}, "TTS attempt recorded");
	}
	getStatus() {
		const recentSuccesses = this.recentEntries.filter((e) => e.success).length;
		const recentTotal = this.recentEntries.length;
		return {
			lastAttempt: this.recentEntries.length > 0 ? this.recentEntries[this.recentEntries.length - 1] : void 0,
			recentSuccessRate: recentTotal > 0 ? recentSuccesses / recentTotal : void 0,
			totalCalls: this.totalCalls,
			totalSuccesses: this.totalSuccesses,
			totalFailures: this.totalFailures
		};
	}
	getRecentEntries(count) {
		const limit = count ?? MAX_RECENT_ENTRIES;
		return this.recentEntries.slice(-limit);
	}
	reset() {
		this.recentEntries = [];
		this.totalCalls = 0;
		this.totalSuccesses = 0;
		this.totalFailures = 0;
	}
};
const ttsStatusTracker = new TtsStatusTrackerImpl();
function recordTtsSuccess(params) {
	ttsStatusTracker.recordAttempt({
		timestamp: Date.now(),
		success: true,
		...params
	});
}
function recordTtsFailure(params) {
	ttsStatusTracker.recordAttempt({
		timestamp: Date.now(),
		success: false,
		...params
	});
}
//#endregion
export { recordTtsFailure, recordTtsSuccess, ttsStatusTracker };

//# sourceMappingURL=status-tracker.js.map