import axios from 'axios';
import { API_URL_TRANSACTION } from '@/shared/api/api-url-transaction';
import { resultify } from '@/shared/lib/resultify';
import { NiceAxiosError } from '@/shared/@types/error';
import { 
  DownloadConfirmationParams,
  DownloadConfirmationResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

export const downloadConfirmation = (params: DownloadConfirmationParams) => {
  let headerOptions = {
    menuId: 31,
    apiType: 'DOWNLOAD'
  };
  let options = {
    headers: {
      'X-User-Agent': getHeaderUserAgent(headerOptions)
    }
  };
  return resultify(
    axios.post<DownloadConfirmationResponse>(API_URL_TRANSACTION.downloadConfirmation(), params, options),
  );
};

export const useDownloadConfirmationMutation = (options?: UseMutationOptions<DownloadConfirmationResponse, NiceAxiosError, DownloadConfirmationParams>) => {
  const mutation = useMutation<DownloadConfirmationResponse, NiceAxiosError, DownloadConfirmationParams>({
    ...options,
    mutationFn: (params: DownloadConfirmationParams) => downloadConfirmation(params),
  });

  return {
    ...mutation,
  };
};
