import type { Config } from '@/types/Config'
import axios from 'axios'

let configObject = null as Config | null

export async function getConfig() {
  if (configObject) return Promise.resolve(configObject)

  configObject = await axios.get('/config.json?noCache=' + Date.now()).then((resp) => {
    return {
      apiBaseURL: resp.data.apiBaseURL,
      oidcAuthority: resp.data.oidcAuthority,
      oidcClientID: resp.data.oidcClientID,
      oidcProjectID: resp.data.oidcProjectID
    } as Config
  })
  return configObject
}
