Map<String, dynamic> toJson() { return { 'id': id, 'type': type, if (role != null) 'role': role, if (content != null) 'content': content, }; }