import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { MenuQuery, MenuVO, MenuForm } from "./types";

/**
 * 获取路由列表
 */
export function listRoutes() {
  return request({
    url: "/api/v1/menus/routes",
    method: "get",
  });
}

/**
 * 获取菜单树形列表
 *
 * @param queryParams
 */
export function listMenus(): AxiosPromise<any> {
  return request({
    url: "/api/v1/sys/menu/tree",
    method: "POST",
  });
}

/**
 * 获取菜单下拉树形列表
 */
export function getMenuOptions(): AxiosPromise {
  return request({
    url: "/api/v1/sys/menu/tree",
    method: "post",
  });
}

/**
 * 获取菜单表单数据
 *
 * @param id
 */
export function getMenuForm(id: string): AxiosPromise<MenuForm> {
  return request({
    url: "/api/v1/sys/menu/get",
    method: "post",
    data: { id: id },
  });
}

/**
 * 添加菜单
 *
 * @param data
 */
export function addMenu(data: any) {
  return request({
    url: "/api/v1/sys/menu/add",
    method: "post",
    data: data,
  });
}

/**
 * 修改菜单
 *
 * @param id
 * @param data
 */
export function updateMenu(id: string, data: MenuForm) {
  return request({
    url: "/api/v1/sys/menu/update",
    method: "post",
    data: data,
  });
}

/**
 * 删除菜单
 *
 * @param id 菜单ID
 */
export function deleteMenu(id: string) {
  return request({
    url: "/api/v1/sys/menu/del",
    method: "post",
    data: { id: id },
  });
}
