import { http } from "@/utils/http";

type Result = {
  code: number;
  message: string;
  data?: any;
};

type ResultTable = {
  code: number;
  message: string;
  data?: {
    list: Array<any>;
    total: number;
    pageSize: number;
    currentPage: number;
  };
};

export const getProductList = (params: {
  page?: number;
  pageSize?: number;
  name?: string;
  barcode?: string;
  category?: string;
  syncStatus?: number;
}) => {
  return http.request<ResultTable>("get", "/products/list", { params });
};

export const getProductById = (id: number) => {
  return http.request<Result>("get", `/products/${id}`);
};

export const getProductStatistics = () => {
  return http.request<Result>("get", "/products/statistics");
};

export const addProduct = (data: any) => {
  return http.request<Result>("post", "/products", { data });
};

export const updateProduct = (id: number, data: any) => {
  return http.request<Result>("put", `/products/${id}`, { data });
};

export const deleteProduct = (id: number) => {
  return http.request<Result>("delete", `/products/${id}`);
};

export const syncProduct = (id: number) => {
  return http.request<Result>("post", `/products/${id}/sync`);
};
