/**
 * 订单管理相关API
 */

import { get, post } from '@/utils/request';

export interface OrderQueryParams {
  page?: number;
  pageSize?: number;
  orderNo?: string;
  deviceId?: string;
  payStatus?: string;
  status?: number;
  statusList?: number[];
  startDate?: string;
  endDate?: string;
}

export interface OrderListResponse {
  list: any[];
  total: number;
  page: number;
  pageSize: number;
}

/**
 * 获取订单列表
 */
export async function getOrderList(params: OrderQueryParams = {}): Promise<OrderListResponse> {
  const query = { ...params };
  if (query.status === -1) {
    delete (query as any).status;
  }
  return get('/order/list', query);
}

/**
 * 获取订单详情
 */
export async function getOrderDetail(orderId: string): Promise<any> {
  return get(`/order/${orderId}`);
}

/**
 * 获取订单统计
 */
export async function getOrderStats(params?: { startDate?: string; endDate?: string }): Promise<any> {
  return get('/order/statistics', params || {});
}

/**
 * 处理退款
 */
export async function handleRefund(orderId: string, reason: string): Promise<void> {
  await post(`/order/${orderId}/refund`, { reason });
}
