import { useTaehuiStore } from "@/state/Stores";

import { wwwAPI } from "@/utilities/wwwAPI";
import { useMutation, useQueryClient } from "@tanstack/react-query";
import { getMillis } from "taehui-lib/date";

export default function useWipeAutoEssay() {
  const { totem } = useTaehuiStore();

  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: async ({
      forumID,
      autoEssayID,
    }: {
      forumID: string;
      autoEssayID: number;
    }) => {
      await wwwAPI.delete(`/autoEssay/${forumID}/${autoEssayID}`, {
        headers: { millis: getMillis(), totem },
      });
    },
    onSuccess: async () => {
      await queryClient.invalidateQueries({ queryKey: ["autoEssay"] });
    },
  });
}
