import baseAxios from "../index";
import { iContact, iUserinfo } from "./types";
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: "get",
      params: data,
      paramsSerializer: (data: { addrs: string[] }) => {
        console.log(data);
        return `addrs=${data.addrs.toString()}`;
      },
    });
  }

  userInfo(data: { addrs: string[] }) {
    return baseAxios<iUserinfo[]>({
      url: "/user/user_info",
      method: "get",
      params: data,
      paramsSerializer: (data: { addrs: string[] }) => {
        console.log(data);
        return `addrs=${data.addrs.toString()}`;
      },
    });
  }

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

export default UserService;
