import 'package:aitrainer_app/model/cache.dart';
import 'package:aitrainer_app/service/logging.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';

class RemoteConfigRepository with Logging {
  RemoteConfig? remoteConfig;

  String getConfigValue(String configKey, String baseValue) {
    String value = "";
    remoteConfig = Cache().remoteConfig;
    if (remoteConfig != null) {
      remoteConfig!.fetchAndActivate();
      Map config = remoteConfig!.getAll();
      RemoteConfigValue? configValue = config[configKey];
      if (configValue != null && configValue.asString().isNotEmpty) {
        log("RemoteConfig $configKey value: ${configValue.asString()}");
        if (configValue.asString() == baseValue) {
          value = configValue.asString();
        }
      }
    }
    return value;
  }
}
