import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
  createSignature,
  getSignature,
  updateSignature,
} from "../service/Service";
import type { SignatureData } from "../types/Types";

export const useSignatureData = () => {
  return useQuery({
    queryKey: ["signature-data"],
    queryFn: getSignature,
    retry: false,
  });
};

export const useCreateSignature = () => {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: (data: SignatureData) => createSignature(data),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["signature-data"] });
    },
  });
};

export const useUpdateSignature = () => {
  const queryClient = useQueryClient();

  return useMutation({
    mutationFn: (data: SignatureData) => updateSignature(data),
    onSuccess: () => {
      queryClient.invalidateQueries({ queryKey: ["signature-data"] });
    },
  });
};
