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

enum Api {
    GetAll = '/tags/TagsProvider/getAll',
    CheckTag = '/tags/TagsProvider/checkTag',
    GetType = '/tags/TagsProvider/getType',
    Insert = '/tags/TagsProvider/insert',
    Update = '/tags/TagsProvider/update',
    Delete = '/tags/TagsProvider/delete',
    GenerateCode = '/tags/TagsProvider/generateCode'
}
const locationType = { apiUrl2: true };

/**
 * @description: 获取所有标签
 * @param: 1:用户登录tokenV2
 */
export const getAllTags = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.GetAll, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};

/**
 * @description: 检查标签编码是否重复
 * @param: 1:用户登录tokenV2
 * @param: 2:标签编码code
 */
export const checkTagCode = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.CheckTag, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};

/**
 * @description: 获取所有标签类型
 * @param: 1:用户登录tokenV2
 */
export const getAllTagsType = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.GetType, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};

/**
 * @description: 新增标签
 * @param: 1:用户登录tokenV2
 * @param: 2:标签信息对象数组
 */
export const addTag = (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:标签信息对象数组
 */
export const updateTag = (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:标签信息对象数组
 * @param: 3:id数组
 */
export const deleteTag = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.Delete, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};

/**
 * @description: 根据名称生成code
 * @param: 1:用户登录tokenV2
 * @param: 2:name
 */
export const generateCodeByName = (params: any) => {
    return new Promise<void>((resolve) => {
        defHttp.post({ ...locationType, url: Api.GenerateCode, params: params }, { joinParamsToUrl: true }).then((res) => {
            resolve(res)
        })
    })
};