import axios from 'axios';
import { API_URL_ADDITIONAL_SERVICE } from '@/shared/api/api-url-additional-service';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import {
  ExtensionPayoutDetailDownloadCertificateParams,
  ExtensionPayoutDetailDownloadCertificateResponse
} from '../../model/payout/types';
import {
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const extensionPayoutDetailDownloadCertificate = (params: ExtensionPayoutDetailDownloadCertificateParams) => {
  let headerOptions = {
    menuId: 53,
    apiType: 'SELECT'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<ExtensionPayoutDetailDownloadCertificateResponse>(API_URL_ADDITIONAL_SERVICE.extensionPayoutDetailDownloadCertificate(), params, options),
  );
};

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

  return {
    ...mutation,
  };
};
