import request from '@/config/request';

export const APIDevice = {
  addPolygonFence,
  editPolygonFence,
  delPolygonFence,
  getPolygonFence,
  deleteGeofence, //删除围栏
  getAllFence, //获取全部围栏列表
  geofenceList, //围栏列表
  editGeofence, //编辑围栏
  addGeofence, //增加围栏
  getPersonInfo, //获取宝贝信息
  deviceTimeRelatedParam, //查看设备激活时间,有效时间
  updatePersonInfo, //编辑宝贝信息
  bindingScan, //设备绑定-扫码
  bindingInput, //设备绑定-输入
  deviceList, //获取设备列表
  locateInstance, //立即定位设备
  sendCommand, //发送一个指令给设备
  unbindDevice, //解绑设备
  getCallLogList, //通话清单
  setSMSLog, //短信代收
  getDeviceStep, //健康计步
  temperatureInfoList, //健康温度
  historyDetailList, //查询设备历史轨迹
  historyDetailListByIMEI, //根据时间段查看设备历史轨迹
  history, //历史轨迹
  bindDevice, //绑定设备
  bindDeviceSsjl, //设备绑定, 只接受
  bindDeviceResult, //设备绑定结果
  addVoiceMessage, //上传录音文件
  queryVoicePage, //获取分页
  decodeSerialNo, //通过密文解析获取imei
  LckjCreateOrderPackage, //零川物联网卡加油包订购
  LckjGetOrderPackageShow, //查询零川物联网卡加油包订购记录
  checkWxPayResult, //查询微信支付状态
  updateDrownReportAiStatus, //修改溺水告警状态(ai-呼叫)
  psychQuestionAutoCommit //自动提交心里问卷调查答案
};
const baseUrl =
  process.env.NODE_ENV === 'production'
    ? 'https://ai.ssjlai.com/telpopay/api/wx/order/callback'
    : 'https://id.ssjlai.com/telpopay/api/wx/order/callback';
export default APIDevice;
// 增加多边形围栏
function addPolygonFence({ fencePoints, fenceName, serialNo, appType, address }) {
  return request({
    url: '/api/Geofence/AddPolygonFence',
    method: 'post',
    headers: { AuthKey: 'key1' },
    data: { fencePoints, fenceName, serialNo, appType, address }
  });
}

// 修改多边形围栏
function editPolygonFence({ fenceId, fencePoints, fenceName, serialNo, address }) {
  return request({
    url: '/api/Geofence/EditPolygonFence',
    method: 'post',
    headers: { AuthKey: 'key1' },
    data: { fenceId, fencePoints, fenceName, serialNo, address }
  });
}

// 删除多边形围栏
function delPolygonFence({ geofenceId }) {
  return request({
    url: '/api/Geofence/DeletePolygonFence',
    method: 'post',
    headers: { AuthKey: 'key1' },
    data: { geofenceId }
  });
}
// 删除围栏
function deleteGeofence(params) {
  return request({
    url: '/api/Geofence/Delete',
    method: 'post',
    data: params
  });
}

// 获取全部围栏：包括圆形和多边形
function getPolygonFence(serialNo) {
  return request({
    url: '/api/Geofence/GetPolygonFence',
    method: 'get',
    headers: { AuthKey: 'key1' },
    params: { serialNo }
  });
}

// 获取全部围栏：包括圆形和多边形
function getAllFence(deviceId) {
  return request({
    url: '/api/Geofence/GeofenceList',
    method: 'post',
    data: { deviceId }
  });
}

//  围栏列表
function geofenceList(params) {
  return request({
    url: '/api/Geofence/GeofenceList',
    method: 'post',
    data: params
  });
}
// 编辑围栏
function editGeofence(params) {
  return request({
    url: '/api/Geofence/Edit',
    method: 'post',
    data: params
  });
}

