/// 题目数据模型 class Problem { final String id; final double difficulty; final String questionType; final String importType; final List chapters; final List knowledgeCodes; final String comment; final String source; final String createdAt; final String updatedAt; final String? renderHtml; final String bodyPreview; Problem({ required this.id, this.difficulty = 0.5, this.questionType = '', this.importType = '精选题', this.chapters = const [], this.knowledgeCodes = const [], this.comment = '', this.source = '', this.createdAt = '', this.updatedAt = '', this.renderHtml, this.bodyPreview = '', }); factory Problem.fromJson(Map json) { return Problem( id: json['id'] ?? '', difficulty: (json['difficulty'] ?? 0.5).toDouble(), questionType: json['question_type'] ?? '', importType: json['import_type'] ?? '精选题', chapters: List.from(json['chapters'] ?? []), knowledgeCodes: List.from(json['knowledge_codes'] ?? []), comment: json['comment'] ?? '', source: json['source'] ?? '', createdAt: json['created_at'] ?? '', updatedAt: json['updated_at'] ?? '', renderHtml: json['render_html'], bodyPreview: json['body_preview'] ?? '', ); } String get difficultyLabel { if (difficulty >= 0.7) return '易'; if (difficulty >= 0.4) return '中'; return '难'; } bool get isAnnotated => knowledgeCodes.isNotEmpty && knowledgeCodes.first.isNotEmpty; } /// 搜索命中结果 class SearchResult { final String id; final String bodySnippet; final double difficulty; final String questionType; final String importType; final List chapters; SearchResult({ required this.id, this.bodySnippet = '', this.difficulty = 0.5, this.questionType = '', this.importType = '', this.chapters = const [], }); factory SearchResult.fromJson(Map json) { return SearchResult( id: json['id'] ?? '', bodySnippet: json['body_snippet'] ?? '', difficulty: (json['difficulty'] ?? 0.5).toDouble(), questionType: json['question_type'] ?? '', importType: json['import_type'] ?? '', chapters: List.from(json['chapters'] ?? []), ); } }