
import type spuQuery from "./spuQuery";
import { type spuImgQuery, type getPresaleListQuery,type getPresaleNotifyListQuery } from "./spuQuery";
import type Detaile from "~/domain/Detaile";
import type { ServerList, ServerRes } from '~/service/index'
import httpRequest from "~/service/index";

export function useSpu() {
  const apiRoot = "/seller/spu"
  async function getSpuList(req?: spuQuery) {
    return await httpRequest.post(`${apiRoot}/list`, req)
  }

  async function getDetail(id: string) {
    return await httpRequest.get<ServerRes<Detaile>>(`${apiRoot}/get/${id}`)
  }
  async function getDetailImg(req: spuImgQuery) {
    return await httpRequest.post(`/seller/spuImage/list`, req)
  }

  // 下载产品数据
  async function spuDown(spu: string) {
    return await httpRequest.post(`${apiRoot}/download/${spu}`, {})
  }

  // 下载产品 -- 数据统计
  async function spuStatDown(spu: string) {
    return await httpRequest.post(`${apiRoot}/download/stat/${spu}`, {})
  }
 
  // 查询预售列表
  async function getInboundList(req: getPresaleListQuery) {
    return await httpRequest.post(`/seller/inbound/list`, req)
  }

  // 订阅预售通知
  async function subscribe(spuCode: string) {
    return await httpRequest.post(`/seller/presaleNotify/subscribe`, { spuCode: spuCode })
  }

  // 取消订阅预售通知
  async function unsubscribe(spuCode: string) {
    return await httpRequest.post(`/seller/presaleNotify/unsubscribe`, { spuCode: spuCode })
  }

  // 查询订阅预售列表
  async function getPresaleNotifyList(req: getPresaleNotifyListQuery) {
    return await httpRequest.post(`/seller/presaleNotify/list`, req)
  }

  // 查询spu数据
  async function getSpuFiles(spu: string) {
    return await httpRequest.post(`/seller/spu/getSpuFiles/${spu}`, {})
  }

  // 查询即将开售概要统计
  async function getPresaleNotifySummary() {
    return await httpRequest.post(`/seller/presaleNotify/summary`, {})
  }

  

  return {
    getSpuList,
    getDetail,
    getDetailImg,
    spuDown,
    spuStatDown,
    getInboundList,
    subscribe,
    unsubscribe,
    getSpuFiles,
    getPresaleNotifyList,getPresaleNotifySummary
  } 
}
