import type { CartItem } from '@/entities/cart/model/types'
import { apiClient } from '@/shared/api/client'

export type CartResponse = { items: CartItem[] }

export async function fetchMyCart(): Promise<CartResponse> {
  const { data } = await apiClient.get<CartResponse>('me/cart')
  return data
}

export async function addToCart(body: { productId: string; qty?: number }): Promise<void> {
  await apiClient.post('me/cart/items', body)
}

export async function setCartQty(id: string, qty: number): Promise<void> {
  await apiClient.patch(`me/cart/items/${id}`, { qty })
}

export async function removeCartItem(id: string): Promise<void> {
  await apiClient.delete(`me/cart/items/${id}`)
}
