import type addCartQuery from './cartQuery'
import { type addressQuery,type updateGroupQuery } from './cartQuery'
import type Cart from '~/domain/Cart'
import type { ServerList, ServerRes } from '~/service/index'
import httpRequest from "~/service/index";

/**
 * order service
 * api service
 */
export function useCart() {
  const apiRoot = '/seller/shoppingCart'

  async function getCart(query?:any | {}) {
    return await httpRequest.post<ServerList<Cart>>(`${apiRoot}/get`, query)
  }

  async function addCart(query: addCartQuery) {
    return await httpRequest.post(`${apiRoot}/addDetail`, query)
  }

  async function updateCart(query: addCartQuery) {
    return await httpRequest.post(`${apiRoot}/updateDetail`, query)
  }

  async function updateGroup(query:updateGroupQuery) {
    return await httpRequest.post(`${apiRoot}/updateGroupInfo`, query)
  }


  async function delCart(query:{skuCode:string,vendorWarehouseCode:string}) {
    return await httpRequest.post<ServerList<any>>(`${apiRoot}/removeDetail`, query)
  }

  async function updateAddress(query:addressQuery) {
    return await httpRequest.post(`${apiRoot}/updateAddressInfo`, query)
  }

  async function submitCart(query:any) {
    return await httpRequest.post(`${apiRoot}/submit`, query)
  }

  return {
    getCart,
    addCart,
    updateCart,
    delCart,
    updateAddress,
    submitCart,
    updateGroup
  }
}
