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

export function getWholeData(sceneCode) {
  let url = `${process.env.VUE_APP_API_URL_PREFIX}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 = `${process.env.VUE_APP_API_URL_PREFIX}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 = `${process.env.VUE_APP_API_URL_PREFIX}laser/route/resetRouteInfo/${sceneCode}`
  return axios
    .get(url).then((res) => {
      if (res?.data?.code === 200) {
        return res?.data?.msg
      } else {
        throw(res?.data?.msg || '操作失败')
      }
    })
}
export function reportTagInfo(data) {
  const url = `https://uat-laser.4dkankan.com/location/ingest`

  return axios.post(url, data).then((res) => {
    if (res?.data?.code === 200 || res?.status === 200) {
      return res?.data?.msg || 'report success'
    } else {
      throw(res?.data?.msg || 'report failed')
    }
  })
}
