const { MAST_API_BASE_PATH, MAST_API_BASE_PATH_LEGACY } = require('./constants')

/**
 * Temporarily support backwards compatibility with mast/matrix routes.
 * Until all environments are listening on /matrix at the conclusion of release 6.4.0, we need to handle
 * the possibility that some environments will listen to MAST on /mast or /matrix
 *
 * This temporary code can be removed in release 6.5.0 - CORE-7670
 */
async function getMastApiBasePath (client, instance) {
  try {
    await client._fetch('GET', `${MAST_API_BASE_PATH}/${instance}/instances/${instance}/assessments`)
    return MAST_API_BASE_PATH
  } catch (_) {
    // no-op, we want to fall back to legacy route.
  }

  return MAST_API_BASE_PATH_LEGACY
}

module.exports = { getMastApiBasePath }
