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

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

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

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

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

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