import {
  riskDataGapSeconds,
  riskDeltaAbs,
  riskDrawdownPct,
  riskHedgeFailures,
  riskStatus
} from "../../telemetry/src/metrics";

export interface RiskMetricsSnapshot {
  deltaAbs: number;
  hedgeFailures: number;
  dataGapSeconds: number;
  drawdownPct: number;
  halted: boolean;
  haltReason?: string;
}

export function emitRiskMetrics(snapshot: RiskMetricsSnapshot): void {
  riskDeltaAbs.set(snapshot.deltaAbs);
  riskHedgeFailures.set(snapshot.hedgeFailures);
  riskDataGapSeconds.set(snapshot.dataGapSeconds);
  riskDrawdownPct.set(snapshot.drawdownPct);

  const reason = snapshot.halted ? snapshot.haltReason ?? "unknown" : "running";
  riskStatus.set({ reason }, snapshot.halted ? 1 : 0);
}
