import Vue from 'vue';
import { auth } from '@services/AuthService';
import { AxiosRequestConfig } from 'axios';
import { Configuration, ConfigurationParameters } from '@openapi/preorder-pgs';

/*
 * Конфигурация сервиса
 */
const initParams = async (): Promise<ConfigurationParameters> => {
  return {
    basePath: '/service/preorder/service',
    accessToken: await auth.getAccessToken(),
  };
};

export const axiosOptions: AxiosRequestConfig = {
  responseType: 'json',
  headers: {
    Accept: '*/*',
  },
};

export const configCreator = async (): Promise<Configuration | undefined> => {
  try {
    return new Configuration(await initParams());
  } catch (e) {
    console.error(`[services/preorder-pgs/configCreator] - ${e.toString()}`);
  }
};
