import { api } from './client'
import type { Genlocke, GenlockeListItem, GenlockeDetail, GenlockeGraveyard, GenlockeLineage, CreateGenlockeInput, Region, SurvivorEncounter, AdvanceLegInput } from '../types/game'

export function getGenlockes(): Promise<GenlockeListItem[]> {
  return api.get('/genlockes')
}

export function getGenlocke(id: number): Promise<GenlockeDetail> {
  return api.get(`/genlockes/${id}`)
}

export function createGenlocke(data: CreateGenlockeInput): Promise<Genlocke> {
  return api.post('/genlockes', data)
}

export function getGamesByRegion(): Promise<Region[]> {
  return api.get('/games/by-region')
}

export function getGenlockeGraveyard(id: number): Promise<GenlockeGraveyard> {
  return api.get(`/genlockes/${id}/graveyard`)
}

export function getGenlockeLineages(id: number): Promise<GenlockeLineage> {
  return api.get(`/genlockes/${id}/lineages`)
}

export function getLegSurvivors(genlockeId: number, legOrder: number): Promise<SurvivorEncounter[]> {
  return api.get(`/genlockes/${genlockeId}/legs/${legOrder}/survivors`)
}

export function advanceLeg(genlockeId: number, legOrder: number, data?: AdvanceLegInput): Promise<Genlocke> {
  return api.post(`/genlockes/${genlockeId}/legs/${legOrder}/advance`, data ?? {})
}
