import type * as T from './type'
import http from '@/utils/http'

export type * from './type'

const BASE_URL = '/system/menu'

/** @desc 查询菜单列表(已废弃) */
export function listMenu(query?: T.MenuQuery) {
  return http.get<T.MenuResp[]>(`${BASE_URL}/tree`, query)
}

/** @desc 查询菜单树（新接口） */
export function getMenuTree(query?: T.MenuTreeQuery) {
  return http.get<T.MenuResp[]>('/menu/tree', query)
}

/** @desc 查询菜单详情(已废弃) */
export function getMenu(id: string) {
  return http.get<T.MenuResp>(`${BASE_URL}/${id}`)
}

/** @desc 查询菜单详情（新接口） */
export function getMenuDetail(menuId: string) {
  return http.get<T.MenuDetailResp>(`/menu/detail/${menuId}`)
}

/** @desc 新增菜单 */
export function addMenu(data: T.MenuAddReq) {
  return http.post<boolean>('/menu', data)
}

/** @desc 修改菜单(已废弃) */
export function updateMenu(data: any, id: string) {
  return http.put(`${BASE_URL}/${id}`, data)
}

/** @desc 修改菜单（新接口） */
export function updateMenuNew(menuId: string, data: T.MenuUpdateReq) {
  return http.put<boolean>(`/menu/${menuId}`, data)
}

/** @desc 删除菜单 */
export function deleteMenu(id: string) {
  return http.del(`/menu/${id}`)
}

/** @desc 清除菜单缓存 */
export function clearMenuCache() {
  return http.del(`${BASE_URL}/cache`)
}
