import { createUrl, http } from "@/utils/http";
import type { Result } from "@/model";

// 后端请求接口
const apiUrl: any = createUrl({
  listHelpTree: "/help/doc/tree",
  getDoc: "/help/doc/detail",
  save: "/help/doc/add",
  update: "/help/doc/update",
  del: "/help/doc/delete"
});

export interface HelpDoc {
  id: number;
  label: string;
  parentId: number;
  content: string;
}

/**
 * 接口管理
 */
export const api: any = {
  /**
   * 查询帮助树
   * @param data
   */
  listHelpTree(params: object) {
    return http.get<Result<Array<HelpDoc>>, any>(apiUrl.listHelpTree, {
      params
    });
  },
  /**
   * 文档详情
   * @param data
   */
  getDoc(id: any) {
    return http.get<Result<any>, any>(apiUrl.getDoc, {
      params: {
        id
      }
    });
  },
  save(data) {
    return http.post(apiUrl.save, {
      data
    });
  },
  update(data) {
    return http.post(apiUrl.update, {
      data
    });
  },
  del(data) {
    return http.post(apiUrl.del, {
      data
    });
  }
};
