import FetchRequest from "@/api/FetchRequest";
import type AjaxResult from "@/mode/AjaxResult";
import type Message from "@/mode/Message";

class MessageApi {
  static url = "/api/sys/messages";
  static Shortcut_url = "/imShortcut/queryAutoReplyShortcutContent";
  static Shortcut_hf_url = "/imShortcut/queryById";
  static list(
    chatId: string,
    fromId: string,
    type: string,
    pageSize: number
  ) {
    const param =
      `?chatId=${chatId}&fromId=${fromId}&type=${type}&pageSize=${pageSize}`;
    return FetchRequest.get(this.url + param, true);
  }

  static getReadTime(chatId: string, fromId: string): Promise<AjaxResult<string>> {
    return FetchRequest.get(`${this.url}/getReadTime?chatId=${chatId}&fromId=${fromId}`, true)
  }

  static page(
      chatId: string,
      fromId: string,
      type: string,
      messageType: string,
      current: number,
      size: number
    ) {
      const param =
        `?chatId=${chatId}&fromId=${fromId}&chatType=${type}&messageType=${messageType}&current=${current}&size=${size}`;
      return FetchRequest.get(`${this.url}/page${param}`, true);
    }

  static search(
      chatId: string,
      fromId: string,
      searchText: string,
      type: string,
      messageType: string,
      current: number,
      dateRange1: string,
      dateRange2: string,
      size: number
  ) {
    let param = `?chatId=${chatId}&fromId=${fromId}&searchText=${searchText}&chatType=${type}&messageType=${messageType}&current=${current}&size=${size}`
    if (dateRange1 != null && dateRange1 != '') {
      param += `&dateRange=${dateRange1}`
    }
    if (dateRange2 != null && dateRange2 != '') {
      param += `&dateRange=${dateRange2}`
    }
    return FetchRequest.get(`${this.url}/page${param}`, true)
  }
  static Shortcut(
    userId: string,
  ){
    const param =
      "?userId=" +
      userId
    return FetchRequest.get(this.Shortcut_url + param, true);
  }
  static Shortcuthf(
    id: string,
  ) {
    const param =
      "?id=" +
      id
    return FetchRequest.get(this.Shortcut_hf_url + param, true);
  }
}

export default MessageApi;
