/**
 * Lookup resources used to populate form dropdowns (Farbschlag, Becken,
 * Kontakte, Würfe). These endpoints are Gridify-paged like the rest; for
 * dropdowns we request a large page and read `.items`.
 */
import { api, resources } from './client'
import { toQueryString } from './gridify'
import type { ColorVariety, Contact, Enclosure, Litter, Paged } from './types'

const ALL = toQueryString({ page: 1, pageSize: 1000, orderBy: 'name' })

export async function listColorVarieties(): Promise<ColorVariety[]> {
  const paged = await api.get<Paged<ColorVariety>>(
    `${resources.colorVarieties}${toQueryString({ page: 1, pageSize: 1000, orderBy: 'sortOrder' })}`,
  )
  return paged.items
}

export async function listEnclosures(): Promise<Enclosure[]> {
  const paged = await api.get<Paged<Enclosure>>(`${resources.enclosures}${ALL}`)
  return paged.items
}

export async function listContacts(): Promise<Contact[]> {
  const paged = await api.get<Paged<Contact>>(`${resources.contacts}${ALL}`)
  return paged.items
}

export async function listLitters(): Promise<Litter[]> {
  const paged = await api.get<Paged<Litter>>(
    `${resources.litters}${toQueryString({ page: 1, pageSize: 1000, orderBy: 'date desc' })}`,
  )
  return paged.items
}
