import { handlePost } from '../tools'

export default ({ service, request, serviceForMock, requestForMock, mock, faker, tools }) => ({
  /**
   * @description 方法名称
   * @param {Object} data 请求携带的信息
   */
  VERIFY_SERVER (url) {
    return request({
      auth: {
        username: 'admin',
        password: process.env.VUE_APP_HSLSERVER_PASSWORD
      },
      method: 'post',
      url: url + '/Admin/ServerSettingsRequest'
    })
  },

  MODIFY_SERVER (url, data) {
    return request({
      auth: {
        username: 'admin',
        password: process.env.VUE_APP_HSLSERVER_PASSWORD
      },
      data: data,
      method: 'post',
      url: url + '/Admin/ServerSettingsModify'
    })
  },

  ADD_SERVER: (data) => handlePost(request, data),
  UPDATE_SERVER: (data) => handlePost(request, data),
  REMOVE_SERVER: (data) => handlePost(request, data),

  QUERY_SERVERS () {
    return request({ url: '?query=servers' })
  },

  QUERY_SERVE_MONITORING () {
    return request({ url: '?query=working_subclasses' })
  },
  GET_DEVICE (serveId) {
    return request({ url: '?query=device_list&id=' + serveId })
  },
  GET_DEVICE_STATUS (serveId) {
    return request({ url: '?query=device_status&id=' + serveId })
  },
  ADD_DEVICE: (data) => handlePost(request, data),
  DEL_DEVICE: (data) => handlePost(request, data),
  GET_HSLSERVER_CONFIGURE (url) {
    return request({
      auth: {
        username: 'admin',
        password: process.env.VUE_APP_HSLSERVER_PASSWORD
      },
      method: 'post',
      url: url + '/Admin/JsonSettingsRequest'
    })
  },
  SET_HSLSERVER_CONFIGURE (url, data) {
    return request({
      auth: {
        username: 'admin',
        password: process.env.VUE_APP_HSLSERVER_PASSWORD
      },
      data: data,
      method: 'post',
      url: url + '/Admin/JsonSettingsModify'
    })
  },
  SET_DEVICE_CONFIGURE: (data) => handlePost(request, data),
  GET_DEVICE_CONFIGURE (id) {
    return request({ url: '?query=device&id=' + id })
  },
  GET_SERVE_DEVICE_MONITORING (url) {
    return request({
      auth: {
        username: 'admin',
        password: process.env.VUE_APP_HSLSERVER_PASSWORD
      },
      url: url + '/Edge/DeviceData?data=/'
    })
  },
  GET_ALL_DEVICES () {
    return request({ url: '?query=all_devices' })
  },
  SET_SERVER_EXEC: (data) => handlePost(request, data),
  GET_SERVER_DEVICE_STATUS (url) {
    return request({
      auth: {
        username: 'admin',
        password: process.env.VUE_APP_HSLSERVER_PASSWORD
      },
      url: url + '/Edge/DeviceData?data=__status'
    })
  },
  GET_DEVICE_POINT_VALUE (url, deviceName, data, type) {
    return request({
      validateStatus: (status) => {
        return status === 404 ? 200 : status
      },
      auth: {
        username: 'admin',
        password: process.env.VUE_APP_HSLSERVER_PASSWORD
      },
      data: {
        address: data
      },
      method: 'post',
      url: url + '/' + deviceName + '/Read' + type + '32'
    })
  },
  SET_DEVICE_POINT_VALUE (url, deviceName, data, type, value) {
    return request({
      auth: {
        username: 'admin',
        password: process.env.VUE_APP_HSLSERVER_PASSWORD
      },
      data: {
        address: data,
        value: value
      },
      method: 'post',
      url: url + '/' + deviceName + '/Write' + type + '32'
    })
  }
})
