import { api } from './client'
import type { Game, Route, RouteEncounterDetail } from '../types/game'

export interface GameDetail extends Game {
  routes: Route[]
}

export function getGames(): Promise<Game[]> {
  return api.get('/games')
}

export function getGame(id: number): Promise<GameDetail> {
  return api.get(`/games/${id}`)
}

export function getGameRoutes(gameId: number): Promise<Route[]> {
  // Use flat=true to get all routes in a flat list
  // The frontend organizes them into hierarchy based on parentRouteId
  return api.get(`/games/${gameId}/routes?flat=true`)
}

export function getRoutePokemon(routeId: number, gameId?: number): Promise<RouteEncounterDetail[]> {
  const params = gameId != null ? `?game_id=${gameId}` : ''
  return api.get(`/routes/${routeId}/pokemon${params}`)
}
