import request from '@/utils/request';

/**
 * 分页查询
 * @param params 查询条件
 */
export async function pageClues(params) {
  const res = await request.get('/receiver/clues/page', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function getClues(params) {
  const res = await request.get('/receiver/clues', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function pageCluesOptLog(params) {
  const res = await request.get('/receiver/clues/opt', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function addCluesOptLog(data) {
  const res = await request.post('/receiver/clues/addLog', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function getSearch(params) {
  const res = await request.get('/receiver/clues/search', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function pageCluesEnroll(params) {
  const res = await request.get('/receiver/clues/enroll', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function updateClues(data) {
  const res = await request.put('/receiver/clues', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function callPhone(data) {
  const res = await request.post('/receiver/clues/call', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 导出用户
 * @param params 查询条件
 */
export async function exportClues(params) {
  const res = await request.get('/receiver/clues/export', {
    params
  });
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
export async function updateLevel(data) {
  const res = await request.post('/receiver/clues/level', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 发送优惠券
 * @param data
 * @returns {Promise<*>}
 */
export async function sendCoupon(data) {
  const res = await request.post('/receiver/clues/sendCoupon', data);
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}
