2026-02-05 15:09:14 +01:00
|
|
|
import { api } from './client'
|
2026-02-05 15:28:50 +01:00
|
|
|
import type { Game, Route, RouteEncounterDetail } from '../types/game'
|
2026-02-05 15:09:14 +01:00
|
|
|
|
|
|
|
|
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}`)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 12:22:05 +01:00
|
|
|
export function getGameRoutes(gameId: number, allowedTypes?: string[]): Promise<Route[]> {
|
2026-02-06 11:07:45 +01:00
|
|
|
// Use flat=true to get all routes in a flat list
|
|
|
|
|
// The frontend organizes them into hierarchy based on parentRouteId
|
2026-02-21 12:22:05 +01:00
|
|
|
const params = new URLSearchParams({ flat: 'true' })
|
|
|
|
|
for (const t of allowedTypes ?? []) params.append('allowed_types', t)
|
|
|
|
|
return api.get(`/games/${gameId}/routes?${params}`)
|
2026-02-05 15:09:14 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-16 20:39:41 +01:00
|
|
|
export function getRoutePokemon(routeId: number, gameId?: number): Promise<RouteEncounterDetail[]> {
|
2026-02-08 12:07:42 +01:00
|
|
|
const params = gameId != null ? `?game_id=${gameId}` : ''
|
|
|
|
|
return api.get(`/routes/${routeId}/pokemon${params}`)
|
2026-02-05 15:09:14 +01:00
|
|
|
}
|