import axios from 'bc-common-ui-vue3/src/bc-components/bc-libs/api.request'

/**
 * 分页查询方法
 * @param params
 * @returns {*|void|ClientRequest|ClientHttp2Stream|never|AxiosPromise<any>}
 */
export const getDictPage = (params) => {
  return axios.request({
    url: 'api/v1/base/dict/page',
    params: params,
    method: 'get',
  })
}

/**
 * 根据参数查询列表
 * @param params
 * @returns {*|void|ClientRequest|ClientHttp2Stream|never|AxiosPromise<any>}
 */
export const getDictList = (params) => {
  return axios.request({
    url: 'api/v1/base/dict/list',
    params: params,
    method: 'get',
  })
}

/**
 * 根据参数查询tree
 * @param params
 * @returns {*|void|ClientRequest|ClientHttp2Stream|never|AxiosPromise<any>}
 */
export const getDictTree = (params) => {
  return axios.request({
    url: 'api/v1/base/dict/tree',
    params: params,
    method: 'get',
  })
}

/**
 * 新增
 * @param params
 * @returns {Promise<any>}
 */
export const addDict = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/base/dict/add',
        method: 'POST',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

/**
 * 修改
 * @param params
 * @returns {Promise<any>}
 */
export const editDict = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/base/dict/merge',
        method: 'POST',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

/**
 * 删除
 * @param id
 * @returns {Promise<any>}
 */
export const deleteDict = (id) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: 'api/v1/base/dict/delete/' + id,
        method: 'POST',
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}
