// Container-engine identity for host-cp.
//
// Phase 1a / A1: defaults to "docker"; switches to "kubernetes" when running
// inside a K8s pod (autodetected via KUBERNETES_SERVICE_HOST). Operators can
// override either way via OLAM_HOST_CP_ENGINE.
//
// This module exists separately from server.mjs to keep the engine-resolution
// logic pure (no I/O, no mkdir, no global side-effects) so unit tests can
// import it without triggering server startup. server.mjs imports
// resolveHostCpEngine from here and computes its module-level HOST_CP_ENGINE
// constant.
//
// KubernetesEngine adapter (Phase B / PR3) consumes the same env variables
// when constructing the engine; the context-allowlist guard (T6 / Decision 10)
// lives inside that adapter, not here. This module is "what name to surface
// in the X-Olam-Engine response header" — nothing more.

/**
 * Resolve the active container-engine identity for host-cp.
 *
 * Precedence (matches HOST_CP_MODE convention at server.mjs:85-87):
 *   1. Explicit env override: OLAM_HOST_CP_ENGINE=docker|kubernetes
 *   2. Autodetect: KUBERNETES_SERVICE_HOST set → "kubernetes"
 *   3. Default: "docker"
 *
 * @param {NodeJS.ProcessEnv} [env=process.env] - environment to inspect.
 * @returns {string} - engine identity surfaced via X-Olam-Engine header.
 */
export function resolveHostCpEngine(env = process.env) {
  return env.OLAM_HOST_CP_ENGINE
    ?? (env.KUBERNETES_SERVICE_HOST ? 'kubernetes' : 'docker');
}
