/** RÜCKNAHMEN: API-Client für zurückgenommene Tiere (/returns). */
import { api } from './client'

const RESOURCE = '/returns'

/** Payload für POST/PUT /returns. */
export interface ReturnRecordInput {
  gerbilId?: string | null
  gerbilName?: string | null
  returnDate?: string | null
  returnPrice?: number | null
  originalPrice?: number | null
  originalSaleDate?: string | null
  fromContactId?: string | null
  fromContactName?: string | null
  note?: string | null
}

export interface ReturnRecord {
  id: string
  gerbilId: string | null
  gerbilName: string | null
  returnDate: string | null
  returnPrice: number | null
  originalPrice: number | null
  originalSaleDate: string | null
  fromContactId: string | null
  fromContactName: string | null
  note: string | null
  createdAt: string
}

export function listReturns(gerbilId?: string): Promise<ReturnRecord[]> {
  const q = gerbilId ? `?gerbilId=${encodeURIComponent(gerbilId)}` : ''
  return api.get<ReturnRecord[]>(`${RESOURCE}${q}`)
}

export function createReturn(body: ReturnRecordInput): Promise<ReturnRecord> {
  return api.post<ReturnRecord>(RESOURCE, body)
}

export function updateReturn(id: string, body: ReturnRecordInput): Promise<ReturnRecord> {
  return api.put<ReturnRecord>(`${RESOURCE}/${id}`, body)
}

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