/* eslint-disable @typescript-eslint/no-explicit-any */ import { getChatConfig } from "../Chat.config"; import { FileType } from "../components/common/FilePreview"; import { Path } from "../lib/api/endpoint"; export const sendMessage = async (params: { receiverId: string; senderId: string; message: string; attachments: { type: FileType; url: string; name: string; size: number }[]; bookingId?: string; serviceTitle?: string; type?: "personal" | "service"; serviceId?: string; senderRole?: string; receiverRole?: string; }) => { const { receiverId, senderId, message, attachments, bookingId, serviceTitle, type, serviceId, senderRole, receiverRole, } = params; // const apiClient = getApiClient(); const {apiClient,apiUrl} = getChatConfig(); const response = await apiClient.post( `${apiUrl}/${Path.sendmessage}/${receiverId}/${senderId}`, { message, attachments, bookingId, serviceTitle, type, serviceId, messageType: "user", senderRole, receiverRole } ); return response.data; }; export const fetchMessages = async (chatId: string | undefined, userid: string, pagenum: number) => { const {apiClient,apiUrl} = getChatConfig(); try { const response = await apiClient.get(`${apiUrl}/${Path.getmessage}/${chatId}/${userid}`, { params: { pagenum, limit: 20 }, }); // console.log(response); return response.data; } catch (error) { console.error("Error fetching messages:", error); return []; } }; export const setEditMessage = async ({ messageId, userId, newMessage }: { messageId: string; userId: string; newMessage: string; }) => { const {apiClient,apiUrl} = getChatConfig(); try { const response = await apiClient.put(`${apiUrl}/${Path.editMessage}/${messageId}`, { userId, newMessage }); return response.data; } catch (error) { console.error("Error editing message:", error); throw error; } }; export const deleteMessage = async ({ messageId, userId }: { messageId: string; userId: string; }) => { const {apiClient,apiUrl} = getChatConfig(); try { const response = await apiClient.delete( `${apiUrl}/${Path.deleteMessage}/${messageId}`, { data: { userId } } ); return response.data; } catch (error) { console.error("Error deleting message:", error); throw error; } };