/** Typed API functions for the Tiere (Rennmäuse) resource. */
import { api, resources } from './client'
import { toQueryString, type GridifyQuery } from './gridify'
import type { CreateGerbil, Gerbil, Paged, UpdateGerbil } from './types'

export function listGerbils(query: GridifyQuery): Promise<Paged<Gerbil>> {
  return api.get<Paged<Gerbil>>(`${resources.gerbils}${toQueryString(query)}`)
}

export function getGerbil(id: string): Promise<Gerbil> {
  return api.get<Gerbil>(`${resources.gerbils}/${id}`)
}

/** SEARCH-2b: distinct non-empty originBreeder (Herkunft) values, sorted. */
export function listOriginBreeders(): Promise<string[]> {
  return api.get<string[]>(`${resources.gerbils}/breeders`)
}

export function createGerbil(body: CreateGerbil): Promise<Gerbil> {
  return api.post<Gerbil>(resources.gerbils, body)
}

export function updateGerbil(id: string, body: UpdateGerbil): Promise<Gerbil> {
  return api.put<Gerbil>(`${resources.gerbils}/${id}`, body)
}

export function deleteGerbil(id: string): Promise<void> {
  return api.delete(`${resources.gerbils}/${id}`)
}
