import type { contextObject } from "src/page-contexts/pages/types/context-object";
import type { Message } from "../types/dialogue-message";
import { api } from "src/boot/axios";

export const chatbotService = {
  // Function to send the message to the backend
  sendChatMessage: async (userInput: string): Promise<Message> => {
    const response = await api.post("/chat/respond", { userInput });
    return response.data as Message;
  },

  // Function to send context to backend
  sendPageContext: async (context: contextObject): Promise<string> => {
    const response = await api.post("/chat/context", context);
    return response.data;
  },

  // Function to send user credentials to the backend to communicate with n8n.
  // Will have to modify later on to accomodate newer versions of User Auth/User Structure
  sendUserCredentials: async (
    email: string,
    role: string
  ): Promise<boolean> => {
    const response = await api.post("/chat/user", { email, role });
    return response.data;
  },
};