// 增加围栏
function addGeofence(params) {
  return request({
    url: '/api/Geofence/Add',
    method: 'post',
    data: params
  });
}
// 获取宝贝信息
function getPersonInfo(params) {
  return request({
    url: '/api/Device/GetPersonInfo',
    method: 'post',
    data: params
  });
}
//查看设备激活时间,有效时间
function deviceTimeRelatedParam(sn) {
  return request({
    url: '/api/DeviceFeatures/DeviceTimeRelatedParam',
    method: 'get',
    headers: { AuthKey: 'key1' },
    params: { sn }
  });
}
//  编辑宝贝信息
function updatePersonInfo(params) {
  return request({
    url: '/api/Device/UpdatePersonInfo',
    method: 'post',
    data: params
  });
}
// 设备绑定-扫码
function bindingScan({ url }) {
  return request({
    url: '/api/Device/BindingScan',
    method: 'post',
    data: { url }
  });
}
// 通过密文解析获取imei
function decodeSerialNo({ code }) {
  return request({
    url: '/api/Device/DecodeImei',
    method: 'post',
    headers: { authKey: 'key1' },
    data: { code }
  });
}
// 设备绑定-输入
function bindingInput({ serialNo }) {
  return request({
    url: '/api/Device/BindingInput',
    method: 'post',
    data: { serialNo }
  });
}
// 获取设备列表
function deviceList(params) {
  return request({
    url: '/api/Location/DeviceList',
    method: 'post',
    data: params
  });
}
//立即定位设备
function locateInstance(params) {
  return request({
    url: '/api/Command/LocateInstance',
    method: 'post',
    data: params
  });
}
//发送一个指令给设备
function sendCommand(params) {
  return request({
    url: '/api/Command/SendCommand',
    method: 'post',
    data: params
  });
}
//解绑设备
function unbindDevice(params) {
  return request({
    url: '/api/Device/UnbindDevice',
    method: 'post',
    data: params
  });
}
//通话清单
function getCallLogList(params) {
  return request({
    url: '/api/DeviceCommunication/GetCallLogList',
    method: 'post',
    data: params
  });
}
//短信代收
function setSMSLog(params) {
  return request({
    url: '/api/DeviceCommunication/SetSMSLog',
    method: 'post',
    data: params
  });
}
//健康计步
function getDeviceStep(params) {
  return request({
    url: '/api/DeviceFeatures/GetDeviceStep',
    method: 'post',
    data: params
  });
}
//健康温度
function temperatureInfoList({ sn, c }) {
  return request({
    url: '/api/DeviceFeatures/TemperatureInfoList',
    method: 'get',
    headers: { authKey: 'key1' },
    params: { sn, c }
  });
}

//查询设备历史轨迹
function historyDetailList({ imei, queryDate }) {
  return request({
    url: '/api/Location/HistoryDetailList',
    method: 'get',
    params: { imei, queryDate }
  });
}
//根据时间段查询设备历史轨迹
function historyDetailListByIMEI(params) {
  return request({
    url: '/api/Location/HistoryListByIMEI',
    method: 'post',
    data: params
  });
}
//历史轨迹
function history(params) {
  return request({
    url: '/api/Location/History',
    method: 'post',
    data: params
  });
}

// 设备绑定
function bindDevice({ headers, body }) {
  return request({
    url: '/api/Device/BindDevice',
    method: 'post',
    headers: headers,
    data: body
  });
}

// 设备绑定,只接收
function bindDeviceSsjl({ headers, body }) {
  return request({
    url: '/api/Device/BindDeviceSsjl',
    method: 'post',
    headers: headers,
    data: body
  });
}

//  设备绑定结果
function bindDeviceResult({ headers, body }) {
  return request({
    url: '/api/Device/BindDeviceResult',
    method: 'post',
    headers: headers,
    data: body
  });
}

//  上传录音文件
function addVoiceMessage(params) {
  return request({
    url: '/voicemessage/voiceMessage/addVoiceMessage',
    method: 'post',
    data: params
  });
}
//  获取录音文件和文字留言分页
function queryVoicePage({ gpsUserId, pageNum, pageSize }) {
  return request({
    url: '/voicemessage/voiceMessage/queryVoicePage',
    method: 'get',
    params: { gpsUserId, pageNum, pageSize }
  });
}

// 随手精灵(零川物联卡加油包套餐订购)
function LckjCreateOrderPackage(params) {
  return request({
    url: 'api/IOTCard/LckjCreateOrderPackage',
    method: 'post',
    data: params
  });
}

// 随手精灵(查询零川物联卡加油包已订购套餐)
function LckjGetOrderPackageShow({ iccid, imei }) {
  return request({
    url: '/api/IOTCard/LckjGetOrderPackageShow',
    method: 'get',
    params: { iccid, imei }
  });
}

function checkWxPayResult(params) {
  return request({
    url: `${baseUrl}`,
    method: 'post',
    data: params
  });
}

function updateDrownReportAiStatus(data) {
  return request({
    url: '/api/Device/UpdateDrownReportAiStatus',
    method: 'get',
    params: data
  });
}
function psychQuestionAutoCommit(data) {
  return request({
    url: '/api/Device/PsychQuestionAutoCommit',
    method: 'get',
    params: data
  });
}
