import 'package:prosapp_web_app/models/message_entity.dart';

class ChatEntity {
  final String? id;
  final String userId;
  final String professionalId;
  final List<MessageEntity> messages;

  const ChatEntity({
    required this.id,
    required this.userId,
    required this.professionalId,
    required this.messages,
  });

  static ChatEntity fromDocument(Map<String, dynamic> doc) {
    return ChatEntity(
      id: doc['id'] as String,
      userId: doc['user_id'] as String,
      professionalId: doc['professional_id'] as String,
      messages: (doc['messages'] as List)
          .map((e) => MessageEntity.fromDocument(e as Map<String, dynamic>))
          .toList(),
    );
  }

  Map<String, dynamic> toDocument() {
    return {
      'id': id,
      'user_id': userId,
      'professional_id': professionalId,
      'messages': messages.map((e) => e.toDocument()).toList(),
    };
  }

  @override
  String toString() {
    return '''ChatEntity{
      id: $id, 
      userId: $userId, 
      professionalId: $professionalId, 
      messages: $messages
      }''';
  }
}
