import { apiFetch } from "@/lib/auth/api-client"; import { CreateOptions, idempotencyHeaders } from "@/lib/offline/idempotency"; import { CreateTreatmentInput, Treatment, UpdateTreatmentInput, WithdrawalStatus, } from "./types"; export function fetchColonyTreatments(colonyId: string): Promise { return apiFetch(`/colonies/${encodeURIComponent(colonyId)}/treatments`); } export function fetchWithdrawalStatus( colonyIds: string[], ): Promise { if (colonyIds.length === 0) { return Promise.resolve([]); } return apiFetch( `/treatments/withdrawal-status?colonyIds=${colonyIds.join(",")}`, ); } export function createTreatment( input: CreateTreatmentInput, options: CreateOptions = {}, ): Promise { return apiFetch("/treatments", { method: "POST", headers: idempotencyHeaders(options), body: JSON.stringify(input), }); } export function updateTreatment( id: string, input: UpdateTreatmentInput, ): Promise { return apiFetch(`/treatments/${encodeURIComponent(id)}`, { method: "PATCH", body: JSON.stringify(input), }); }