import { useQuery } from "@tanstack/react-query";
import { useAuthToken } from "../hooks/use-root-data";
import { createFollowsManagementApi } from "~/utils/api-client-factory";

/**
 * Custom hook to get the list of sellers followed by the current user
 */
export function useServiceGetFollowedSellers() {
  const token = useAuthToken();

  return useQuery({
    queryKey: ["getFollowedSellersService"],
    queryFn: async () => {
      if (!token) {
        throw new Error("Authentication token is required");
      }
      const followsApi = createFollowsManagementApi(token);
      return await followsApi.apiEngagementV1FollowsListList();
    },
    enabled: !!token,
    retry: 1,
    retryDelay: 3000,
    refetchOnWindowFocus: false,
  });
}
