import axios from "axios"
import mockData from "../input-data/data3.js";

let AJAX_ORIGIN = ''
switch (process.env.NODE_ENV) {
  case 'development':
    AJAX_ORIGIN = 'https://uat-laser.4dkankan.com/'
    break;
  case 'production':
    AJAX_ORIGIN = 'https://uat-laser.4dkankan.com/'
    // AJAX_ORIGIN = 'https://laser.4dkankan.com/backend/'

    break;
  default:
    AJAX_ORIGIN = ''
    break;
}

export function getWholeData(sceneCode) {
  let url = `${AJAX_ORIGIN}laser/route/${sceneCode}/getRouteInfo`
  return axios
    .get(url)
    .then((res) => {
      if (Array.isArray(res.data.data) && res.data.data.length > 0) {
        return res.data.data
      } else {
        throw('getWholeData结果异常！')
      }
    })
}

export function uploadWholeData(sceneCode, wholeData) {
  let url = `${AJAX_ORIGIN}laser/route/${sceneCode}/editRouteInfo`
  return axios
    .post(url, {
      list: wholeData,
    }).then((res) => {
      if (res?.data?.code === 200) {
        return res?.data?.msg
      } else {
        throw(res?.data?.msg || '操作失败')
      }
    })
}

export function resetWholeData(sceneCode) {
  let url = `${AJAX_ORIGIN}laser/route/resetRouteInfo/${sceneCode}`
  return axios
    .get(url).then((res) => {
      if (res?.data?.code === 200) {
        return res?.data?.msg
      } else {
        throw(res?.data?.msg || '操作失败')
      }
    })
}