import { GetForumAPI } from "@/type/wwwAPI";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useQuery } from "@tanstack/react-query";
import { useLanguage } from "taehui-lib/language";

export default function useGetForum(forumID: string, page: number) {
  const language = useLanguage();

  return useQuery({
    queryKey: ["forum", forumID, page, language],
    queryFn: async () => {
      const { data } = await wwwAPI.get<GetForumAPI>(`/forum/${forumID}`, {
        params: {
          page,
          language,
        },
      });
      return data;
    },
    initialData: {
      title: "",
      text: "",
      essays: [],
      essayCount: 0,
      level: 0,
    },
  });
}
