class CommentUser { final String id; final String displayName; CommentUser({ required this.id, required this.displayName, }); factory CommentUser.fromJson(Map json) { return CommentUser( id: json['id'].toString(), displayName: json['displayName'] ?? '', ); } Map toJson() { return { 'id': id, 'displayName': displayName, }; } } class Comment { final String id; final String postId; final CommentUser creator; final String body; final DateTime creationDate; final String? replyComment; final String? displayReplyComment; final CommentUser? replyUser; final int level; final List replies; Comment({ required this.id, required this.postId, required this.creator, required this.body, required this.creationDate, this.replyComment, this.displayReplyComment, this.replyUser, required this.level, required this.replies, }); factory Comment.fromJson(Map json) { return Comment( id: json['id'].toString(), postId: json['postId'].toString(), creator: CommentUser.fromJson(json['creator']), body: json['body'] ?? '', creationDate: DateTime.parse(json['creationDate']), replyComment: json['replyComment']?.toString(), displayReplyComment: json['displayReplyComment']?.toString(), replyUser: json['replyUser'] != null ? CommentUser.fromJson(json['replyUser']) : null, level: json['level'] ?? 1, replies: (json['replies'] as List?)?.map((reply) => Comment.fromJson(reply)).toList() ?? [], ); } Map toJson() { return { 'id': id, 'postId': postId, 'creator': creator.toJson(), 'body': body, 'creationDate': creationDate.toIso8601String(), 'replyComment': replyComment, 'displayReplyComment': displayReplyComment, 'replyUser': replyUser?.toJson(), 'level': level, 'replies': replies.map((reply) => reply.toJson()).toList(), }; } } class CommentsResponse { final bool status; final String? message; final List data; CommentsResponse({ required this.status, this.message, required this.data, }); factory CommentsResponse.fromJson(Map json) { return CommentsResponse( status: json['status'] ?? false, message: json['message'], data: json['data'] != null ? (json['data'] as List).map((comment) => Comment.fromJson(comment)).toList() : [], ); } Map toJson() { return { 'status': status, 'message': message, 'data': data.map((comment) => comment.toJson()).toList(), }; } }