/**
 * Chain 138 OMNL address resolution — prefers v2 stack after cutover.
 */
export function omnlComplianceCore138(): string | undefined {
  const v2 = (process.env.OMNL_COMPLIANCE_CORE_V2_138 || '').trim();
  if (v2) return v2;
  return (process.env.OMNL_COMPLIANCE_CORE_138 || '').trim() || undefined;
}

export function omnlReserveStore138(): string | undefined {
  const v2 = (process.env.OMNL_RESERVE_STORE_V2_138 || '').trim();
  if (v2) return v2;
  const legacy = (process.env.OMNL_RESERVE_STORE_138 || '').trim();
  if (legacy) return legacy;
  return (process.env.OMNL_RESERVE_COMMITMENT_STORE || '').trim() || undefined;
}

export function omnlStackCutover(): {
  usingV2: boolean;
  complianceCore: string | undefined;
  reserveStore: string | undefined;
} {
  const complianceCore = omnlComplianceCore138();
  const reserveStore = omnlReserveStore138();
  const usingV2 = Boolean(
    (process.env.OMNL_COMPLIANCE_CORE_V2_138 || '').trim() &&
      complianceCore === (process.env.OMNL_COMPLIANCE_CORE_V2_138 || '').trim()
  );
  return { usingV2, complianceCore, reserveStore };
}
