validateQuranDataStructure static method
Validate JSON structure for Quran data
Implementation
static void validateQuranDataStructure(Map<String, dynamic> data) {
// Check required top-level fields
final requiredFields = ['version', 'source', 'surahs'];
for (final field in requiredFields) {
if (!data.containsKey(field)) {
throw ArgumentError('Missing required field: $field');
}
}
// Check surahs array
final surahs = data['surahs'];
if (surahs is! List) {
throw ArgumentError('surahs must be a list');
}
if (surahs.length != 114) {
throw ArgumentError(
'surahs must contain exactly 114 entries, got: ${surahs.length}');
}
// Validate each surah structure
for (int i = 0; i < surahs.length; i++) {
final surah = surahs[i];
if (surah is! Map<String, dynamic>) {
throw ArgumentError('Surah at index $i must be a map');
}
validateSurahStructure(surah, i + 1);
}
}