import { http } from "@/utils/http";
import { baseUrlApi } from "../utils";

export interface BasicResponseModel<T = any> {
  code: number;
  msg: string;
  data: T;
}

/**
 * 获取菜单列表
 * @param query
 */
export const getSystemMenuList = (query?: object) => {
  return http.request<BasicResponseModel>(
    "get",
    baseUrlApi("system/menu/list"),
    { params: query }
  );
};

/**
 * 根据ID获取菜单详细信息
 * @param id
 */
export const getSystemMenuDetailById = (id: number) => {
  return http.request<BasicResponseModel>(
    "get",
    baseUrlApi(`system/menu/${id}`)
  );
};

/**
 * 添加菜单
 * @param data
 */
export const addMenu = (data?: object) => {
  return http.post<BasicResponseModel, any>(baseUrlApi(`system/menu`), {
    data
  });
};

/**
 * 修改菜单
 * @param data
 */
export const updateMenu = (data?: object) => {
  return http.put<BasicResponseModel, any>(baseUrlApi(`system/menu`), { data });
};

/**
 * 删除菜单
 * @param id
 */
export const deleteMenu = (id: number) => {
  return http.request<BasicResponseModel>(
    "delete",
    baseUrlApi(`system/menu/${id}`)
  );
};

/**
 * 获取业务系统列表
 */
export const getSystemList = () => {
  return http.request<BasicResponseModel>(
    "get",
    baseUrlApi(`system/businessSystem/list`)
  );
};

/**
 * 获取部门树结构
 */
export interface DeptTreeModel<T = any> {
  code: number;
  msg: string;
  depts: T;
  checkedKeys: number[];
}

/**
 * 获取菜单树结构
 */
export const getMenuListTree = () => {
  return http.request<BasicResponseModel>(
    "get",
    baseUrlApi(`system/menu/treeselect`)
  );
};

/**
 * 获取角色对应菜单树结构
 * @param id
 */
export const getMenuListTreeSelect = (id?: string) => {
  return http.request<DeptTreeModel>(
    "get",
    baseUrlApi(`system/menu/roleMenuTreeselect/${id}`)
  );
};
