import { useQuery } from '@tanstack/react-query'
import { getGames, getGame, getGameRoutes, getRoutePokemon } from '../api/games'

export function useGames() {
  return useQuery({
    queryKey: ['games'],
    queryFn: getGames,
  })
}

export function useGame(id: number) {
  return useQuery({
    queryKey: ['games', id],
    queryFn: () => getGame(id),
  })
}

export function useGameRoutes(gameId: number | null) {
  return useQuery({
    queryKey: ['games', gameId, 'routes'],
    queryFn: () => getGameRoutes(gameId!),
    enabled: gameId !== null,
  })
}

export function useRoutePokemon(routeId: number | null, gameId?: number) {
  return useQuery({
    queryKey: ['routes', routeId, 'pokemon', gameId],
    queryFn: () => getRoutePokemon(routeId!, gameId),
    enabled: routeId !== null,
  })
}
