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

const prefix = 'api/v1/rbac'

export const getPage = (params) => {
  return axios.request({
    url: prefix + '/menu',
    params: params,
    method: 'get',
  })
}

export const getAll = (params) => {
  return axios.request({
    url: prefix + '/menu/all',
    params: params,
    method: 'get',
  })
}

export const getAllSystem = (params) => {
  return axios.request({
    url: prefix + '/license/allSystem/loginUser',
    params: params,
    method: 'get',
  })
}

export const getSystemLicense = (params) => {
  return axios.request({
    url: prefix + '/license/companyLicenseInfo/loginUser',
    params: params,
    method: 'get',
  })
}

export const makeActivatekey = (params) => {
  return axios.request({
    url: prefix + '/license/makeActivatekey',
    params: params,
    method: 'get',
  })
}

export const makeLicenseCode = (params) => {
  return axios.request({
    url: prefix + '/license/makeLicenseCode',
    params: params,
    method: 'get',
  })
}

export const useLicenseCode = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: prefix + '/license/useLicenseCode',
        method: 'POST',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const doLicense = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: prefix + '/license/doLicense',
        method: 'POST',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const addRes = (params) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: prefix + '/menu',
        method: 'POST',
        data: params,
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const getChilds = (pid) => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: prefix + '/menu/childs/' + pid,
        method: 'GET',
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const getTree = () => {
  return new Promise((resolve, reject) => {
    axios
      .request({
        url: prefix + '/menu/tree',
        method: 'GET',
      })
      .then((response) => {
        resolve(response.data)
      })
      .catch((err) => {
        reject(err)
      })
  })
}

export const getTreeSelectData = () => {
  return axios.request({
    url: 'api/v1/get_tree_select_data',
    method: 'get',
  })
}
