parseQuotaSection function

QuotaSection parseQuotaSection(
  1. Object? node
)

Parses the quota: yaml section (issue #823). A null node means the section is absent — the caller applies the defaults. Any present-but- invalid shape, value or key throws ConfigException, consistent with the other strict config sections.

Implementation

QuotaSection parseQuotaSection(Object? node) {
  if (node == null) return const QuotaSection();
  if (node is! YamlMap) {
    throw ConfigException('quota must be a map, got: $node');
  }
  var badge = defaultQuotaBadge;
  var ttlMinutes = defaultQuotaTtlMinutes;
  for (final key in node.keys) {
    switch (key) {
      case 'badge':
        final value = node[key];
        if (value is! bool) {
          throw ConfigException('"quota.badge" must be a boolean');
        }
        badge = value;
      case 'ttl_minutes':
        final value = node[key];
        if (value is! int || value <= 0) {
          throw ConfigException(
            '"quota.ttl_minutes" must be a positive integer (minutes)',
          );
        }
        ttlMinutes = value;
      default:
        throw ConfigException('unknown "quota" key: $key');
    }
  }
  return QuotaSection(badge: badge, ttlMinutes: ttlMinutes);
}