validateAyahStructure static method

void validateAyahStructure(
  1. Map<String, dynamic> ayah,
  2. int expectedId
)

Validate individual ayah structure

Implementation

static void validateAyahStructure(Map<String, dynamic> ayah, int expectedId) {
  final requiredFields = ['id', 'text', 'juz', 'hizb'];

  for (final field in requiredFields) {
    if (!ayah.containsKey(field)) {
      throw ArgumentError('Ayah missing required field: $field');
    }
  }

  final id = ayah['id'];
  if (id != expectedId) {
    throw ArgumentError('Expected ayah ID $expectedId, got: $id');
  }

  final text = ayah['text'];
  if (text is! String || text.isEmpty) {
    throw ArgumentError('Ayah text must be a non-empty string');
  }

  validateJuzNumber(ayah['juz']);
  validateHizbNumber(ayah['hizb']);

  // sajdah field is optional but if present must be boolean
  if (ayah.containsKey('sajdah') && ayah['sajdah'] is! bool) {
    throw ArgumentError('sajdah field must be boolean');
  }
}