import request from '@/utils/request';

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

/**
 * 同步直播场次数据
 * @param params 查询条件
 */
export async function sessionApi(params) {
  const res = await request.get('/sylive/live/session_api', {
    params
  });
  if (res.data.code === 0) {
    return res.data.message;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 同步直播观看详情数据
 * @param params 查询条件
 */
export async function viewApi(params) {
  const res = await request.get('/sylive/live/view_api', {
    params
  });
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

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

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

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