import request from '@/utils/request';
import type { ApiResult, PageResult } from '@/api';
import { Order, OrderParam } from '@/api/apps/bc/order/model';
import { OPEN_API_URL } from '@/config/setting';

/**
 * 菜品预定统计
 */
export async function countOrderGoods(params: any) {
  const res = await request.get<ApiResult<any>>(
    OPEN_API_URL + '/apps/bc-statistics/baoCanUsers',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function repairData(params?: OrderParam) {
  const res = await request.get<ApiResult<Order[]>>(
    OPEN_API_URL + '/apps/bc-statistics/repairData',
    {
      params
    }
  );
  if (res.data.code === 0 && res.data.data) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}

export async function pageUserLog(params: any) {
  const res = await request.get<ApiResult<PageResult<any>>>(
    'http://127.0.0.1:10051/api/shop/user-balance-log/page',
    {
      params
    }
  );
  if (res.data.code === 0) {
    return res.data.data;
  }
  return Promise.reject(new Error(res.data.message));
}
