import { useMutation, useQueryClient } from "@tanstack/react-query";
import type { UseMutationResult } from "@tanstack/react-query";
import { approvePartnerAccess } from "../services/legal-api";
import { LEGAL_QUERY_KEYS } from "./use-legal-query";

export const useApprovePartnerMutation = (): UseMutationResult<
  void,
  Error,
  string
> => {
  const queryClient = useQueryClient();

  return useMutation<void, Error, string>({
    mutationFn: (partnerId: string) => approvePartnerAccess(partnerId),
    onSuccess: () => {
      queryClient.invalidateQueries({
        queryKey: LEGAL_QUERY_KEYS.pending(),
      });
    },
  });
};
