/**分页查询接口重试日志 */
import request from '@/utils/request'
// import { SERVICE_DATA_API_BASE } from '@/config/serviceSettings.js'
const serviceName = '/api/upcloud-base-common'

//分页查询接口重试日志 GET
export const mainTableInfoUrl = serviceName + '/datasource/v1/page'

function responseThen(response) {
  if (response.success) {
    this.visible = false
    this.$message.success(response.message)
  } else {
    this.$exception(response)
  }
  this.confirmLoading = false
  return response
}
export const getDrives = data => {
  return request({
    url: serviceName + '/datasource/v1/drivers',
    method: 'get',
    data
  }).then(response => {
    if (response.success) {
      return response.data
    } else {
      this.$exception(response)
      return false
    }
  })
}

export const addFormItem = (_this, data) => {
  _this.confirmLoading = true
  return request({
    url: serviceName + '/datasource/v1/add',
    method: 'post',
    data
  }).then(responseThen.bind(_this))
}

export const updateFormItem = (_this, data) => {
  _this.confirmLoading = true
  return request({
    url: serviceName + '/datasource/v1/update',
    method: 'post',
    data
  }).then(responseThen.bind(_this))
}



//删除告警记录
export const deleteFormItem = (context, id) => {

  return new Promise(resolve => {
    context.$confirm({
      title: '是否删除?',
      confirmLoading: context.spinning,
      onOk(clear) {
        context.spinning = true
        return request({
          url: serviceName + '/datasource/v1/delete',
          method: 'post',
          params: {id}
        }).then(response => {
          if (response.success) {
            clear()
            context.$refs.table.reload()
          } else {
            context.$exception(response)
          }
          context.spinning=false
          return resolve(response)
        })
      }

    })
  })
}

// 测试数据源 POST
export const testDateSource =(context,data)  => {
  return request({
    url: serviceName + '/datasource/v1/test',
    method: 'post',
    data
  }).then(response => {
    if (response.success) {
      context.$message.success(response.message)
    } else {
      context.$exception(response)
    }
    return response

  })
}


