import request from '@/utils/request';

/**
 * 查询订单列表
 * @param params 查询条件
 */
export async function listGroupsExchange(params) {
  const res = await request.get('/sylive/groupsExchange', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 导出订单
 * @param params 查询条件
 */
export async function exportGroupsExchange(params) {
  const res = await request.get('/sylive/groupsExchange/export', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 操作详情
 * @param params 查询条件
 */
export async function getGroupsExchangeDetail(params) {
  const res = await request.get('/sylive/groupsExchange/detail', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 修改使用状态
 * @param data 操作信息
 */
export async function updateGroupsExchangeUseStatus(data) {
  const res = await request.put('/sylive/groupsExchange/status', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 导入用户
 * @param file excel文件
 */
export async function importGroupsExchange(file) {
  const formData = new FormData();
  formData.append('file', file);
  const res = await request.post('/sylive/groupsExchange/import', formData);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
