import request from '@/utils/request'

// ==================== MQTT消息发送API ====================
// 对接 MqttController.java，提供HTTP接口调用MQTT消息发送

/**
 * 发送MQTT消息（通用接口）
 */
export function sendMqttMessage(topic, payload) {
  return request({
    url: '/mqtt/sendMessage',
    method: 'post',
    params: { topic, payload }
  })
}

// ==================== LD导航系统接口 ====================

/**
 * 请求地图列表
 */
export function requestMapList() {
  return request({
    url: '/mqtt/ld/map/list',
    method: 'post'
  })
}

/**
 * 位姿初始化(坐标)
 */
export function initPose(x, y, yaw) {
  return request({
    url: '/mqtt/ld/localization/init',
    method: 'post',
    params: {x, y, yaw }
  })
}

/**
 * 位姿初始化(路网点ID)
 */
export function initPoseByNid(nid) {
  return request({
    url: '/mqtt/ld/localization/initByNid',
    method: 'post',
    params: { nid }
  })
}

/**
 * 开启导航
 */
export function startNavigation(mapName) {
  return request({
    url: '/mqtt/ld/navigation/start',
    method: 'post',
    params: { mapName }
  })
}

/**
 * 关闭导航
 */
export function stopNavigation() {
  return request({
    url: '/mqtt/ld/navigation/stop',
    method: 'post'
  })
}

/**
 * 重启导航
 */
export function restartNavigation(mapName) {
  return request({
    url: '/mqtt/ld/navigation/restart',
    method: 'post',
    params: { mapName }
  })
}

/**
 * 启动标准导航 (ASM.nav_standard.start)
 */
export function startNavStandard(mapName) {
  return request({
    url: '/mqtt/nav/standard/start',
    method: 'post',
    params: { mapName }
  })
}

// ==================== 任务操作接口 ====================

/**
 * 前往目标点(路网点ID)
 */
export function gotoTargetByNid(mapName, nid) {
  return request({
    url: '/mqtt/ld/task/gotoByNid',
    method: 'post',
    params: { mapName, nid }
  })
}

/**
 * 前往目标点(坐标)
 */
export function gotoTargetByCoord( mapName, x, y) {
  return request({
    url: '/mqtt/ld/task/gotoByCoord',
    method: 'post',
    params: { mapName, x, y }
  })
}

/**
 * 暂停任务
 */
export function pauseTask() {
  return request({
    url: '/mqtt/ld/task/pause',
    method: 'post'
  })
}

/**
 * 继续任务
 */
export function resumeTask() {
  return request({
    url: '/mqtt/ld/task/resume',
    method: 'post'
  })
}

/**
 * 取消任务
 */
export function cancelTask() {
  return request({
    url: '/mqtt/ld/task/cancel',
    method: 'post'
  })
}

// ==================== 规划操作接口 ====================

/**
 * 遇障重规划
 */
export function replan() {
  return request({
    url: '/mqtt/ld/planning/replan',
    method: 'post'
  })
}

/**
 * 请求路径规划
 */
export function requestPlanning(mapName, x, y) {
  return request({
    url: '/mqtt/planning/plan/request',
    method: 'post',
    params: { mapName, x, y }
  })
}

/**
 * 前往目标点(坐标) - 包含规划请求
 */
export function gotoTarget(mapName, x, y) {
  return request({
    url: '/mqtt/ld/task/gotoByCoord',
    method: 'post',
    params: { mapName, x, y }
  })
}

/**
 * 启动任务
 */
export function startTask( mapName, taskName) {
  return request({
    url: '/mqtt/task/procedure/start',
    method: 'post',
    params: { mapName, taskName }
  })
}

// ==================== 急停操作接口 ====================

/**
 * 紧急停止
 * @param {string} deviceId 设备ID
 * @param {boolean} type true-急停, false-释放
 */
export function emergencyStop(type = true) {
  return request({
    url: '/mqtt/emergency/stop',
    method: 'post',
    params: {type }
  })
}

/**
 * 释放急停
 */
export function releaseEmergencyStop() {
  return request({
    url: '/mqtt/emergency/release',
    method: 'post'
  })
}
