
import type wantQuery from "./wantQuery";
import { type myWantQuery, type addWantQuery, type addWantImgQuery, type updateWantImgQuery, type wantSubscribeQuery, type willSaleSubscribeList } from "./wantQuery";
// import {type spuImgQuery,type getPresaleListQuery} from "./wantQuery";
import type wantListType from '~/domain/Want'
import { type wantDetailType, type myWantListType } from '~/domain/Want'
import type { ServerList, ServerRes } from '~/service/index'
import httpRequest from "~/service/index";

export function useWant() {
  const apiRoot = "/seller/wantSpu"

  // 卖家想要列表
  async function getWantSpuList(req: wantQuery) {
    return await httpRequest.post<ServerList<wantListType>>(`${apiRoot}/list`, req)
  }

  // 卖家想要详情
  async function getWantDetail(wantCode: string) {
    return await httpRequest.get<ServerRes<wantDetailType>>(`${apiRoot}/get/${wantCode}`)
  }

  // 我的需求列表
  async function getMyWantSpuList(req: myWantQuery) {
    return await httpRequest.post<ServerList<myWantListType>>(`${apiRoot}/myWantSpuList`, req)
  }

  // 创建找货需求单号
  async function addWant(req: addWantQuery) {
    return await httpRequest.post(`${apiRoot}/add`, req)
  }

  // 更新找货需求
  async function updateWant(req: updateWantImgQuery) {
    return await httpRequest.post(`${apiRoot}/update`, req)
  }

  // 提交找货需求
  async function applyWant(wantCode: string) {
    return await httpRequest.post(`${apiRoot}/apply`, { wantCode: wantCode })
  }

  // 添加找货需求图片
  async function addWantImg(req: addWantImgQuery) {
    return await httpRequest.post(`${apiRoot}Image/add`, req)
  }

  // 删除找货需求图片
  async function delWantImg(hash: string) {  //图片哈希
    return await httpRequest.post(`${apiRoot}Image/remove/${hash}`, {})
  }

  // 订阅
  async function wantSpuSubscribe(wantCode: string) {
    return await httpRequest.post(`/seller/wantSpuSubscribe/add`, { wantCode: wantCode })
  }

  // 订阅预售 sku
  async function wantSubscribe(req: wantSubscribeQuery) {
    return await httpRequest.post(`/seller/willSaleSubscribe/subscribe`, req)
  }

  // 取消订阅预售 sku
  async function wantUnsubscribe(req: {spuCode: string,skuCode: string }) {
    return await httpRequest.post(`/seller/willSaleSubscribe/unsubscribe`, req)
  }

  //查询即将开售通知订阅列表
  async function willSaleSubscribeList(req: willSaleSubscribeList) {
    return await httpRequest.post(`/seller/willSaleSubscribe/list`, req)
  }

  //查询预售订阅统计
  async function willSaleSubscribeSummary() {
    return await httpRequest.post(`/seller/willSaleSubscribe/mySummary`, {})
  }

  //查询找货需求统计
  async function wantSpuSummary() {
    return await httpRequest.post(`/seller/wantSpu/mySummary`, {})
  }

  return {
    getWantSpuList, getWantDetail, getMyWantSpuList, addWant, addWantImg, delWantImg, updateWant, applyWant, wantSpuSubscribe, wantSubscribe, wantUnsubscribe, willSaleSubscribeList, willSaleSubscribeSummary,wantSpuSummary
  }
}
