import 'package:uuid/uuid.dart'; class Message { final String id; final String role; // 'user' or 'assistant' final String content; final DateTime timestamp; final bool isStreaming; final List? attachments; Message({ String? id, required this.role, required this.content, DateTime? timestamp, this.isStreaming = false, this.attachments, }) : id = id ?? const Uuid().v4(), timestamp = timestamp ?? DateTime.now(); Message copyWith({ String? id, String? role, String? content, DateTime? timestamp, bool? isStreaming, List? attachments, }) { return Message( id: id ?? this.id, role: role ?? this.role, content: content ?? this.content, timestamp: timestamp ?? this.timestamp, isStreaming: isStreaming ?? this.isStreaming, attachments: attachments ?? this.attachments, ); } factory Message.fromJson(Map json) { return Message( id: json['id'], role: json['role'], content: json['content'], timestamp: json['timestamp'] != null ? DateTime.parse(json['timestamp']) : DateTime.now(), attachments: json['attachments'] != null ? List.from(json['attachments']) : null, ); } Map toJson() { return { 'id': id, 'role': role, 'content': content, 'timestamp': timestamp.toIso8601String(), 'attachments': attachments, }; } bool get isUser => role == 'user'; bool get isAssistant => role == 'assistant'; }