import { getClient, createConnection, clientPublish, clientSubscribe } from '@/utils/mqtt';
import { airPortStore } from '@/store/modules/airport';
import errorCode from './error_code.json';

const airPortStoreVal = airPortStore();
const airPort = airPortStoreVal.getAirport;
const uav = airPortStoreVal.getUAV;
export const debug_mode_openOptions = {
  canceled: '取消或终止',
  failed: '失败',
  in_progress: '执行中',
  ok: '执行成功',
  paused: '暂停',
  rejected: '拒绝',
  sent: '已下发',
  timeout: '超时',
};
export const cover_stateOptions = { '0': '关闭', '1': '打开', '2': '半开', '3': '舱盖状态异常' };
export const cover_opensStatus = {
  canceled: '取消或终止',
  failed: '失败',
  in_progress: '执行中',
  ok: '执行成功',
  paused: '暂停',
  rejected: '拒绝',
  sent: '已下发',
  timeout: '超时',
};

export const errorName = (code) => {
  const error_code = errorCode.error_code;
  if (error_code[code]) {
    return error_code[code];
  } else {
    return '错误码' + code;
  }
};
export const servicesTopic = (data) => {
  // 发送消息
  clientPublish('thing/product/' + airPort.sn + '/services', data);
};
export const services_replyTopic = () => {
  // 订阅消息
  clientSubscribe('thing/product/' + airPort.sn + '/services_reply');
};
// 无人机
export const servicesUAVTopic = (data) => {
  // 发送消息
  clientPublish('thing/product/' + uav.sn + '/services', data);
};
export const services_replyUAVTopic = () => {
  // 订阅消息
  clientSubscribe('thing/product/' + uav.sn + '/services_reply');
};
export const eventsTopic = (data) => {
  // 发送消息
  clientPublish('thing/product/' + airPort.sn + '/events', data);
};
export const events_replyTopic = () => {
  // 订阅消息
  clientSubscribe('thing/product/' + airPort.sn + '/events_reply');
};
export const drcDownTopic = (data) => {
  // 发送消息thing/product/{gateway_sn}/drc/down
  clientPublish('thing/product/' + airPort.sn + '/drc/down', data);
};

export const eventsTopicSubscribe = () => {
  // 发送消息
  clientSubscribe('thing/product/' + airPort.sn + '/events');
};
export const drcUpTopic = () => {
  clientSubscribe('thing/product/' + airPort.sn + '/drc/up');
};

export const setTopic = (data) => {
  // 发送消息
  clientPublish('thing/product/' + airPort.sn + '/property/set', data);
};
export const set_replyTopic = () => {
  // 订阅消息
  clientSubscribe('thing/product/' + airPort.sn + '/services_reply');
};
