import fetch from 'isomorphic-unfetch';
import invokeApi from '../helpers/apiHelpers';
import apiPath from '../constants/apiPath';
import config from '../config';

export const initialPdfFile = async (token: string): Promise<any> => invokeApi({
  path: apiPath.initPdf,
  method: 'GET',
  data: {
    f: token,
  },
});

export const saveFile = async (token: string, data: any): Promise<any> => invokeApi({
  path: `${apiPath.saveFile}?f=${token}`,
  method: 'POST',
  data,
});

export const fetchXfdf = (token: string): Promise<any> => (
  fetch(`${config.API_HOST}${apiPath.getXfdf}?f=${token}`).then(res => res.text())
);

export default {};
