import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { CBDCAxiosError } from '@/shared/@types/error';
import {
    useMutation,
    UseMutationOptions
} from '@tanstack/react-query';
import { ExtensionLinkPayRequestParams, ExtensionLinkPayRequestResponse } from '../../model/types';

export const extensionLinkPayRequest = (params: ExtensionLinkPayRequestParams) => {
  return resultify(
    axios.post<ExtensionLinkPayRequestResponse>(API_URL_ADDITIONAL_SERVICE.extensionLinkPaymentRequest(), params),
  );
};

export const useExtensionLinkPayRequestMutation = (options?: UseMutationOptions<ExtensionLinkPayRequestResponse, CBDCAxiosError, ExtensionLinkPayRequestParams>) => {
  const mutation = useMutation<ExtensionLinkPayRequestResponse, CBDCAxiosError, ExtensionLinkPayRequestParams>({
    ...options,
    mutationFn: (params: ExtensionLinkPayRequestParams) => extensionLinkPayRequest(params),
  });

  return {
    ...mutation,
  };
};