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 getShopList = (params: {
  page?: number;
  pageSize?: number;
  name?: string;
  city?: string;
  status?: number;
}) => {
  return http.request<ResultTable>("get", "/shops/list", { params });
};

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

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

export const getEnabledShops = () => {
  return http.request<Result>("get", "/shops/enabled");
};

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

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

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

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

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

export const linkDevice = (id: number, data: { deviceId: number }) => {
  return http.request<Result>("post", `/shops/${id}/devices`, { data });
};

export const batchLinkDevices = (id: number, data: { deviceIds: number[] }) => {
  return http.request<Result>("post", `/shops/${id}/devices/batch`, { data });
};

export const unlinkDevice = (shopId: number, deviceId: number) => {
  return http.request<Result>("delete", `/shops/${shopId}/devices/${deviceId}`);
};

export const batchUnlinkDevices = (
  id: number,
  data: { deviceIds: number[] }
) => {
  return http.request<Result>("delete", `/shops/${id}/devices/batch`, { data });
};

export const getUnlinkedDevices = () => {
  return http.request<Result>("get", "/shops/unlinked-devices");
};

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

export const addReplenisherToShop = (id: number, data: { replenisherId: number }) => {
  return http.request<Result>("post", `/shops/${id}/replenishers`, { data });
};
