/*配置中心的接口*/


import { del, get, post, put } from 'src/axios/tools';


/**
 * 根据条件查询配置信息
 * @param params
 * @param headers
 * @returns {Promise<any | never>}
 */
export const queryConfig = (params, headers = {}) => get({ url: '/config/v1/property/config', headers, params });

/**
 * 查询标签信息
 * @param params
 */
export const findPLabel = (params) => get({ url: '/config/v1/property/label', params });

export const labelAdd = (params) => post({ url: '/config/v1/property/label', data: params });

export const labelEdit = (params) => put({ url: '/config/v1/property/label', data: params });
export const pLabelDelete = (id) => del({ url: `/config/v1/property/label/${id}` });

/**
 * 如果没有关键词，则不查询网络
 * @param keywords
 * @returns {{records: Array}|Promise<any | never>}
 */
export const searchLabel = ({ keywords }) => {
    if (keywords === '') return { records: [] };
    return get({ url: '/config/v1/property/label', params: { keywords } });
};


/**
 * 查询配置
 * @param params
 * @param headers
 * @returns {Promise<unknown>}
 */
export const configQueryConfigList = ({ params, headers = {} }) => get({
    url: 'config/v1/property/config',
    params,
    headers,
});

/**
 * 添加属性配置
 * @param data
 * @returns {Promise<unknown>}
 */
export const configAddConfig = (data) => post({ url: 'config/v1/property/config', data });

/**
 * 编辑配置项
 * @param id
 * @param data
 * @returns {Promise<AxiosResponse<any>|never>}
 */
export function configEditConfig({ id, data }) {
    return put({ url: `config/v1/property/config/${id}`, data });
}

/**
 * 删除配置项
 * @param id
 * @returns {Promise<unknown>}
 */
export function configDelConfig(id) {
    return del({ url: `config/v1/property/config/${id}` });
}
