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

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

/** 从 ERP 同步店铺数据 */
export const syncErpShops = () =>
  http.request<Result>("post", "/erp-shops/sync");

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

/** 绑定设备与 ERP 店铺 */
export const bindErpShop = (deviceId: number, erpShopId: number) =>
  http.request<Result>("post", "/erp-shops/bind", { data: { deviceId, erpShopId } });

/** 解除设备与 ERP 店铺的绑定 */
export const unbindErpShop = (deviceId: number) =>
  http.request<Result>("post", "/erp-shops/unbind", { data: { deviceId } });

/** 一键自动绑定：按 shopCode 匹配设备 deviceId */
export const autoBindErpShop = () =>
  http.request<Result>("post", "/erp-shops/auto-bind");

/** 一键解绑所有设备 */
export const unbindAllErpShop = () =>
  http.request<Result>("post", "/erp-shops/unbind-all");

/** 批量修改允许绑定标识 */
export const batchUpdateBindEnabled = (erpShopIds: number[], bindEnabled: number) =>
  http.request<Result>("post", "/erp-shops/batch-bind-enabled", { data: { erpShopIds, bindEnabled } });
