import 'feedback.dart';
import 'reply.dart';
import 'user.dart';

class CommentData {
  int id;
  final String text;
  final String createdAt;
  bool liked;
  bool disliked;
  int status;
  final FeedbackData feedback;
  final UserOverview user;
  final List<Reply> replies;

  CommentData({
    required this.id,
    required this.text,
    required this.createdAt,
    required this.liked,
    required this.disliked,
    required this.feedback,
    required this.user,
    required this.replies,
    required this.status,
  });

  factory CommentData.fromJson(Map<String, dynamic> json) => CommentData(
        id: json['id'],
        text: json['text'],
        createdAt: json['createdAt'],
        liked: json['liked'],
        disliked: json['disliked'],
        feedback: FeedbackData.fromJson(json['feedback']),
        user: UserOverview.fromJson(json['user']),
        replies: List<Reply>.from(
          json['replies'].map(
            (reply) => Reply.fromJson(reply),
          ),
        ),
        status: json['status'],
      );

  Map<String, dynamic> toJson() => {
        'id': id,
        'text': text,
        'createdAt': createdAt,
        'liked': liked,
        'disliked': disliked,
        'feedback': feedback.toJson(),
        'user': user.toJson(),
        'replies': replies.map((e) => e.toJson()).toList(),
      };
}
