import http from "../utils/http";
import type {
  // ProductListItem,
  ProductCategory,
  ProductDetail,
  ProductDTO,
  ProductPageParams,
  ProductPageResponse,
} from "@/types/product";

// 获取商品列表
export const getProductList = (params: ProductPageParams) => {
  return http<ProductPageResponse>({
    url: "/product/page",
    method: "get",
    params,
  });
};

// 获取商品分类
export const getProductCategories = () => {
  return http<ProductCategory[]>({
    url: "/product/category",
    method: "get",
  });
};

// 获取子分类
export const getProductSubCategories = (id: number) => {
  return http<ProductCategory[]>({
    url: `/product/category/${id}`,
    method: "get",
  });
};

// 获取商品详情
export const getProductDetail = (id: number) => {
  return http<ProductDetail>({
    url: `/product/${id}`,
    method: "get",
  });
};

// 新增商品
export const saveProduct = (data: ProductDTO) => {
  return http({
    url: "/product",
    method: "post",
    data,
  });
};

// 更新商品
export const updateProduct = (data: ProductDTO) => {
  return http({
    url: "/product",
    method: "put",
    data,
  });
};

// 更新商品状态（上下架）
export const updateProductStatus = (id: number, status: number) => {
  return http({
    url: `/product/status/${id}/${status}`,
    method: "put",
  });
};
