class FollowUpMessage { const FollowUpMessage({ required this.id, required this.seq, required this.role, required this.content, required this.timestamp, }); final String id; final int seq; final String role; final String content; final DateTime timestamp; factory FollowUpMessage.fromJson(Map json) { return FollowUpMessage( id: _requiredString(json, 'id'), seq: _requiredInt(json, 'seq'), role: _requiredString(json, 'role'), content: _requiredStringAllowEmpty(json, 'content'), timestamp: DateTime.parse(_requiredString(json, 'timestamp')).toLocal(), ); } } String _requiredString(Map json, String key) { final value = json[key]; if (value is! String || value.isEmpty) { throw FormatException('Missing required string: $key'); } return value; } String _requiredStringAllowEmpty(Map json, String key) { final value = json[key]; if (value is! String) { throw FormatException('Missing required string: $key'); } return value; } int _requiredInt(Map json, String key) { final value = json[key]; if (value is int) { return value; } if (value is num) { return value.toInt(); } throw FormatException('Missing required int: $key'); }