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 { 
  ExtensionPayoutDetailDownloadCertificateParams,
  ExtensionPayoutDetailDownloadCertificateResponse
} from '../../model/payout/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';

export const extensionPayoutDetailDownloadCertificate = (params: ExtensionPayoutDetailDownloadCertificateParams) => {
  return resultify(
    axios.post<ExtensionPayoutDetailDownloadCertificateResponse>(API_URL_ADDITIONAL_SERVICE.extensionPayoutDetailDownloadCertificate(), params),
  );
};

export const useExtensionPayoutDetailDownloadCertificateMutation = (options?: UseMutationOptions<ExtensionPayoutDetailDownloadCertificateResponse, CBDCAxiosError, ExtensionPayoutDetailDownloadCertificateParams>) => {
  const mutation = useMutation<ExtensionPayoutDetailDownloadCertificateResponse, CBDCAxiosError, ExtensionPayoutDetailDownloadCertificateParams>({
    ...options,
    mutationFn: (params: ExtensionPayoutDetailDownloadCertificateParams) => extensionPayoutDetailDownloadCertificate(params),
  });

  return {
    ...mutation,
  };
};
