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 { 
  CashReceiptReceiptDownloadParams,
  CashReceiptReceiptDownloadResponse
} from '../model/types';
import { 
  useMutation,
  UseMutationOptions
} from '@tanstack/react-query';
import { getHeaderUserAgent } from '@/shared/constants/url';

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

export const useCashReceiptReceiptDownloadMutation = (options?: UseMutationOptions<CashReceiptReceiptDownloadResponse, NiceAxiosError, CashReceiptReceiptDownloadParams>) => {
  const mutation = useMutation<CashReceiptReceiptDownloadResponse, NiceAxiosError, CashReceiptReceiptDownloadParams>({
    ...options,
    mutationFn: (params: CashReceiptReceiptDownloadParams) => cashReceiptReceiptDownload(params),
  });

  return {
    ...mutation,
  };
};
