import { apiGet, apiPost, apiPatch, apiDelete } from "@/lib/api/client";

/**
 * A print/prep station (e.g. Kitchen, Bar). Each station can have its own
 * thermal printer; menu categories are routed to a station so their items print
 * on that station's printer. Items in categories with no station fall back to the
 * branch kitchen printer. See backend KitchenStation + PrintKitchenTicketAsync.
 */
export interface KitchenStation {
  id: string;
  branchId?: string | null;
  name: string;
  printerIp?: string | null;
  printerPort: number;
  sortOrder: number;
  categoryCount: number;
}

export function fetchKitchenStations(cafeId: string): Promise<KitchenStation[]> {
  return apiGet<KitchenStation[]>(`/api/cafes/${cafeId}/kitchen-stations`);
}

export function createKitchenStation(
  cafeId: string,
  body: { name: string; printerIp?: string | null; printerPort?: number; sortOrder?: number }
): Promise<KitchenStation> {
  return apiPost<KitchenStation>(`/api/cafes/${cafeId}/kitchen-stations`, body);
}

export function updateKitchenStation(
  cafeId: string,
  id: string,
  body: { name?: string; printerIp?: string | null; printerPort?: number | null; sortOrder?: number | null }
): Promise<KitchenStation> {
  return apiPatch<KitchenStation>(`/api/cafes/${cafeId}/kitchen-stations/${id}`, body);
}

export function deleteKitchenStation(cafeId: string, id: string): Promise<void> {
  return apiDelete(`/api/cafes/${cafeId}/kitchen-stations/${id}`);
}
