import { API_ENDPOINTS } from "@/lib/api";
import { contactUsService } from "@/lib/api/services/contact-us-service";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useMemo } from "react";
import { toast } from "react-toastify";

export const useReadAllContactUs = (params?: Record<string, unknown>) => {
  const queryKey = useMemo(
    () => [API_ENDPOINTS.CONTACT_US.BASE(), params],
    [params],
  );

  return useQuery({
    queryKey,
    queryFn: () => contactUsService.getAllContactUs(params),
  });
};
export const useDeleteContactUs = (successCallback?: () => void) => {
  const queryClient = useQueryClient();
  const mutationKey = useMemo(
    () => [API_ENDPOINTS.CONTACT_US.BASE(), "DELETE CONTACT US"],
    [],
  );
  return useMutation({
    mutationKey,
    mutationFn: contactUsService.deleteContactUs,
    onSuccess: (response) => {
      toast.success(response.data.message);

      successCallback?.();
      queryClient.invalidateQueries({
        queryKey: [API_ENDPOINTS.CONTACT_US.BASE()],
      });
    },
  });
};
