import { chatQueryKeys } from '../chat-query-keys';
import { type PostGetUnreadCountReturn, chatApi } from '../chat-api';
import { queryClient } from 'src/utils/queryClient';

export const fetchUnreadMessagesCount = async (token: string) => {
  try {
    const data: PostGetUnreadCountReturn = await queryClient.fetchQuery({
      queryKey: chatQueryKeys.getUnreadMessagesCount(token),
      queryFn: async () => {
        const response = await chatApi.getUnreadMessagesCount(token);
        return response.data;
      },
      gcTime: 0,
      staleTime: 0
    });

    return data;
  } catch (error) {
    console.error('Failed to fetch unread messages count:', error);
  }
};
