/**
 * config/proxy-version.js — Single source of truth for oracle-proxy.py version tracking.
 *
 * Owns: LATEST_PROXY_VERSION constant + versionLessThan() semver helper.
 * Imported by: server.js, routes/agent.js, routes/connections-list.js.
 *
 * To bump the proxy version: change LATEST_PROXY_VERSION here only.
 * Do NOT keep separate copies in server.js or route files.
 */

'use strict';

/** Current canonical oracle-proxy.py version. Bump when VERSION in oracle-proxy.py changes. */
const LATEST_PROXY_VERSION = '3.21.16';

/**
 * Returns true if version string `a` is strictly older than `b`.
 * Parses each segment as an integer so 3.20.9 < 3.20.10 compares correctly.
 * Treats null/undefined `a` as infinitely old (always returns true).
 */
function versionLessThan(a, b) {
  if (!a) return true;
  const parse = v => (v || '0.0.0').replace(/[^0-9.]/g, '').split('.').map(Number);
  const [aM, am, ap] = parse(a);
  const [bM, bm, bp] = parse(b);
  if (aM !== bM) return aM < bM;
  if (am !== bm) return am < bm;
  return ap < bp;
}

module.exports = { LATEST_PROXY_VERSION, versionLessThan };
