class MessageModel { final String id; final String body; final bool fromMe; final int timestamp; final String type; // "chat"|"image"|"video"|"audio"|"document"|"sticker" final bool hasMedia; final bool isForwarded; final String? author; final int ack; // 0=error/none 1=pending 2=sent 3=delivered 4=read MessageModel({ required this.id, required this.body, required this.fromMe, required this.timestamp, required this.type, required this.hasMedia, required this.isForwarded, this.author, required this.ack, }); factory MessageModel.fromJson(Map json) { return MessageModel( id: json['id'] ?? '', body: json['body'] ?? '', fromMe: json['fromMe'] ?? false, timestamp: json['timestamp'] ?? 0, type: json['type'] ?? 'chat', hasMedia: json['hasMedia'] ?? false, isForwarded: json['isForwarded'] ?? false, author: json['author'], ack: json['ack'] ?? 0, ); } Map toJson() { return { 'id': id, 'body': body, 'fromMe': fromMe, 'timestamp': timestamp, 'type': type, 'hasMedia': hasMedia, 'isForwarded': isForwarded, 'author': author, 'ack': ack, }; } MessageModel copyWith({ String? id, String? body, bool? fromMe, int? timestamp, String? type, bool? hasMedia, bool? isForwarded, String? author, int? ack, }) { return MessageModel( id: id ?? this.id, body: body ?? this.body, fromMe: fromMe ?? this.fromMe, timestamp: timestamp ?? this.timestamp, type: type ?? this.type, hasMedia: hasMedia ?? this.hasMedia, isForwarded: isForwarded ?? this.isForwarded, author: author ?? this.author, ack: ack ?? this.ack, ); } }