import request from '@/utils/request';

/**
 * 分页查询字典数据
 * @param params 查询条件
 */
export async function pageDictionaryData(params) {
  const res = await request.get('/system/dictionaryData/page', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 查询字典数据列表
 * @param params 查询条件
 */
export async function listDictionaryData(params) {
  const res = await request.get('/system/dictionaryData', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 添加字典数据
 * @param data 字典数据信息
 */
export async function addDictionaryData(data) {
  const res = await request.post('/system/dictionaryData', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改字典数据
 * @param data 字典数据信息
 */
export async function updateDictionaryData(data) {
  const res = await request.put('/system/dictionaryData', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 删除字典项
 * @param id 字典项id
 */
export async function removeDictionaryData(id) {
  return removeDictionaryDataBatch([id]);
}

/**
 * 删除字典项
 * @param ids 字典项id集合
 */
export async function removeDictionaryDataBatch(ids) {
  const res = await request.delete('/system/dictionaryData/batch', {
    data: { ids }
  });
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
