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 getDictGroupPage = (params) => {
  return axios.request({
    url: 'api/v1/base/dictGroup/page',
    params: params,
    method: 'get',
  })
}

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

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

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

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

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