/** Typed API functions for the Becken (Enclosure) resource. (FEAT-2) */
import { api, resources } from './client'
import { toQueryString, type GridifyQuery } from './gridify'
import type { Enclosure, Paged } from './types'

/** Payload for POST /enclosures. */
export interface CreateEnclosure {
  name: string
  notes?: string | null
}

/** Payload for PUT /enclosures/{id}. */
export type UpdateEnclosure = Partial<CreateEnclosure>

export function listEnclosuresPaged(query: GridifyQuery): Promise<Paged<Enclosure>> {
  return api.get<Paged<Enclosure>>(`${resources.enclosures}${toQueryString(query)}`)
}

export function getEnclosure(id: string): Promise<Enclosure> {
  return api.get<Enclosure>(`${resources.enclosures}/${id}`)
}

export function createEnclosure(body: CreateEnclosure): Promise<Enclosure> {
  return api.post<Enclosure>(resources.enclosures, body)
}

export function updateEnclosure(id: string, body: UpdateEnclosure): Promise<Enclosure> {
  return api.put<Enclosure>(`${resources.enclosures}/${id}`, body)
}

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