import type { GamePrepResponse } from "../api/types";

const KEY_PREFIX = "walkup-prep:";

export function savePreparedGame(gameId: string, payload: GamePrepResponse): void {
  localStorage.setItem(`${KEY_PREFIX}${gameId}`, JSON.stringify(payload));
}

export function loadPreparedGame(gameId: string): GamePrepResponse | null {
  const raw = localStorage.getItem(`${KEY_PREFIX}${gameId}`);
  if (!raw) {
    return null;
  }
  try {
    return JSON.parse(raw) as GamePrepResponse;
  } catch {
    return null;
  }
}
