104 lines
2.7 KiB
Dart
104 lines
2.7 KiB
Dart
class FaqCategoryDocument {
|
|
const FaqCategoryDocument({
|
|
required this.originalName,
|
|
required this.url,
|
|
});
|
|
|
|
final String originalName;
|
|
final String url;
|
|
|
|
factory FaqCategoryDocument.fromJson(Map<String, dynamic>? json) {
|
|
if (json == null) {
|
|
return const FaqCategoryDocument(originalName: '', url: '');
|
|
}
|
|
return FaqCategoryDocument(
|
|
originalName: (json['originalName'] ?? '').toString(),
|
|
url: (json['url'] ?? '').toString(),
|
|
);
|
|
}
|
|
|
|
bool get isPresent => url.isNotEmpty;
|
|
}
|
|
|
|
class FaqCategoryModel {
|
|
const FaqCategoryModel({
|
|
required this.id,
|
|
required this.slug,
|
|
required this.name,
|
|
this.description,
|
|
this.pdfFr,
|
|
this.pdfEn,
|
|
});
|
|
|
|
final int id;
|
|
final String slug;
|
|
final String name;
|
|
final String? description;
|
|
final FaqCategoryDocument? pdfFr;
|
|
final FaqCategoryDocument? pdfEn;
|
|
|
|
bool get hasDownloads =>
|
|
(pdfFr?.isPresent ?? false) || (pdfEn?.isPresent ?? false);
|
|
|
|
factory FaqCategoryModel.fromJson(Map<String, dynamic> json) {
|
|
FaqCategoryDocument? parseDoc(dynamic raw) {
|
|
if (raw is! Map<String, dynamic>) return null;
|
|
final doc = FaqCategoryDocument.fromJson(raw);
|
|
return doc.isPresent ? doc : null;
|
|
}
|
|
|
|
return FaqCategoryModel(
|
|
id: _asInt(json['id']),
|
|
slug: (json['slug'] ?? '').toString(),
|
|
name: (json['name'] ?? '').toString(),
|
|
description: json['description']?.toString(),
|
|
pdfFr: parseDoc(json['pdfFr']),
|
|
pdfEn: parseDoc(json['pdfEn']),
|
|
);
|
|
}
|
|
}
|
|
|
|
class FaqEntryModel {
|
|
const FaqEntryModel({
|
|
required this.id,
|
|
required this.question,
|
|
required this.answer,
|
|
required this.category,
|
|
this.categorySlug = '',
|
|
this.viewCount = 0,
|
|
});
|
|
|
|
final String id;
|
|
final String question;
|
|
final String answer;
|
|
final String category;
|
|
final String categorySlug;
|
|
final int viewCount;
|
|
|
|
factory FaqEntryModel.fromJson(Map<String, dynamic> json) {
|
|
final rawAnswer = (json['answerHtml'] ?? json['answer'] ?? '').toString();
|
|
return FaqEntryModel(
|
|
id: (json['id'] ?? '').toString(),
|
|
question: (json['question'] ?? '').toString(),
|
|
answer: rawAnswer
|
|
.replaceAll(RegExp(r'<[^>]*>'), ' ')
|
|
.replaceAll(RegExp(r'\s+'), ' ')
|
|
.trim(),
|
|
category: (json['categoryName'] ??
|
|
json['category'] ??
|
|
json['categorySlug'] ??
|
|
'')
|
|
.toString(),
|
|
categorySlug: (json['categorySlug'] ?? '').toString(),
|
|
viewCount: _asInt(json['viewCount']),
|
|
);
|
|
}
|
|
}
|
|
|
|
int _asInt(dynamic value) {
|
|
if (value == null) return 0;
|
|
if (value is int) return value;
|
|
if (value is num) return value.toInt();
|
|
return int.tryParse(value.toString()) ?? 0;
|
|
}
|