// Telemetry utility — routes frontend events to backend via BackendAdapter
// Replaces telemetry-bridge.ts (which imported Tauri invoke directly)

import { getBackend } from '../backend/backend';

/** Convenience wrappers for structured logging */
export const tel = {
  error: (msg: string, ctx?: Record<string, unknown>) => {
    try { getBackend().telemetryLog('error', msg, ctx); } catch { /* backend not ready */ }
  },
  warn: (msg: string, ctx?: Record<string, unknown>) => {
    try { getBackend().telemetryLog('warn', msg, ctx); } catch { /* backend not ready */ }
  },
  info: (msg: string, ctx?: Record<string, unknown>) => {
    try { getBackend().telemetryLog('info', msg, ctx); } catch { /* backend not ready */ }
  },
  debug: (msg: string, ctx?: Record<string, unknown>) => {
    try { getBackend().telemetryLog('debug', msg, ctx); } catch { /* backend not ready */ }
  },
  trace: (msg: string, ctx?: Record<string, unknown>) => {
    try { getBackend().telemetryLog('trace', msg, ctx); } catch { /* backend not ready */ }
  },
};
