'use strict';

const MODES = Object.freeze({
  LOCAL_WINDOWS: 'local_windows',
  CONNECTOR_WINDOWS_SERVICE: 'connector_windows_service',
  CLOUD_SERVER: 'cloud_server',
});

function getRuntimeMode() {
  const raw = (process.env.ARKHON_MODE || MODES.LOCAL_WINDOWS).trim().toLowerCase();
  if (raw === 'local_connector') return MODES.CONNECTOR_WINDOWS_SERVICE;
  if (raw === 'cloud') return MODES.CLOUD_SERVER;
  if (Object.values(MODES).includes(raw)) return raw;
  return MODES.LOCAL_WINDOWS;
}

function isOfflineFirstEnabled() {
  return String(process.env.ARKHON_OFFLINE_FIRST || 'true').toLowerCase() !== 'false';
}

function isLocalRuntime(mode = getRuntimeMode()) {
  return mode === MODES.LOCAL_WINDOWS || mode === MODES.CONNECTOR_WINDOWS_SERVICE;
}

function isConnectorRuntime(mode = getRuntimeMode()) {
  return mode === MODES.LOCAL_WINDOWS || mode === MODES.CONNECTOR_WINDOWS_SERVICE;
}

function isCloudRuntime(mode = getRuntimeMode()) {
  return mode === MODES.CLOUD_SERVER;
}

module.exports = {
  MODES,
  getRuntimeMode,
  isOfflineFirstEnabled,
  isLocalRuntime,
  isConnectorRuntime,
  isCloudRuntime,
};
