import {
  ConfigurationParameters,
  Configuration,
} from '@openapi/idm/configuration';
import { auth } from '@services/AuthService';

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

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