
import type msgListQuery from "./msgQuery";
import type msgType from "~/domain/Msg";
import type { ServerList, ServerRes } from '~/service/index'
import httpRequest from "~/service/index";

export function useMsg() {
  const apiRoot = "/seller/sellerMessage" 

  //获取消息列表
  async function getMsgList(res:msgListQuery) {
    return await httpRequest.post<ServerList<msgType>>(`${apiRoot}/list`, res)
  }

  //获取消息详情
  async function getMsgDetail(id: string) {
    return await httpRequest.get<ServerRes<msgType>>(`${apiRoot}/get/${id}`)
  }

  //查询消息概要统计
  async function getMsgSummary() {
    return await httpRequest.post<ServerRes<any>>(`${apiRoot}/summary`, {})
  }

  async function getMsgRead(messageIds:any) {
    return await httpRequest.post(`${apiRoot}/read`, {messageIds:messageIds})
  }

  //消息设置全部已读
  async function setMsgReadAll() {
    return await httpRequest.post(`${apiRoot}/readAll`, {})
  }

  return {
    getMsgList,getMsgDetail,getMsgSummary,getMsgRead,setMsgReadAll
  } 
}
