import Request from '../..'

enum Api {
  RolesList = '/workspace/role/list',
  PostPage = '/workspace/post/page',
  PostList = '/workspace/post/list',
  PostDel = '/workspace/post/del',
  PostAdd = '/workspace/post/create',
  PostUpdate = '/workspace/post/update',
  RolesBase = '/workspace/role',
  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.PostPageResult>>({
    url: Api.PostPage,
    params: query
  })
}

export function fetchPostList() {
  return Request.get<API.PostListResult>({
    url: Api.PostList
  })
}

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

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

export function delObj(id: string) {
  return Request.post({
    url: Api.PostDel,
    data: { postIds: [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<number[]>({
    url: Api.RolesMenuTree,
    params: { roleId }
  })
}
