import axiosApi from './AxiosApi.js'

const apiList = {
  page: {
    url: `/role/page`,
    method: 'POST'
  },
  save: {
    url: `/role`,
    method: 'POST'
  },
  update: {
    url: `/role`,
    method: 'PUT'
  },
  delete: {
    url: `/role`,
    method: 'DELETE'
  },
  saveUserRole: {
    url: `/role/user`,
    method: 'POST'
  },
  saveRoleAuthority: {
    url: `/role/authority`,
    method: 'POST'
  },
  preview: {
    method: 'POST',
    url: `/user/preview`
  },
  export: {
    method: 'POST',
    url: `/user/export`
  },
  import: {
    method: 'POST',
    url: `/role/import`
  }
}

export default {
  page (data) {
    return axiosApi({
      ...apiList.page,
      // formData: true,
      data
    })
  },
  save (data) {
    return axiosApi({
      ...apiList.save,
      data
    })
  },
  update (data) {
    return axiosApi({
      ...apiList.update,
      data
    })
  },
  delete (data) {
    return axiosApi({
      ...apiList.delete,
      data
    })
  },
  get (id) {
    return axiosApi({
      url: `/role/${id}`,
      method: 'GET'
    })
  },
  getDetails (id) {
    return axiosApi({
      url: `/role/details/${id}`,
      method: 'GET'
    })
  },
  check (code) {
    return axiosApi({
      url: `/role/check/${code}`,
      method: 'GET'
    })
  },
  saveUserRole (data) {
    return axiosApi({
      ...apiList.saveUserRole,
      data
    })
  },
  findUserIdByRoleId (roleId) {
    return axiosApi({
      url: `/role/user/${roleId}`,
      method: 'GET'
    })
  },
  findAuthorityIdByRoleId (roleId) {
    return axiosApi({
      url: `/role/authority/${roleId}`,
      method: 'GET'
    })
  },
  saveRoleAuthority (data) {
    return axiosApi({
      ...apiList.saveRoleAuthority,
      data
    })
  },
  preview (data) {
    return axiosApi({
      ...apiList.preview,
      data
    })
  },
  export (data) {
    return axiosApi({
      ...apiList.export,
      responseType: "blob",
      data
    })
  },
  import (data) {
    return axiosApi({
      ...apiList.import,
      data
    })
  }
}
