/**
 * 订单相关API
 */

import { post } from '../utils/request';

/**
 * 订单商品信息
 */
export interface OrderProduct {
  id: string;
  name: string;
  price: number;
  quantity: number;
  image?: string;
  subtotal?: number;
}

/**
 * 订单信息
 */
export interface OrderInfo {
  id: number;
  orderNo: string;
  outTradeNo: string;
  hahaOrderNo: string;
  deviceId: string;
  totalAmount: number;
  payStatus: string;
  status: number;
  statusText?: string;
  createTime: string;
  payTime?: string;
  videoUrl?: string;
  confidence?: number;
  products: OrderProduct[];
}

/**
 * 订单列表请求参数
 */
export interface OrderListRequest {
  status?: number; // 0-待支付，1-已完成，2-已取消
}

/**
 * 订单详情请求参数
 */
export interface OrderDetailRequest {
  orderId?: number;
  orderNo?: string;
  outTradeNo?: string;
}

/**
 * 取消订单请求参数
 */
export interface CancelOrderRequest {
  orderId: number;
}

/**
 * 获取订单列表
 * @param params 查询参数
 */
export const getOrderList = (params?: OrderListRequest): Promise<OrderInfo[]> => {
  return post<OrderInfo[]>('/order/list', params || {});
};

/**
 * 获取订单详情
 * @param params 查询参数（必须包含orderId、orderNo或outTradeNo之一）
 */
export const getOrderDetail = (params: OrderDetailRequest): Promise<OrderInfo> => {
  return post<OrderInfo>('/order/detail', params);
};

/**
 * 取消订单
 * @param orderId 订单ID
 */
export const cancelOrder = (orderId: number): Promise<void> => {
  return post<void>('/order/cancel', { orderId });
};
