
import { type MonitorSummary, type MonitorList } from "~/domain/Monitor";
import { type monitorListQuery, type setSmsNotifyQuery, type setStockCanSellLowThresholdQuery } from './monitorQuery'
import type { ServerList, ServerRes } from '~/service/index'
import httpRequest from "~/service/index";

export function useMonitor() {
  const apiRoot = "/seller/sellerSpuMonitor"

  // 获取监控统计
  async function getMonitorSummary() {
    return await httpRequest.post<ServerRes<MonitorSummary>>(`${apiRoot}/summary`, {})
  }

  // 订阅SPU监控
  async function monitorSubscribe(spuCode: string) {
    return await httpRequest.post(`${apiRoot}/subscribe`, { spuCode: spuCode })
  }

  // 获取SPU监控列表
  async function getMonitorList(query: monitorListQuery) {
    return await httpRequest.post<ServerList<MonitorList>>(`${apiRoot}/list`, query)
  }

  // 设置短信通知开关
  async function setSmsNotify(query: setSmsNotifyQuery) {
    return await httpRequest.post(`${apiRoot}/setSmsNotify`, query)
  }

  // 设置库存预警阈值
  async function setStockCanSellLowThreshold(query: setStockCanSellLowThresholdQuery) {
    return await httpRequest.post(`${apiRoot}/setStockCanSellLowThreshold`, query)
  }

  // 取消SPU监控
  async function monitorUnsubscribe(spuCode:string) {
    return await httpRequest.post(`${apiRoot}/unsubscribe`, {spuCode:spuCode})
  }

   // 获取spu监控的详情
   async function getMonitorDetail(spuCode:string) {
    return await httpRequest.post(`${apiRoot}/getInfo/${spuCode}`, {})
  }
  // async function getDetail(id: string) {
  //   return await httpRequest.get<ServerRes<Detaile>>(`${apiRoot}/get/${id}`)
  // }

  return {
    getMonitorSummary, monitorSubscribe, getMonitorList, setSmsNotify, setStockCanSellLowThreshold,monitorUnsubscribe,getMonitorDetail
  }
}
