
import request from '@/utils/request'
import qs from 'qs'
import { SERVICE_DATA_API_BASE, upcloud_base_common } from '@/config/serviceSettings.js'
const baseUrl = SERVICE_DATA_API_BASE
const baseUrl2 = upcloud_base_common
export const api = {
  queryList: baseUrl + '/management/listInterfaceDefinitonsPage',
  queryItem: baseUrl + '/management/getInterfaceDefinitonInfo',
  getDataSourceSelect: baseUrl + '/datasource/v1/list',

  addItem: baseUrl + '/management/addInterfaceDefiniton',
  uploadItem: baseUrl + '/management/editInterfaceDefiniton',

  deleteList: baseUrl + '/management/delInterfaceDefinitons',

  querySubItem: baseUrl + '/management/searchInterfaceDefinitonSqlTemplate',

  addOrUpdateSubItem: baseUrl + '/management/addOrEditInterfaceDefinitonSqlTemplate',

  testSQL: baseUrl + '/print/test',
  dbkeys: baseUrl + '/config/dbkeys',
}

export function queryItem(parameter) {
  return request({
    method: 'get',
    url: api.queryItem,
    params: parameter,
  })
}

export function getDbkeys() {
  return request({
    method: 'get',
    url: api.dbkeys,
  })
}
export function testSQL(parameter) {
  return request({
    method: 'post',
    url: '/api/upcloud-base-common/print/test ',
    data: parameter,
  })
}

export function addItem(parameter) {
  return request({
    method: 'post',
    url: api.addItem,
    data: parameter,
  })
}
//新增数据
export function printStrategy(parameter) {
  return request({
    method: 'post',
    url: '/api/upcloud-base-common/print/strategy/insert',
    data: parameter,
  })
}
//查询详情数据
export function findByIdStrategy(parameter) {
  return request({
    method: 'post',
    url: '/api/upcloud-base-common/print/strategy/findById',
    params: parameter,
  })
}
//修改详情数据
export function editStrategy(parameter) {
  return request({
    method: 'post',
    url: '/api/upcloud-base-common/print/strategy/edit',
    data: parameter,
  })
}
//删除数据
// export function deleteStrategy(parameter) {
//   return request({
//     method: 'post',
//     url: '/api/upcloud-base-common/print/strategy/delete',
//     params: parameter,
//   })
// }
//删除数据
export function deleteStrategy(parameter) {
  return request({
    method: 'post',
    url: '/api/upcloud-base-common/print/strategy/delete',
    data: qs.stringify(parameter),
    headers: {
      'content-type': 'application/x-www-form-urlencoded',
    },
  })
}
//人员策略关联方案-删除
export function deletePersonStrategy(parameter) {
  return request({
    method: 'post',
    url: '/api/upcloud-base-common/print/strategy/deletePersonStrategy',
    data: qs.stringify(parameter),
    headers: {
      'content-type': 'application/x-www-form-urlencoded',
    },
  })
}

export function addPersonStrategy(parameter) {
  return request({
    method: 'post',
    url: '/api/upcloud-base-common/print/strategy/addPersonStrategy',
    data: parameter,
  })
}

export function getList(params) {
  return request({
    url: '/api/upcloud-base-common/printconf/list',
    method: 'get',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params:  params
  })
}
//修改
export function updateDetail(params) {
  return request({
    url: '/api/upcloud-base-common/printconf/update',
    method: 'post',
    headers: { 'Content-Type': 'application/json'  },
    data:params
    // params: qs.stringify(params)
  })
}
//新增
export function addDetail(params) {
  return request({
    url: '/api/upcloud-base-common/printconf/create',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data: params
  })
}
//删除
export function delDetail(params) {
  return request({
    url:'/api/upcloud-base-common/printconf/batch-delete',
    method: 'post',
    headers: { 'Content-Type': 'application/json' },
    data:params
    // data: JSON.stringify(params) 
  })
}

export function getLogs(parameter) {
  return request({
    method: 'get',
    url: baseUrl2 + '/print/strategy/logs',
    params: parameter,
  })
}

export function sqlForTest(parameter) {
  return request({
    method: 'post',
    url: baseUrl2 + '/print/executePrintSingle',
    data: parameter,
  })
}