import type OrderQuery from './orderQuery'
import { type cancelOrderType,type pullShopOrderLabelsQuery } from './orderQuery'
import type Order from '~/domain/Order'
import {type orderCreate} from '~/domain/Order'
import type { ServerList, ServerRes } from '~/service/index'
import httpRequest from "~/service/index";

/**
 * order service
 * api service
 */
export function useOrder() {
  const apiRoot = '/seller/sellerOrder'

  async function listOrders(query?: OrderQuery) {
    return await httpRequest.post<ServerList<Order>>(`${apiRoot}/list`, query)
  }

  async function exportOrders(query?: OrderQuery) {
    return await httpRequest.post<ServerList<Order>>(`${apiRoot}/export`, query)
  }

  async function createOrders(query?: orderCreate) {
    return await httpRequest.post<ServerList<Order>>(`${apiRoot}/add`, query)
  }

  async function getCity(query?: any) {
    return await httpRequest.post<ServerList<any>>(`/seller/zip/listCitys`, query)
  }

  async function getDetail(id: number) {
    return await httpRequest.post<ServerList<any>>(`${apiRoot}Detail/list`, {orderCode:id})
  }

  // 取消订单
  async function cancelOrder(query: cancelOrderType) {
    return await httpRequest.post<ServerList<any>>(`${apiRoot}/applyCancelOrder`, query)
  }
  
  //批量拉取店铺订单面单（异步）
  async function pullShopOrderLabels(query: pullShopOrderLabelsQuery) {
    return await httpRequest.post<ServerList<any>>(`/seller/sellerOrder/pullShopOrderLabels`, query)
  }

  //查询订单统计
  async function getOrderSummary() {
    return await httpRequest.post<ServerList<any>>(`/seller/sellerOrder/getOrderSummary`, {})
  }

  return {
    listOrders,
    createOrders,
    getCity,
    getDetail,
    cancelOrder,
    pullShopOrderLabels,
    exportOrders,
    getOrderSummary
  }
}
