import http from "../utils/http";
import type { ShoppingCartItem, ShoppingCartDTO } from "@/types/shoppingcart";

// 获取用户购物车列表
export const getUserCartList = (userId: number) => {
  return http<ShoppingCartItem[]>({
    url: "/cart",
    method: "get",
    params: { userId },
  });
};

// 添加商品到购物车
export const addCart = (data: ShoppingCartDTO) => {
  return http({
    url: "/cart",
    method: "post",
    data,
  });
};

// 更新购物车商品数量
export const updateCartCount = (data: ShoppingCartDTO) => {
  return http({
    url: "/cart/count",
    method: "put",
    data,
  });
};

// 更新购物车商品勾选状态
export const updateCartChecked = (data: ShoppingCartDTO) => {
  return http({
    url: "/cart/checked",
    method: "put",
    data,
  });
};

// 删除购物车商品
export const deleteCart = (id: number, userId: number) => {
  return http({
    url: `/cart/${id}`,
    method: "delete",
    params: { userId },
  });
};
