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

const prefix = 'api/v1/rbac/functionInit'

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

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

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

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

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