// Comment data models for Coves // // These models match the backend response structure from: // /xrpc/social.coves.community.comment.getComments import 'post.dart'; class CommentsResponse { CommentsResponse({required this.post, this.cursor, required this.comments}); factory CommentsResponse.fromJson(Map json) { // Handle null comments array from backend final commentsData = json['comments']; final List commentsList; if (commentsData == null) { // Backend returned null, use empty list commentsList = []; } else { // Parse comment items commentsList = (commentsData as List) .map( (item) => ThreadViewComment.fromJson(item as Map), ) .toList(); } return CommentsResponse( post: json['post'], cursor: json['cursor'] as String?, comments: commentsList, ); } final dynamic post; final String? cursor; final List comments; } class ThreadViewComment { ThreadViewComment({ required this.comment, this.replies, this.hasMore = false, }); factory ThreadViewComment.fromJson(Map json) { return ThreadViewComment( comment: CommentView.fromJson(json['comment'] as Map), replies: json['replies'] != null ? (json['replies'] as List) .map( (item) => ThreadViewComment.fromJson( item as Map, ), ) .toList() : null, hasMore: json['hasMore'] as bool? ?? false, ); } final CommentView comment; final List? replies; final bool hasMore; } class CommentView { CommentView({ required this.uri, required this.cid, required this.content, this.contentFacets, required this.createdAt, required this.indexedAt, required this.author, required this.post, this.parent, required this.stats, this.viewer, this.embed, }); factory CommentView.fromJson(Map json) { return CommentView( uri: json['uri'] as String, cid: json['cid'] as String, content: json['content'] as String, contentFacets: json['contentFacets'] != null ? (json['contentFacets'] as List) .map((f) => PostFacet.fromJson(f as Map)) .toList() : null, createdAt: DateTime.parse(json['createdAt'] as String), indexedAt: DateTime.parse(json['indexedAt'] as String), author: AuthorView.fromJson(json['author'] as Map), post: CommentRef.fromJson(json['post'] as Map), parent: json['parent'] != null ? CommentRef.fromJson(json['parent'] as Map) : null, stats: CommentStats.fromJson(json['stats'] as Map), viewer: json['viewer'] != null ? CommentViewerState.fromJson( json['viewer'] as Map, ) : null, embed: json['embed'], ); } final String uri; final String cid; final String content; final List? contentFacets; final DateTime createdAt; final DateTime indexedAt; final AuthorView author; final CommentRef post; final CommentRef? parent; final CommentStats stats; final CommentViewerState? viewer; final dynamic embed; } class CommentRef { CommentRef({required this.uri, required this.cid}); factory CommentRef.fromJson(Map json) { return CommentRef(uri: json['uri'] as String, cid: json['cid'] as String); } final String uri; final String cid; } class CommentStats { CommentStats({this.upvotes = 0, this.downvotes = 0, this.score = 0}); factory CommentStats.fromJson(Map json) { return CommentStats( upvotes: json['upvotes'] as int? ?? 0, downvotes: json['downvotes'] as int? ?? 0, score: json['score'] as int? ?? 0, ); } final int upvotes; final int downvotes; final int score; } class CommentViewerState { CommentViewerState({this.vote}); factory CommentViewerState.fromJson(Map json) { return CommentViewerState(vote: json['vote'] as String?); } final String? vote; }