// Synthetic battle reports for DEV / e2e mode.
//
// Mirrors the shape of `pkg/model/report/battle.go` so the
// BattleViewer can be exercised without a running engine. Fixtures
// are registered by battle UUID; the synthetic-report loader fills
// the report's `battles[]` with these same UUIDs so the report ↔
// battle link is consistent.

import type { BattleReport } from "./battle-fetch";

const SYNTHETIC_BATTLES = new Map<string, BattleReport>();

/**
 * registerSyntheticBattle adds a fixture battle to the in-memory map
 * keyed by its `id`. Used by the synthetic-report DEV loader and by
 * Vitest unit tests that need a deterministic BattleReport without a
 * live engine.
 */
export function registerSyntheticBattle(report: BattleReport): void {
	SYNTHETIC_BATTLES.set(report.id, report);
}

/**
 * lookupSyntheticBattle returns the fixture stored under `battleId`,
 * or `null` if nothing was registered (mirrors the engine's 404).
 */
export function lookupSyntheticBattle(battleId: string): BattleReport | null {
	return SYNTHETIC_BATTLES.get(battleId) ?? null;
}

/**
 * resetSyntheticBattles clears every registered fixture. Test
 * harnesses call this between cases to avoid bleed-through.
 */
export function resetSyntheticBattles(): void {
	SYNTHETIC_BATTLES.clear();
}
