import baseAxios from "../index";
import { iContact, iUserinfo } from "./types";
import { iContactPerson } from "@/types/chat/index";
class UserService {
  static instance: UserService;
  static getInstance() {
    if (!UserService.instance) {
      UserService.instance = new UserService();
    }
    return UserService.instance;
  }

  contact_custom_service(data: { outLetID: number }) {
    return baseAxios<iContact>({
      url: "/user/contact_custom_service",
      method: "post",
      data,
    });
  }

  staffInfo(data: { addrs: string[] }) {
    return baseAxios<{
      total: number;
      item: (iContact & { out_let_name: string })[];
    }>({
      url: "/user/staff_info",
      method: "post",
      data: data,
    });
  }

  userInfo(data: { addrs: string[] }) {
    return baseAxios<iUserinfo[]>({
      url: "/user/user_info",
      method: "post",
      data: data,
    });
  }

  getChatToken() {
    return baseAxios<{ addr: string; token: string }>({
      url: "/chat_info",
    });
  }

  userGetAccountManager() {
    return baseAxios<
      (Omit<iContactPerson, "address"> & { addr: string }) | null
    >({
      url: "/user/myAccountManager",
      method: "get",
    }).then((ret) => {
      if (!ret.data) {
        const { data, ...otherValues } = ret;
        return {
          ...otherValues,
          data: null,
        };
      }
      const { addr, ...otherValues } = ret.data;
      return {
        ...ret,
        data: {
          ...otherValues,
          address: addr,
        },
      };
    });
  }
}

export default UserService;
