import Request from '../..'

enum Api {
  RolesList = '/workspace/role/list',
  RolesPage = '/workspace/role/page',
  RolesBase = '/workspace/role',
  RoleCreate = '/workspace/role/create',
  RoleUpdate = '/workspace/role/update',
  RoleDel = '/workspace/role/del',
  RolesMenuUpdate = '/workspace/role/menu/update',
  RolesMenuTree = '/workspace/menu/role/list'
}

export function deptRoleList() {
  return Request.get<API.RoleListResult>({
    url: Api.RolesList
  })
}

export function fetchList(query: API.PageParams) {
  return Request.get<API.TableListResult<API.RolesPageResult>>({
    url: Api.RolesPage,
    params: query
  })
}

export function addObj(data: API.AddRolesParams) {
  return Request.post({
    url: Api.RoleCreate,
    data
  })
}

export function putObj(data: API.UpdateRolesParams) {
  return Request.post({
    url: Api.RoleUpdate,
    data
  })
}

export function delObj(id: number) {
  return Request.post({
    url: Api.RoleDel,
    data: { roleIds: [id], deleteType: 'SOFT' }
  })
}

export function permissionUpd(roleId: number, menuIds: string[]) {
  return Request.post({
    url: Api.RolesMenuUpdate,
    data: {
      roleId,
      menuIds
    }
  })
}

export function fetchRoleTree(roleId: number) {
  return Request.get<string[]>({
    url: Api.RolesMenuTree,
    params: { roleId }
  })
}
