import 'package:guru_utils/property/property_model.dart';
import 'package:guru_utils/settings/settings.dart';
import 'package:guru_utils/property/runtime_property.dart';
import 'package:guru_utils/property/app_property.dart';
import 'package:guru_app/ads/ads_manager.dart';
import 'package:guru_app/property/settings/guru_settings.dart';

import '../core/property_keys.dart';

class DebugModeSettings extends Settings {
  static DebugModeSettings instance = DebugModeSettings._();

  final SettingData<bool> fakeInterstitialAds = SettingBoolData(UtilsPropertyKeys.fakeInterstitialAds, defaultValue: RuntimeProperty.instance.getBool(UtilsPropertyKeys.fakeInterstitialAds, defValue: false));

  final SettingData<bool> fakeRewardedAds = SettingBoolData(UtilsPropertyKeys.fakeRewardedAds, defaultValue: RuntimeProperty.instance.getBool(UtilsPropertyKeys.fakeRewardedAds, defValue: false));

  final SettingData<bool> forcePubmatic = SettingBoolData(UtilsPropertyKeys.forcePubmatic, defaultValue: false);

  final SettingData<bool> forceGdpr = SettingBoolData(UtilsPropertyKeys.forceGdpr, defaultValue: false);

  final SettingData<bool> globalFloatingWindow = SettingBoolData(DataViewerPropertyKeys.globalFloatingWindow, defaultValue: false);

  DebugModeSettings._();
}

class KeywordsTestSetting {
  static KeywordsTestSetting instance = KeywordsTestSetting._();

  KeywordsTestSetting._();

  static const tag = "keywords";

  static const appVersionEnabledKey = PropertyKey.setting("app_version_enabled", tag: tag);
  static const ltEnabledKey = PropertyKey.setting("lt_enabled", tag: tag);
  static const paidEnabledKey = PropertyKey.setting("paid_enabled", tag: tag);
  static const appVersionKey = PropertyKey.setting("app_version", tag: tag);
  static const paidKey = PropertyKey.setting("paid", tag: tag);
  static const ltValueKey = PropertyKey.setting("lt_value", tag: tag);

  final RuntimeSettingBoolData appVersionEnabled =
      RuntimeSettingBoolData(appVersionEnabledKey, defaultValue: false);
  final RuntimeSettingBoolData ltEnabled =
      RuntimeSettingBoolData(ltEnabledKey, defaultValue: false);
  final RuntimeSettingBoolData paidEnabled =
      RuntimeSettingBoolData(paidEnabledKey, defaultValue: false);

  final RuntimeSettingStringData appVersion =
      RuntimeSettingStringData(appVersionKey, defaultValue: '3.8.0');
  final RuntimeSettingBoolData paidValue = RuntimeSettingBoolData(paidKey, defaultValue: false);

  final RuntimeSettingIntData ltValue = RuntimeSettingIntData(ltValueKey, defaultValue: 0);

  Future<Map<String, String>> init() async {
    final keywords = AdsManager.instance.adsKeywords;

    final _appVersion = keywords["app_version"];
    if (_appVersion != null) {
      appVersionEnabled.set(true);
      appVersion.set(_appVersion);
    } else {
      appVersion.set(GuruSettings.instance.version.get());
    }

    final _paid = keywords["paid"];
    if (_paid != null) {
      paidEnabled.set(true);
      paidValue.set(_paid == "true");
    } else {
      paidValue.set(false);
    }

    final _lt = keywords["lt"];
    if (_lt != null) {
      ltEnabled.set(true);
      ltValue.set(int.parse(_lt));
    } else {
      ltValue.set(AdsManager.ltSamples[0]);
    }
    return keywords;
  }
}