import http from '@/api'
import { MenuQuery, MenuVO, MenuForm, MenuTreeOption, RoleMenuTree } from '@/api/interface/system/menu'
import { RouteRecordRaw } from 'vue-router'
// 获取路由
export const getRoutersApi = () => {
  return http.get<RouteRecordRaw[]>('/system/menu/getRouters', {}, { loading: false })
}

/**
 * @name 查询菜单列表
 * @param query 参数
 * @returns 返回列表
 */
export const listMenuApi = (query?: MenuQuery) => {
  return http.get<MenuVO[]>('/system/menu/list', query, { loading: true })
}

/**
 * @name 查询菜单详细
 * @param menuId menuId
 * @returns returns
 */
export const getMenuApi = (menuId: string | number) => {
  return http.get<MenuVO>(`/system/menu/${menuId}`)
}

/**
 * @name 新增菜单
 * @param data data
 * @returns returns
 */
export const addMenuApi = (data: MenuForm) => {
  return http.post<any>('/system/menu', data, { loading: false })
}

/**
 * @name 修改菜单
 * @param data data
 * @returns returns
 */
export const updateMenuApi = (data: MenuForm) => {
  return http.put<any>('/system/menu', data, { loading: false })
}

/**
 * @name 删除菜单
 * @param menuId menuId
 * @returns returns
 */
export const delMenuApi = (menuId: string | number) => {
  return http.delete<any>(`/system/menu/${menuId}`)
}

/**
 * @name 查询菜单下拉树结构
 * @returns returns
 */
export const treeSelectApi = () => {
  return http.get<MenuTreeOption[]>(`/system/menu/treeselect`)
}

/**
 * @name 根据角色ID查询菜单下拉树结构
 * @param roleId roleId
 * @returns returns
 */
export const roleMenuTreeselectApi = (roleId: string | number) => {
  return http.get<RoleMenuTree>(`/system/menu/roleMenuTreeselect/${roleId}`)
}
