/// 评论模型(《03-接口文档》6.3/6.4/6.5,对应服务端 interaction_service 输出) class CommentItem { CommentItem({ required this.commentId, required this.userId, this.nickname = '', this.avatarUrl = '', this.content = '', this.likeCount = 0, this.replyCount = 0, this.createdAt = '', }); final int commentId; final int userId; final String nickname; final String avatarUrl; final String content; final int likeCount; /// 一级评论的回复数(二级回复列表项恒为 0) final int replyCount; final String createdAt; CommentItem copyWith({int? replyCount}) => CommentItem( commentId: commentId, userId: userId, nickname: nickname, avatarUrl: avatarUrl, content: content, likeCount: likeCount, replyCount: replyCount ?? this.replyCount, createdAt: createdAt, ); factory CommentItem.fromJson(Map json) { final user = (json['user'] as Map?) ?? const {}; return CommentItem( commentId: (json['comment_id'] as num?)?.toInt() ?? 0, userId: (user['user_id'] as num?)?.toInt() ?? 0, nickname: (user['nickname'] as String?) ?? '', avatarUrl: (user['avatar_url'] as String?) ?? '', content: (json['content'] as String?) ?? '', likeCount: (json['like_count'] as num?)?.toInt() ?? 0, replyCount: (json['reply_count'] as num?)?.toInt() ?? 0, createdAt: (json['created_at'] as String?) ?? '', ); } } /// 评论分页(普通 page/page_size 分页,《03-接口文档》1.4) class CommentListPage { CommentListPage({required this.total, required this.items}); final int total; final List items; factory CommentListPage.fromJson(Map json) => CommentListPage( total: (json['total'] as num?)?.toInt() ?? 0, items: ((json['list'] as List?) ?? const []) .whereType>() .map(CommentItem.fromJson) .toList(), ); } /// 评论积分奖励进度(发表/删除评论响应中的 reward_progress) class RewardProgress { RewardProgress({ required this.current, required this.target, this.rewardedThisTime = false, this.rewardPoints = 0, }); /// 当前进度(满 target 自动发奖并清零) final int current; final int target; /// 本次是否触发发奖 final bool rewardedThisTime; /// 本次发放积分数(未发奖为 0) final int rewardPoints; factory RewardProgress.fromJson(Map json) => RewardProgress( current: (json['current'] as num?)?.toInt() ?? 0, target: (json['target'] as num?)?.toInt() ?? 10, rewardedThisTime: (json['rewarded_this_time'] as bool?) ?? false, rewardPoints: (json['reward_points'] as num?)?.toInt() ?? 0, ); } /// 发表评论响应(《03-接口文档》6.4) class CommentCreateResult { CommentCreateResult({required this.commentId, required this.rewardProgress}); final int commentId; final RewardProgress rewardProgress; factory CommentCreateResult.fromJson(Map json) => CommentCreateResult( commentId: (json['comment_id'] as num?)?.toInt() ?? 0, rewardProgress: RewardProgress.fromJson( (json['reward_progress'] as Map?) ?? const {}, ), ); }