import axios from 'axios';
import { ActionContext, ActionTree, mapActions } from 'vuex';

export const state = {};

export const getters = {};

export const mutations = {};

export const actions: ActionTree<any, any> = {
  dispatchPrint(
    { commit }: ActionContext<any, any>,
    { format, model, template } = {}
  ) {
    return new Promise((resolve, reject) => {
      const url = `${document.location.origin}/service/report/report/print`;

      axios({
        data: {
          format,
          model,
          template,
        },
        method: 'POST',
        responseType: 'blob',
        url,
      })
        .then((response) => {
          return resolve(response.data);
        })
        .catch((e) => {
          return reject(e);
        });
    });
  },
};

export const reportReportMethods = mapActions('report/report', [
  'dispatchPrint',
]);
