import 'package:cloud_firestore/cloud_firestore.dart'; class MindMapModel { final String id; final String title; final String description; final String ownerEmail; final bool isMain; // Основные карты (админские) vs Личные final List> nodes; final Map settings; final DateTime createdAt; final DateTime updatedAt; MindMapModel({ required this.id, required this.title, this.description = '', required this.ownerEmail, this.isMain = false, this.nodes = const [], this.settings = const {}, required this.createdAt, required this.updatedAt, }); factory MindMapModel.fromFirestore(DocumentSnapshot doc) { final data = doc.data() as Map; return MindMapModel.fromMap(doc.id, data); } factory MindMapModel.fromMap(String id, Map data) { return MindMapModel( id: id, title: data['title'] ?? '', description: data['description'] ?? '', ownerEmail: data['ownerEmail'] ?? '', isMain: data['isMain'] ?? false, nodes: List>.from(data['nodes'] ?? []), settings: data['settings'] ?? {}, createdAt: (data['createdAt'] as Timestamp).toDate(), updatedAt: (data['updatedAt'] as Timestamp).toDate(), ); } Map toFirestore() { return { 'title': title, 'description': description, 'ownerEmail': ownerEmail, 'isMain': isMain, 'nodes': nodes, 'settings': settings, 'createdAt': Timestamp.fromDate(createdAt), 'updatedAt': Timestamp.fromDate(updatedAt), }; } MindMapModel copyWith({ String? id, String? title, String? description, String? ownerEmail, bool? isMain, List>? nodes, Map? settings, DateTime? createdAt, DateTime? updatedAt, }) { return MindMapModel( id: id ?? this.id, title: title ?? this.title, description: description ?? this.description, ownerEmail: ownerEmail ?? this.ownerEmail, isMain: isMain ?? this.isMain, nodes: nodes ?? this.nodes, settings: settings ?? this.settings, createdAt: createdAt ?? this.createdAt, updatedAt: updatedAt ?? this.updatedAt, ); } int get nodeCount => nodes.length; int get maxLevel { if (nodes.isEmpty) return 0; return nodes.fold( 0, (max, node) => max > (node['level'] ?? 0) ? max : (node['level'] ?? 0)); } }