import request from '@/utils/request';
import type { ApiResult } from '@/api';
import type { PayNumData, SaleroomResult, VisitData, CloudData } from './model';

/**
 * 获取支付笔数数据
 */
export async function getPayNumList() {
  const res = await request.get<ApiResult<PayNumData[]>>('/shop/dashboard/statistics');
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取销售量数据
 */
export async function getSaleroomList() {
  const res = await request.get<ApiResult<SaleroomResult>>(
    '/shop/dashboard/statistics/chart'
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取最近 1 小时访问情况数据
 * @returns {Promise<Object>}
 */
export async function getVisitHourList() {
  const res = await request.get<ApiResult<VisitData[]>>(
    '/shop/dashboard/statistics/sales'
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

/**
 * 获取词云数据
 */
export async function getWordCloudList() {
  const res = await request.get<ApiResult<CloudData[]>>(
    'https://oa.gxwebsoft.com/20230508/analysis-hot-search.json'
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
