import { http } from '@/utils/http/axios';
import { MenuDetailTree, MenuDetailItem } from '@/types/menu/type';

/**
 * 获取当前用户可访问态菜单
 */
export function getRouters() {
  return http.request(
    {
      url: '/admin/menu/getRouters',
      method: 'GET',
    },
    {
      ignoreTargetTenantId: true,
    },
  );
}

/**
 * 获取整个菜单树
 */
export function queryFullMenuTree() {
  return http.request<MenuDetailTree>({
    url: '/admin/menu/queryAllMenuTree',
    method: 'post',
  });
}

/**
 * 获取当前用户拥有的菜单树
 */
export function queryOwnedMenuTree() {
  return http.request<MenuDetailTree>({
    url: '/admin/menu/queryOwnedMenuTree',
    method: 'post',
  });
}

/**
 * 添加菜单
 * @param params
 */
export function addMenu(data: MenuDetailItem) {
  return http.request({
    url: '/admin/menu/saveMenu',
    method: 'POST',
    data,
  });
}

/**
 * 编辑菜单
 * @param params
 */
export function editMenu(data: MenuDetailItem) {
  return http.request({
    url: '/admin/menu/updateMenu',
    method: 'POST',
    data,
  });
}

/**
 * 删除菜单
 * @param params
 */
export function deleteMenu(menuId: number) {
  return http.request({
    url: `/admin/menu/deleteMenu?menuId=${menuId}`,
    method: 'POST',
  });
}
