import { createTelemetryClient } from '@bytelyst/telemetry-client';
import { mobileRuntime } from '@/lib/runtime';
import { productConfig } from '../../shared/product.js';

export const mobileTelemetry = createTelemetryClient({
  productId: mobileRuntime.productId,
  baseUrl: mobileRuntime.platformApiUrl,
  platform: 'mobile',
  channel: 'invttrdg_mobile',
  transport: 'fetch',
  appVersion: productConfig.version,
  releaseChannel: process.env.NODE_ENV === 'production' ? 'prod' : 'dev',
});

export function trackMobileError(module: string, eventName: string, error: unknown, tags?: Record<string, string>) {
  mobileTelemetry.trackEvent('error', module, eventName, {
    message: error instanceof Error ? error.message : String(error),
    tags,
  });
}
