import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiPutForm } from "../../../../../lib/api/methods";
import { SETTINGS_ENDPOINTS } from "../endpoints";
import { errorToast, successToast } from "../../../../../utils/toast";
import { SUCCESS_MESSAGES } from "./messages";


export default function useUpdatePlatformLogo() {
  const queryClient = useQueryClient();
  const { mutateAsync, isPending } = useMutation({
    mutationKey: ["update-platform-logo"],
    mutationFn: async (data: FormData) => {
      const response = await apiPutForm(SETTINGS_ENDPOINTS.PLATFORM_LOGO, data);
      return response.data;
    },
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["platform-settings"] });
      successToast(SUCCESS_MESSAGES.UPDATE_LOGO);
    },
    onError: (error) => {
      errorToast("Something Went Wrong");
    },
  });

  return {
    updatePlatformLogo: mutateAsync,
    isUpdatingPlatformLogo: isPending,
  };
}
