"use server"; import { revalidatePath } from "next/cache"; import { winofyFetch } from "./winofy"; import { callApi, type ActionResult } from "./result"; import type { Cart } from "@/types/api"; export async function getCart(): Promise { return winofyFetch("/v1/cart/"); } export async function addToCart(productUuid: string, quantity: number = 1): Promise { const result = await callApi(() => winofyFetch("/v1/cart/items/", { method: "POST", body: { product_uuid: productUuid, quantity } }), ); if (result.ok) revalidatePath("/cart"); return result; } export async function updateCartItemQuantity(itemUuid: string, quantity: number): Promise { const result = await callApi(() => winofyFetch(`/v1/cart/items/${itemUuid}/`, { method: "PATCH", body: { quantity } }), ); if (result.ok) revalidatePath("/cart"); return result; } export async function removeCartItem(itemUuid: string): Promise { const result = await callApi(() => winofyFetch(`/v1/cart/items/${itemUuid}/`, { method: "DELETE" })); if (result.ok) revalidatePath("/cart"); return result; } export async function clearCart(): Promise { const result = await callApi(() => winofyFetch("/v1/cart/", { method: "DELETE" })); if (result.ok) revalidatePath("/cart"); return result; }