import { defHttp } from '/@/utils/http/axios';

enum Api {
    FindList = '/sdatacatlog/SDataCatlogProvider/findList',
    FindRoot = '/sdatacatlog/SDataCatlogProvider/findRoot',
    Insert = '/sdatacatlog/SDataCatlogProvider/insert',
    Delete = '/sdatacatlog/SDataCatlogProvider/delete',
    Update = '/sdatacatlog/SDataCatlogProvider/update',
    UpdateList = '/sdatacatlog/SDataCatlogProvider/updateList'
}
const locationType = { apiUrl2: true };

/**
 * @description: 获取目录树
 * @param: 1:用户登录tokenV2
 * @param: 2:根节点id
 */
export const getTreeList = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.FindList, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};

/**
 * @description: 获取根节点id
 * @param: 1:用户登录tokenV2
 */
export const getTreeRootId = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.FindRoot, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};

/**
 * @description: 新增节点
 * @param: 1:用户登录tokenV2
 * @param: 2:根节点信息
 */
export const addNode = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.Insert, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};

/**
 * @description: 删除节点
 * @param: 1:用户登录tokenV2
 * @param: 2:节点id，多个用逗号隔开
 */
export const delNode = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.Delete, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};

/**
 * @description: 修改节点
 * @param: 1:用户登录tokenV2
 * @param: 2:修改的节点信息
 */
export const updateNode = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.Update, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};

/**
 * @description: 批量修改节点
 * @param: 1:用户登录tokenV2
 * @param: 2:修改的节点信息
 */
export const updateNodeList = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.UpdateList, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};