import 'package:cloud_firestore/cloud_firestore.dart';

/// Firestore document mapping for a single LLM chat message.
/// Stored at: users/{userId}/llm_messages/{messageId}
class LlmChatMessageEntity {
  final String? id;
  final String role; // 'user' or 'assistant'
  final String content;
  final DateTime createdAt;

  const LlmChatMessageEntity({
    this.id,
    required this.role,
    required this.content,
    required this.createdAt,
  });

  factory LlmChatMessageEntity.fromFirestore(
    String id,
    Map<String, dynamic> data,
  ) {
    return LlmChatMessageEntity(
      id: id,
      role: data['role'] as String,
      content: data['content'] as String,
      createdAt: (data['createdAt'] as Timestamp).toDate(),
    );
  }

  Map<String, dynamic> toFirestore() => {
        'role': role,
        'content': content,
        'createdAt': Timestamp.fromDate(createdAt),
      };
}
