/**
 * Model override for a specific session (set via /sf model pin in auto-mode).
 */
export interface SessionModelOverride {
	provider: string;
	id: string;
}

const sessionOverrides = new Map<string, SessionModelOverride>();

function normalizeSessionId(sessionId: string): string {
	return typeof sessionId === "string" ? sessionId.trim() : "";
}

/**
 * Store a model override for a session (e.g., from /sf model command in auto-mode).
 */
export function setSessionModelOverride(
	sessionId: string,
	override: SessionModelOverride,
): void {
	const key = normalizeSessionId(sessionId);
	if (!key) return;
	sessionOverrides.set(key, {
		provider: override.provider,
		id: override.id,
	});
}

/**
 * Retrieve the model override for a session, if one was set.
 */
export function getSessionModelOverride(
	sessionId: string,
): SessionModelOverride | undefined {
	const key = normalizeSessionId(sessionId);
	if (!key) return undefined;
	return sessionOverrides.get(key);
}

/**
 * Clear the model override for a session (e.g., at auto-mode end).
 */
export function clearSessionModelOverride(sessionId: string): void {
	const key = normalizeSessionId(sessionId);
	if (!key) return;
	sessionOverrides.delete(key);
}
