import { axios } from '@/utils/request'
import { stringify } from 'qs'

/**
 * user page func
 * parameter: {
 *     keyword: '',
 * }
 * @param parameter
 * @returns {*}
 */
export function getRolePage (parameter) {
  return axios({
    url: `/upms/roles/page?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

/**
 * role list func
 * @param parameter
 * @returns {*}
 */
export function queryRole (parameter) {
  console.log('parameter', stringify(parameter))
  return axios({
    url: `/upms/roles?${stringify(parameter)}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function addRole (parameter) {
  return axios({
    url: `/upms/roles`,
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data: parameter
  })
}

export function updateRole (parameter) {
  console.log('parameter', parameter)
  return axios({
    url: `/upms/roles/${parameter.roleId}`,
    method: 'PUT',
    data: parameter
  })
}

export function updateStatus (parameter) {
  return axios({
    url: `/upms/roles/status/${parameter.status}`,
    method: 'PUT',
    data: parameter.roleIds
  })
}

export function fetchRole (parameter) {
  return axios({
    url: `/upms/roles/${parameter.roleId}`,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function deleteRoles (parameter) {
  return axios({
    url: `/upms/roles`,
    method: 'DELETE',
    data: parameter
  })
}
