import request from '@/utils/request';
import type { ApiResult } from '@/api';
import type { ShopOrderGoods } from '@/api/shop/shopOrderGoods/model';

/**
 * 根据订单ID查询订单商品列表
 */
export async function listShopOrderGoodsByOrderId(orderId: number) {
  const res = await request.get<ApiResult<ShopOrderGoods[]>>(
    '/shop/shop-order-goods',
    { orderId }
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}

/**
 * 根据ID查询订单商品
 */
export async function getShopOrderGoods(id: number) {
  const res = await request.get<ApiResult<ShopOrderGoods>>(
    '/shop/shop-order-goods/' + id
  );
  if (res.code === 0 && res.data) {
    return res.data;
  }
  return Promise.reject(new Error(res.message));
}
