import { request } from '@/api/_service'

const BASE = 'system_settings/user_management/role/'

function apiParams (method, data = {}) {
  return {
    method: `system_settings_user_management_role_${method}`,
    platform: 'background',
    ...data
  }
}

export function getRoleAll (data) {
  return request({
    url: BASE + 'all',
    method: 'get',
    params: apiParams('all', data)
  })
}

export function getRoleList (data) {
  return request({
    url: BASE + 'list',
    method: 'get',
    params: apiParams('list', data)
  })
}

export function createRole (data) {
  return request({
    url: BASE + 'create',
    method: 'post',
    data: apiParams('create', data)
  })
}

export function editRole (data) {
  return request({
    url: BASE + 'edit',
    method: 'put',
    data: apiParams('edit', data)
  })
}

export function deleteRole (data) {
  return request({
    url: BASE + 'delete',
    method: 'delete',
    data: apiParams('delete', data)
  })
}

export function updateRoleStatus (data) {
  return request({
    url: BASE + 'update_status',
    method: 'put',
    data: apiParams('update_status', data)
  })
}

export function giveRoleMenu (data) {
  return request({
    url: BASE + 'give',
    method: 'put',
    data: {
      method: 'system_settings_user_management_give_role_menu',
      platform: 'background',
      ...data
    }
  })
}

export function getRoleMenu (data) {
  return request({
    url: BASE + 'menu',
    method: 'get',
    params: {
      method: 'system_settings_user_management_role_menu',
      platform: 'background',
      ...data
    }
  })
}
