class MessageEntity {
  final String ownerId;
  final String content;
  final DateTime createdAt;

  const MessageEntity({
    required this.ownerId,
    required this.content,
    required this.createdAt,
  });

  static MessageEntity fromDocument(Map<String, dynamic> doc) {
    return MessageEntity(
      ownerId: (doc['sender_id'] ?? doc['owner_id']) as String,
      content: doc['content'] as String,
      createdAt: DateTime.parse(doc['created_at'] as String),
    );
  }

  Map<String, dynamic> toDocument() {
    return {
      'owner_id': ownerId,
      'content': content,
      'created_at': createdAt.toIso8601String(),
    };
  }

  @override
  String toString() {
    return '''MessageEntity{
      ownerId: $ownerId, 
      content: $content, 
      createdAt: $createdAt
      }''';
  }
}
