import { apiGet, apiPost, apiPut } from "@/app/lib/clientApi"; import type { CatalogRow, CatalogRowPayload } from "@/app/lib/types"; // Client-side wrapper for the /catalog-setup management page (add-admin-catalog-setup). Calls // only the portal's own /api/catalog/** route handlers (mirrors app/lib/services/adminReference.ts) // — never solvway-mobile-api directly. `id` stays a string end-to-end (see CatalogRow) and is // echoed back verbatim; toggling status is a POST (mutation), never a GET, so a Next.js prefetch // can never flip a row's status. export async function listCatalogRows(list: string): Promise { return apiGet(`/api/catalog/${list}`); } /** Create: always POSTs without an id (the row gets its id upstream). */ export async function createCatalogRow( list: string, payload: CatalogRowPayload, ): Promise { return apiPost(`/api/catalog/${list}`, payload); } /** Update: PUTs to the row's own URL; the id is in the path, not the body. */ export async function updateCatalogRow( list: string, id: string, payload: CatalogRowPayload, ): Promise { return apiPut(`/api/catalog/${list}/${id}`, payload); } /** Toggle Activate/Deactivate: POST, no body — the id is in the path. */ export async function toggleCatalogRowStatus(list: string, id: string): Promise { return apiPost(`/api/catalog/${list}/${id}`); } /** Upload a brand/category image; returns its public URL. Called only on dialog submit. */ export async function uploadCatalogImage( list: string, input: { fileName: string; fileType: string; base: string }, ): Promise<{ url: string }> { return apiPost<{ url: string }>(`/api/catalog/${list}/image`, input); }