import request from '@/utils/request'

// 查询参数列表
export function listConfig (query) {
  return request({
    url: '/system/config/list',
    method: 'get',
    params: query
  })
}

// 查询参数详细
export function getConfig (configId) {
  return request({
    url: '/api/system/config/get/' + configId,
    method: 'get'
  })
}

// 根据参数键名查询参数值
export function getConfigKey (configKey) {
  return request({
    url: '/api/system/config/configKey/' + configKey,
    method: 'get'
  })
}

// 新增参数配置
export function addConfig (data) {
  return request({
    url: '/system/config/add',
    method: 'post',
    data: data
  })
}

// 修改参数配置
export function updateConfig (data) {
  return request({
    url: '/system/config/edit',
    method: 'post',
    data: data
  })
}

// 删除参数配置
export function delConfig (configId) {
  return request({
    url: '/system/config/remove/' + configId,
    method: 'get'
  })
}

// 清理参数缓存
export function clearCache () {
  return request({
    url: '/system/config/clearCache',
    method: 'get'
  })
}

// 导出参数
export function exportConfig (query) {
  return request({
    url: '/system/config/export',
    method: 'get',
    params: query
  })
}

//查询geoserver服务地址
export function getGeoServerConfigKey () {
  return request({
    url: '/system/config/configKey/' + "system.geoServer.url",
    method: 'get'
  })
}

// 查询application.yml键值
export function propValue (key) {
  return request({
    url: '/system/config/prop/' + key,
    method: 'get'
  })
}
export function getProperty (key, def) {
  return propValue(key).then((resp) => {
    return new Promise(function (resolve, reject) {
      resolve(resp.code == 200 && resp.data !== null ? resp.data : def);
    });
  }).catch((e) => {
    return new Promise(function (resolve, reject) {
      resolve(def);
    });
  });
}

export function usingExternalUploadService () {
  return request({
    url: '/system/config/usingExternalUploadService',
    method: 'get'
  })
}
