class ForumModel {
  List<Comment>? comments;
  List<Comment>? replies;
  int? page;
  int? totalCount;
  int? lastPage;

  ForumModel({this.comments, this.page, this.totalCount, this.lastPage});

  ForumModel.fromJson(Map<String, dynamic> json) {
    if (json['comments'] != null) {
      comments = <Comment>[];
      json['comments'].forEach((v) {
        comments!.add(Comment.fromJson(v));
      });
    }
    if (json['replies'] != null) {
      replies = <Comment>[];
      json['replies'].forEach((v) {
        replies!.add(Comment.fromJson(v));
      });
    }
    page = json['page'];
    totalCount = json['total_count'];
    lastPage = json['last_page'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    if (comments != null) {
      data['comments'] = comments!.map((v) => v.toJson()).toList();
    }
    if (replies != null) {
      data['replies'] = replies!.map((v) => v.toJson()).toList();
    }
    data['page'] = page;
    data['total_count'] = totalCount;
    data['last_page'] = lastPage;
    return data;
  }
}

class Comment {
  int? id;
  String? text;
  String? image;
  String? createdAt;
  int? replies;
  int? likes;
  int? dislikes;
  int? userFeedback;
  User? user;

  Comment(
      {this.id,
      this.text,
      this.image,
      this.createdAt,
      this.replies = 0,
      this.likes = 0,
      this.dislikes = 0,
      this.userFeedback,
      this.user});

  Comment.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    text = json['text'];
    image = json['image'];
    createdAt = json['created_at'];
    replies = json['replies'] ?? 0;
    likes = json['likes'] ?? 0;
    dislikes = json['dislikes'] ?? 0;
    userFeedback = json['user_feedback'];
    user = json['user'] != null ? User.fromJson(json['user']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['text'] = text;
    data['image'] = image;
    data['created_at'] = createdAt;
    data['replies'] = replies;
    data['likes'] = likes;
    data['dislikes'] = dislikes;
    data['user_feedback'] = userFeedback;
    if (user != null) {
      data['user'] = user!.toJson();
    }
    return data;
  }

  Comment copyWith(
      {int? id,
      String? text,
      String? image,
      String? createdAt,
      int? replies,
      int? likes,
      int? dislikes,
      int? userFeedback,
      User? user}) {
    return Comment(
      id: id ?? this.id,
      text: text ?? this.text,
      image: image ?? this.image,
      replies: replies ?? this.replies,
      likes: likes ?? this.likes,
      dislikes: dislikes ?? this.dislikes,
      userFeedback: userFeedback ?? this.userFeedback,
      createdAt: createdAt ?? this.createdAt,
      user: user ?? this.user,
    );
  }
}

class User {
  String? id;
  String? name;
  String? image;
  String? username;

  User({this.id, this.name, this.image, this.username});

  User.fromJson(Map<String, dynamic> json) {
    id = json['id'];
    name = json['name'];
    image = json['image'];
    username = json['username'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = <String, dynamic>{};
    data['id'] = id;
    data['name'] = name;
    data['image'] = image;
    data['username'] = username;
    return data;
  }
}
