CausalEvent.fromJson constructor
Deserializes from JSON. Throws ArgumentError if type field has an invalid enum name.
Implementation
factory CausalEvent.fromJson(Map<String, dynamic> json) {
final typeName = json['type'] as String;
final CausalEventType eventType;
try {
eventType = CausalEventType.values.byName(typeName);
} catch (_) {
throw ArgumentError('Invalid CausalEventType: "$typeName"');
}
return CausalEvent(
id: json['id'] as String,
parentId: json['parentId'] as String?,
type: eventType,
description: json['description'] as String,
timestamp: DateTime.parse(json['timestamp'] as String),
metadata: json['metadata'] != null
? Map<String, dynamic>.from(json['metadata'] as Map)
: const {},
duration: json['duration_ms'] != null
? Duration(milliseconds: json['duration_ms'] as int)
: null,
);
}