import Request from '../..'

enum Api {
  MenuBase = '/workspace/menu',
  MenuDel = '/workspace/menu/del',
  MenuTree = '/workspace/menu/tree',
  MenuList = '/workspace/menu/user/list',
  MenuPack = '/workspace/menu/bundle/page',
  CreateMenuPack = '/workspace/menu/bundle/create',
  UpdateMenuPack = '/workspace/menu/bundle/update',
  AvailBundle = '/workspace/menu/bundle/avail/list',
  MenuAdd = '/workspace/menu/create',
  MenuUpdate = '/workspace/menu/update',
  MenuDetails = '/workspace/menu/details'
}

export function getMenu(id?: number) {
  return Request.get<API.MenuResult>({
    url: Api.MenuList,
    params: { parentId: id }
  })
}

export function fetchMenuTree(parentId: number | string) {
  return Request.get<API.MenuTreeResult>({
    url: Api.MenuTree,
    params: { parentId: parentId }
  })
}

export function delObj(id: string) {
  return Request.post({
    url: Api.MenuDel,
    data: { menuId: id, deleteType: 'SOFT' }
  })
}

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

export function getObj(id: number) {
  return Request.get<API.MenuDetailResult>({
    url: Api.MenuDetails + `/${id}`
  })
}

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

// 获取菜单包分页
export function getMenuPackList(query: API.PageParams) {
  return Request.get<API.TableListResult<API.MenuPackPageResult>>({
    url: Api.MenuPack,
    params: query
  })
}

// 添加菜单功能包
export function addMenuPack(data: API.AddMenuPackParams) {
  return Request.post({
    url: Api.CreateMenuPack,
    data
  })
}

// 更新菜单功能包
export function updateMenuPack(data: API.UpdateMenuPackParams) {
  return Request.post({
    url: Api.UpdateMenuPack,
    data
  })
}

// 获取全部可用的bundle
export function getAvailBundle() {
  return Request.get<API.BundleList>({
    url: Api.AvailBundle
  })
}
