import type { LobbyGameStore, LobbyGameData } from "./LobbyGameStore.js";

export class InMemoryLobbyGameStore implements LobbyGameStore {
  private games = new Map<string, LobbyGameData>();

  create(lobbyId: string, data: LobbyGameData): Promise<void> {
    if (this.games.has(lobbyId)) {
      throw new Error(`Game already exists for lobby: ${lobbyId}`);
    }
    this.games.set(lobbyId, data);
    return Promise.resolve();
  }

  get(lobbyId: string): Promise<LobbyGameData | null> {
    return Promise.resolve(this.games.get(lobbyId) ?? null);
  }

  set(lobbyId: string, data: LobbyGameData): Promise<void> {
    this.games.set(lobbyId, data);
    return Promise.resolve();
  }

  delete(lobbyId: string): Promise<void> {
    this.games.delete(lobbyId);
    return Promise.resolve();
  }
}
