import http from "../utils/http";
import type {
  OrderCreateDTO,
  // OrderListItem,
  OrderDetail,
  OrderPageParams,
  OrderPageResponse,
} from "@/types/order";

// 获取订单列表
export const getOrderList = (params: OrderPageParams) => {
  return http<OrderPageResponse>({
    url: "/order/page",
    method: "get",
    params,
  });
};

// 获取订单详情
export const getOrderDetail = (id: number, userId: number) => {
  return http<OrderDetail>({
    url: `/order/${id}`,
    method: "get",
    params: { userId },
  });
};

// 创建订单
export const createOrder = (data: OrderCreateDTO) => {
  return http<{ orderId: number }>({
    url: "/order",
    method: "post",
    data,
  });
};

// 直接购买创建订单
export const createOrderDirectly = (
  productId: number,
  skuId: number,
  data: OrderCreateDTO,
) => {
  return http<{ orderId: number }>({
    url: `/order/${productId}?skuId=${skuId}`,
    method: "post",
    data,
  });
};
