import axiosInstance from '../utils/axios';

// 菜单类型枚举
export enum MenuType {
  DIR = 1,    // 目录
  MENU = 2,   // 菜单
  BUTTON = 3  // 按钮
}

// 菜单状态枚举
export enum MenuStatus {
  DISABLE = 0, // 禁用
  ENABLE = 1   // 启用
}

// 菜单 VO
export interface MenuVO {
  id?: number;
  name: string;
  permission: string;
  type: number;
  sort: number;
  parentId: number;
  path: string;
  icon: string;
  component?: string;
  componentName?: string;
  status: number;
  visible: boolean;
  keepAlive: boolean;
  alwaysShow?: boolean;
  createTime?: Date;
}

// 菜单查询参数
export interface MenuQueryParams {
  name?: string;
  status?: number;
}

// 菜单管理 API
export const menuApi = {
  // 查询菜单（精简）列表
  getSimpleMenusList: () => {
    return axiosInstance.get<MenuVO[]>('/system/menu/simple-list');
  },

  // 查询菜单列表
  getMenuList: (params?: MenuQueryParams) => {
    return axiosInstance.get<MenuVO[]>('/system/menu/list', { params });
  },

  // 获取菜单详情
  getMenu: (id: number) => {
    return axiosInstance.get<MenuVO>(`/system/menu/get?id=${id}`);
  },

  // 新增菜单
  createMenu: (data: MenuVO) => {
    return axiosInstance.post('/system/menu/create', data);
  },

  // 修改菜单
  updateMenu: (data: MenuVO) => {
    return axiosInstance.put('/system/menu/update', data);
  },

  // 删除菜单
  deleteMenu: (id: number) => {
    return axiosInstance.delete(`/system/menu/delete?id=${id}`);
  },
};

