import axios, { type AxiosInstance } from "axios";

class TypingService {
  axios: AxiosInstance | null = null;

  constructor() {
    this.axios = axios.create({
      baseURL: import.meta.env.VITE_API_TYPE_URL,
      headers: {
        "Content-Type": "application/json",
      },
    });
  }

  async send(
    message: string
  ): Promise<{ status: boolean; typed: string } | null> {
    if (!this.axios) return null;

    const { data } = await this.axios({
      method: "POST",
      url: "type",
      data: {
        message,
      },
    });

    return data;
  }
}

export const typeingService = new TypingService();
