validate method

ConfigValidation validate()

Validate the merged configuration using built-in rules.

Implementation

ConfigValidation validate() {
  final errors = <String>[];
  final all = getAll();

  // Required non-empty string checks.
  if (all[ConfigKeys.apiKey] == null ||
      (all[ConfigKeys.apiKey] as String).isEmpty) {
    errors.add('${ConfigKeys.apiKey}: API key is required');
  }

  // Numeric range checks.
  final maxTokens = all[ConfigKeys.maxTokens];
  if (maxTokens is int && (maxTokens < 1 || maxTokens > 200000)) {
    errors.add('${ConfigKeys.maxTokens}: must be between 1 and 200000');
  }

  final temp = all[ConfigKeys.temperature];
  if (temp is num && (temp < 0.0 || temp > 2.0)) {
    errors.add('${ConfigKeys.temperature}: must be between 0.0 and 2.0');
  }

  // Permission mode must be one of known values.
  final pm = all[ConfigKeys.permissionMode];
  if (pm is String && !{'prompt', 'auto', 'deny'}.contains(pm)) {
    errors.add('${ConfigKeys.permissionMode}: must be prompt, auto, or deny');
  }

  // Log level.
  final ll = all[ConfigKeys.logLevel];
  if (ll is String &&
      !{'debug', 'info', 'warn', 'error', 'silent'}.contains(ll)) {
    errors.add(
      '${ConfigKeys.logLevel}: must be debug, info, warn, error, or silent',
    );
  }

  return ConfigValidation(isValid: errors.isEmpty, errors: errors);
}