const fetchFn = async (url, params = {}, method = 'GET', headers = { 'Content-Type': 'application/json' }) => {
    const res = await fetch(url, {
        method: method,
        headers: headers,
        body: JSON.stringify(params)
    })

  const data = await res.json()
  return data
}

/**
 * 机器人前往目标站点
 * @param {Object} params
 * @param {string} [params.deviceId]  - 设备ID，默认 agv_src1100
 */
export function getCurrentMapName(params) {
    return fetchFn('/api/agv/getCurrentMapName', params, 'POST')
}

export function getCurrentMap(params) {
    return fetchFn('/api/agv/getCurrentMap', params, 'POST')
}

export function getRobotState(params) {
    return fetchFn('/api/agv/getRobotState', params, 'POST')
}

export function moveRobot(params) {
    return fetchFn('/api/agv/moveRobot', params, 'POST')
}

export function stopRobot(params) {
    return fetchFn('/api/agv/stopRobot', params, 'POST')
}