// Hardcoded default relay URL. Recap users never see or configure this
// — it's baked into the build so Grant (operator) controls relay
// routing entirely through Recap version updates. Bump this constant
// in a new Recap release to point everyone at a different relay host.
//
// Empty string disables the relay path entirely (the "Relay (comped
// credits)" picker option will fail with "baseURL required" — caught
// by the provider-not-configured guard upstream).
//
// Override at runtime via the RECAP_RELAY_BASE_URL env var for local
// dev testing only — there's no StartOS action exposed for this, so
// production installs always use the hardcoded value.
import { relayOperatorKey } from "./config.js";

const DEFAULT_RELAY_BASE_URL = "https://relay.recaps.cc";

export function getRelayBaseURL() {
  const fromEnv = (process.env.RECAP_RELAY_BASE_URL || "").trim();
  return fromEnv || DEFAULT_RELAY_BASE_URL;
}

// Shared "operator key" (core-decoupling): the secret that authenticates
// THIS cloud Recaps server to the relay so it can vouch for its signed-in
// users by account-id (X-Recap-User-Id) instead of attaching a per-user
// Keysat license. Set the SAME value in the relay's relay_cloud_operator_key.
// Empty = cloud user-id identity is disabled; paid users fall back to the
// operator pool. Server-side only — never sent to the browser.
//
// Resolution: the RECAP_RELAY_OPERATOR_KEY env var pins it (local dev);
// otherwise the value comes from the StartOS config sidecar via config.js's
// polled `relayOperatorKey` live binding (set by the "Set Relay Operator
// Key" action, picked up within one poll — no restart needed).
export function getRelayOperatorKey() {
  const fromEnv = (process.env.RECAP_RELAY_OPERATOR_KEY || "").trim();
  if (fromEnv) return fromEnv;
  return (relayOperatorKey || "").trim();
}
