/// Created by Haoyi on 2022/2/26

part of "remote_config_manager.dart";

extension RemoteConfigInterface on RemoteConfigManager {
  bool isIOSReview() {
    if (Platform.isIOS) {
      return getBool(RemoteConfigReservedConstants.iosReviewVersion, defaultValue: true) ?? true;
    } else {
      return false;
    }
  }

  CdnConfig getCdnConfig() {
    final cdnConfigStr = getString(RemoteConfigReservedConstants.cdnConfig);
    if (cdnConfigStr != null && cdnConfigStr.isNotEmpty) {
      return CdnConfig.fromJson(
        jsonDecode(cdnConfigStr),
        defaultStoragePrefix: GuruApp.instance.details.storagePrefix,
        defaultCdnPrefix: GuruApp.instance.details.defaultCdnPrefix,
      );
    }
    return CdnConfig.fromJson(
      {},
      defaultStoragePrefix: GuruApp.instance.details.storagePrefix,
      defaultCdnPrefix: GuruApp.instance.details.defaultCdnPrefix,
    );
  }

  TaichiConfig? getTaichiConfig() {
    final taichiStr =
        RemoteConfigManager.instance.getString(RemoteConfigReservedConstants.taichiConfig);
    if (taichiStr != null && taichiStr.isNotEmpty) {
      return TaichiConfig.fromJson(jsonDecode(taichiStr));
    }
    return null;
  }

  AdInterstitialConfig getIadsConfig() {
    final iadsConfigStr =
        RemoteConfigManager.instance.getString(RemoteConfigReservedConstants.iadsConfig);
    if (iadsConfigStr != null && iadsConfigStr.isNotEmpty) {
      return AdInterstitialConfig.fromJson(jsonDecode(iadsConfigStr));
    }
    return AdInterstitialConfig.fromJson({});
  }

  AdRewardedConfig getRadsConfig() {
    final radsConfigStr =
        RemoteConfigManager.instance.getString(RemoteConfigReservedConstants.radsConfig);
    if (radsConfigStr != null && radsConfigStr.isNotEmpty) {
      return AdRewardedConfig.fromJson(jsonDecode(radsConfigStr));
    }
    return AdRewardedConfig.fromJson({});
  }

  AdBannerConfig getBadsConfig() {
    final badsConfigStr =
        RemoteConfigManager.instance.getString(RemoteConfigReservedConstants.badsConfig);
    if (badsConfigStr != null && badsConfigStr.isNotEmpty) {
      return AdBannerConfig.fromJson(jsonDecode(badsConfigStr));
    }
    return AdBannerConfig.fromJson({});
  }

  StrategyAdsConfig getStrategyAdsConfig() {
    final sadsConfigStr =
        RemoteConfigManager.instance.getString(RemoteConfigReservedConstants.sadsConfig);
    if (sadsConfigStr != null && sadsConfigStr.isNotEmpty) {
      return StrategyAdsConfig.fromJson(jsonDecode(sadsConfigStr));
    }
    return StrategyAdsConfig.fromJson({});
  }

  IOSAttConfig getIOSAttConfig() {
    final iosAttConfigString =
        RemoteConfigManager.instance.getString(RemoteConfigReservedConstants.iosAttConfig);

    if (iosAttConfigString != null && iosAttConfigString.isNotEmpty) {
      return IOSAttConfig.fromJson(jsonDecode(iosAttConfigString));
    }
    return IOSAttConfig.fromJson({});
  }

  CommonAdsConfig getCommonAdsConfig() {
    final commonAdsConfigString =
        RemoteConfigManager.instance.getString(RemoteConfigReservedConstants.commonAdsConfig);

    if (commonAdsConfigString != null && commonAdsConfigString.isNotEmpty) {
      return CommonAdsConfig.fromJson(jsonDecode(commonAdsConfigString));
    }
    return CommonAdsConfig.fromJson({});
  }

  AnalyticsConfig getAnalyticsConfig() {
    final analyticsConfigStr =
        RemoteConfigUtils.instance.getString(RemoteConfigReservedConstants.analyticsConfig);
    if (analyticsConfigStr != null && analyticsConfigStr.isNotEmpty) {
      return AnalyticsConfig.fromJson(jsonDecode(analyticsConfigStr));
    }
    return AnalyticsConfig.fromJson({});
  }

  RemoteDeployment getRemoteDeployment() {
    final deploymentConfigStr =
        RemoteConfigUtils.instance.getString(RemoteConfigReservedConstants.deploymentConfig);
    if (deploymentConfigStr != null && deploymentConfigStr.isNotEmpty) {
      return RemoteDeployment.fromJson(jsonDecode(deploymentConfigStr));
    }
    return RemoteDeployment.fromJson({});
  }
}
