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 getDeviceList = (params: {
  page?: number;
  pageSize?: number;
  deviceId?: string;
  shopId?: number;
  status?: number;
  storeName?: string;
}) => {
  return http.request<ResultTable>("get", "/devices/list", { params });
};

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

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

export const openDoor = (id: number, data: { doorIndex?: string }) => {
  return http.request<Result>("post", `/devices/${id}/open`, { data });
};

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

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