import { defHttp } from '/@/utils/http/axios';
import { getMenuListResultModel } from './model/menuModel';
import { useUserStore } from '/@/store/modules/user';
import { RoleEnum } from '/@/enums/roleEnum';

enum Api {
  BaseMenuUrl = '/menu',
  GetMenuList = '/menu/me/menus',
  SysAdminMenuList = '/admin/me/menus',
  GetMenuIdsByRoleId = '/menu/get_ids/',
}

/**
 * @description: Get user menu based on id
 */

export const getMenuList = (args?: number) => {
  const userStore = useUserStore();
  let url = Api.GetMenuList;
  try {
    if (userStore.getRoleList.find((v) => v == RoleEnum.SYS_ADMIN)) {
      url = Api.SysAdminMenuList;
    }
    return defHttp.get<getMenuListResultModel>({
      url,
      params: {
        needButton: args == 1 ? false : null,
      },
    });
  } catch (e) {}
};

export const delMenu = (menuIds: string[]) => {
  const url = Api.BaseMenuUrl;
  return defHttp.delete({ url: url, data: menuIds });
};
export const getMenusIdsByRoleId = (roleId: string) => {
  const url = Api.GetMenuIdsByRoleId + roleId;
  return defHttp.get<Array<string>>({ url });
};
