import { api } from './client'
import type {
  EncounterDetail,
  CreateEncounterInput,
  UpdateEncounterInput,
  Evolution,
  Pokemon,
} from '../types/game'

export function createEncounter(
  runId: number,
  data: CreateEncounterInput,
): Promise<EncounterDetail> {
  return api.post(`/runs/${runId}/encounters`, data)
}

export function updateEncounter(
  id: number,
  data: UpdateEncounterInput,
): Promise<EncounterDetail> {
  return api.patch(`/encounters/${id}`, data)
}

export function deleteEncounter(id: number): Promise<void> {
  return api.del(`/encounters/${id}`)
}

export function fetchEvolutions(pokemonId: number, region?: string): Promise<Evolution[]> {
  const params = region ? `?region=${encodeURIComponent(region)}` : ''
  return api.get(`/pokemon/${pokemonId}/evolutions${params}`)
}

export function fetchForms(pokemonId: number): Promise<Pokemon[]> {
  return api.get(`/pokemon/${pokemonId}/forms`)
}

export function bulkRandomizeEncounters(runId: number): Promise<{ created: unknown[]; skippedRoutes: number }> {
  return api.post(`/runs/${runId}/encounters/bulk-randomize`, {})
}
