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

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

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

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

/**
 * 新增
 * @param params
 * @returns {Promise<any>}
 */
export const addObjResFunction = (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 editObjResFunction = (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 deleteObjResFunction = (id) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: prefix + '/delete/' + id,
        method: 'POST',
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const getFunctionPageByObjAndRes = (objId, resId, params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: prefix + '/functionPage/' + objId + '/' + resId,
        method: 'GET',
        params: params,
      })
      .then((response) => {
        resolve(response)
      })
      .catch((err) => {
        reject(err)
      })
  })
}
