import instance from "@/util/request";
import apiHandler from "@/util/apiHandler";
import {
  POST_SETTING_POINT_API,
  GET_SETTING_TYPE_API,
  POST_SETTING_TYPE_API,
} from "./api";

export const postProductSettingPoint = async (type, devices) => {
  const res = await instance.post(POST_SETTING_POINT_API, {
    devices: devices.map(({ device_number }) => device_number),
    values: [
      {
        point: "Type",
        value: type.value,
      },
    ],
  });

  return apiHandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
    isSuccess: false,
  });
};

export const getProductSettingType = async () => {
  const res = await instance.post(GET_SETTING_TYPE_API);

  return apiHandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
    isSuccess: false,
  });
};

export const postProductSettingType = async (data) => {
  const res = await instance.post(POST_SETTING_TYPE_API, data);

  return apiHandler(res.code, res.data, {
    msg: res.msg,
    code: res.code,
    isSuccess: false,
  });
};
