import { type UseMutationOptions, useMutation } from 'react-query';

import { type AxiosError, type AxiosResponse } from 'axios';

import { signDocument } from 'src/services/documents';
import {
  type Document,
  type DocumentSignSubmitData,
} from 'src/types/documents';
import { type ResponseError } from 'src/types/services';

type Options = UseMutationOptions<
  AxiosResponse<Document>,
  AxiosError<ResponseError>,
  DocumentSignSubmitData
>;

const useSignDocument = (options: Options) => {
  return useMutation({
    mutationFn: (payload: DocumentSignSubmitData) => signDocument(payload),
    ...options,
  });
};

export default useSignDocument;
