class ExternalSymbolSource { final String author; final String work; final String excerpt; final String fullText; const ExternalSymbolSource({ required this.author, required this.work, this.excerpt = '', this.fullText = '', }); factory ExternalSymbolSource.fromMap(Map map) { return ExternalSymbolSource( author: map['author'] as String? ?? '', work: map['work'] as String? ?? '', excerpt: map['excerpt'] as String? ?? '', fullText: map['full_text'] as String? ?? '', ); } Map toMap() => { 'author': author, 'work': work, 'excerpt': excerpt, 'full_text': fullText, }; } class ExternalSymbol { final String term; final String normalized; final String categoryGuess; final List sources; final List> illustrations; const ExternalSymbol({ required this.term, required this.normalized, this.categoryGuess = 'Внешний академический символ', this.sources = const [], this.illustrations = const [], }); bool get hasIllustrations => illustrations.isNotEmpty; String get primaryAuthor => sources.isNotEmpty ? sources.first.author : ''; String get primaryWork => sources.isNotEmpty ? sources.first.work : ''; String get primaryExcerpt => sources.isNotEmpty ? sources.first.excerpt : ''; factory ExternalSymbol.fromMap(Map map) { final rawSources = map['sources'] as List? ?? []; final rawIlls = map['illustrations'] as List? ?? []; return ExternalSymbol( term: map['term'] as String? ?? '', normalized: map['normalized'] as String? ?? '', categoryGuess: map['category_guess'] as String? ?? 'Внешний символ', sources: rawSources .map((s) => ExternalSymbolSource.fromMap(Map.from(s as Map))) .toList(), illustrations: rawIlls .map((i) => Map.from(i as Map)) .toList(), ); } Map toMap() => { 'term': term, 'normalized': normalized, 'category_guess': categoryGuess, 'sources': sources.map((s) => s.toMap()).toList(), 'illustrations': illustrations, }; }