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

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

/** 从 ERP 同步系统商品数据 */
export const syncErpGoods = () =>
  http.request<Result>("post", "/erp-goods/sync");

/** 分页获取已缓存的 ERP 商品列表 */
export const getErpGoodsList = (params: { keyword?: string; page: number; pageSize: number }) =>
  http.request<Result>("get", "/erp-goods", { params });

/** 关联本地商品与 ERP 商品 */
export const bindErpGoods = (productId: number, erpGoodsId: number) =>
  http.request<Result>("post", "/erp-goods/bind", { data: { productId, erpGoodsId } });

/** 解除本地商品与 ERP 商品的关联 */
export const unbindErpGoods = (productId: number) =>
  http.request<Result>("post", "/erp-goods/unbind", { data: { productId } });

/** 一键自动关联：按 goodsCode 匹配本地商品名称 */
export const autoBindErpGoods = () =>
  http.request<Result>("post", "/erp-goods/auto-bind");
