import 'package:flutter/material.dart'; enum FieldTestEventType { rideStart, rideEnd, gpsFix, gpsHealthChanged, gpsLost, gpsRecovered, gpsBaselineReset, gpsOutlierRejected, speedZeroSnap, speedOutlier, speedChanged, imuSample, imuAnomaly, imuSpikeFiltered, calibrationLoaded, calibrationChanged, gForcePeak, leanPeak, telemetryStarted, telemetryStopped, telemetryBatchFlushed, telemetryPersistenceError, roadAlertReceived, roadAlertDeduplicated, roadAlertExpired, ttsRequested, ttsSuccess, ttsFailure, databaseWrite, databaseWriteFailure, appPaused, appResumed, appBackgrounded, appForegrounded, rideRecovery, rideInterrupted, thermalWarning, memoryWarning, loggerStarted, loggerStopped, loggerFlush, loggerError, } enum FieldTestSeverity { debug, info, warning, error, critical, } extension FieldTestSeverityExtension on FieldTestSeverity { Color get color { switch (this) { case FieldTestSeverity.debug: return Colors.grey; case FieldTestSeverity.info: return Colors.cyanAccent; case FieldTestSeverity.warning: return Colors.amberAccent; case FieldTestSeverity.error: return Colors.orangeAccent; case FieldTestSeverity.critical: return Colors.redAccent; } } String get label => name.toUpperCase(); } enum HealthScoreCategory { good, degraded, warning, critical, } extension HealthScoreCategoryExtension on HealthScoreCategory { Color get color { switch (this) { case HealthScoreCategory.good: return Colors.greenAccent; case HealthScoreCategory.degraded: return Colors.cyanAccent; case HealthScoreCategory.warning: return Colors.amberAccent; case HealthScoreCategory.critical: return Colors.redAccent; } } String get label => name.toUpperCase(); } class SystemHealthSummary { final HealthScoreCategory gpsHealth; final HealthScoreCategory sensorsHealth; final HealthScoreCategory persistenceHealth; final HealthScoreCategory lifecycleHealth; final HealthScoreCategory roadAlertsHealth; final HealthScoreCategory ttsHealth; final int totalAnomalies; final int criticalCount; final int warningCount; const SystemHealthSummary({ required this.gpsHealth, required this.sensorsHealth, required this.persistenceHealth, required this.lifecycleHealth, required this.roadAlertsHealth, required this.ttsHealth, required this.totalAnomalies, required this.criticalCount, required this.warningCount, }); Map toJson() => { 'gpsHealth': gpsHealth.name, 'sensorsHealth': sensorsHealth.name, 'persistenceHealth': persistenceHealth.name, 'lifecycleHealth': lifecycleHealth.name, 'roadAlertsHealth': roadAlertsHealth.name, 'ttsHealth': ttsHealth.name, 'totalAnomalies': totalAnomalies, 'criticalCount': criticalCount, 'warningCount': warningCount, }; factory SystemHealthSummary.fromJson(Map json) { return SystemHealthSummary( gpsHealth: HealthScoreCategory.values.byName(json['gpsHealth'] ?? 'good'), sensorsHealth: HealthScoreCategory.values.byName(json['sensorsHealth'] ?? 'good'), persistenceHealth: HealthScoreCategory.values.byName(json['persistenceHealth'] ?? 'good'), lifecycleHealth: HealthScoreCategory.values.byName(json['lifecycleHealth'] ?? 'good'), roadAlertsHealth: HealthScoreCategory.values.byName(json['roadAlertsHealth'] ?? 'good'), ttsHealth: HealthScoreCategory.values.byName(json['ttsHealth'] ?? 'good'), totalAnomalies: json['totalAnomalies'] ?? 0, criticalCount: json['criticalCount'] ?? 0, warningCount: json['warningCount'] ?? 0, ); } } class AnomalyEvent { final DateTime timestamp; final FieldTestEventType type; final FieldTestSeverity severity; final String title; final String details; const AnomalyEvent({ required this.timestamp, required this.type, required this.severity, required this.title, required this.details, }); }