import axios from 'axios';
import fetchAdapter from '@vespaiach/axios-fetch-adapter';

const axiosGet = axios.create({
  baseURL: '',
  headers: {
    'accept': 'application/json, application/force-download, text/plain, */*',
  },
  adapter: fetchAdapter,
});

axiosGet.interceptors.response.use((response) => response.data);

/**
 * @param {string} url
 * @returns {Promise<ArrayBuffer>}
 */
export const getPdfFromUrl = async (url) => {
  const payload = {
    responseType: 'arraybuffer',
    headers: {
      'accept': 'application/json, application/force-download, text/plain, */*',
    },
  };

  return axiosGet.get(url, payload);
};
