import AsyncStorage from '@react-native-async-storage/async-storage';
import { GameType } from '../components/urge/UrgeGames';

const key = (game: GameType) => `rebreak_best_${game}`;

export async function getBestScore(game: GameType): Promise<number> {
  const raw = await AsyncStorage.getItem(key(game));
  return raw ? parseInt(raw) || 0 : 0;
}

export async function saveBestScore(game: GameType, score: number): Promise<void> {
  const current = await getBestScore(game);
  if (score > current) {
    await AsyncStorage.setItem(key(game), String(score));
  }
}
