import 'package:guru_app/guru_app.dart';
import 'package:guru_app/property/app_property.dart';
import 'package:guru_utils/auth/auth_credential_manager.dart';
import 'package:guru_utils/id/id_utils.dart';
import 'package:guru_utils/property/property_model.dart';
import 'package:guru_utils/settings/settings.dart';

/// Created by Haoyi on 2022/8/25

class PropertyKeys {
  static const PropertyKey version = UtilsSettingsKeys.version;
  static const PropertyKey buildNumber = UtilsSettingsKeys.buildNumber;
  static const PropertyKey firstInstallTime = UtilsSettingsKeys.firstInstallTime;
  static const PropertyKey firstInstallVersion = UtilsSettingsKeys.firstInstallVersion;
  static const PropertyKey prevInstallVersion = UtilsSettingsKeys.prevInstallVersion;
  static const PropertyKey latestInstallVersion = UtilsSettingsKeys.latestInstallVersion;
  static const PropertyKey previousInstalledVersion = UtilsSettingsKeys.previousInstalledVersion;
  static const PropertyKey appInstanceId = UtilsSettingsKeys.appInstanceId;
  static const PropertyKey soundEffect = UtilsSettingsKeys.soundEffect;
  static const PropertyKey vibration = UtilsSettingsKeys.vibration;
  static const PropertyKey deviceId = UtilsSettingsKeys.deviceId;
  static const PropertyKey debugMode = UtilsSettingsKeys.debugMode;
  static const PropertyKey latestLtDate = UtilsSettingsKeys.latestLtDate;
  static const PropertyKey ltDays = UtilsSettingsKeys.ltDays;
  static const PropertyKey keepOnScreenDuration = UtilsSettingsKeys.keepOnScreenDuration;

  static const PropertyKey accountGuruUser =
      PropertyKey.general("account_saas_user", tag: PropertyTags.account);
  @Deprecated("use accountGuruUser instead")
  static const PropertyKey accountSaasUser = accountGuruUser;
  static const PropertyKey accountDevice =
      PropertyKey.general("account_device", tag: PropertyTags.account);
  static const PropertyKey accountProfile =
      PropertyKey.general("account_profile", tag: PropertyTags.account);
  static const PropertyKey latestReportDeviceTimestamp =
      PropertyKey.general("latest_report_device_timestamp", tag: PropertyTags.account);
  static const PropertyKey anonymousSecretKey =
      PropertyKey.general("anonymous_secret_key", tag: PropertyTags.account);

  static const PropertyKey historicalSocialAuths =
      PropertyKey.general("historical_social_auths", tag: PropertyTags.account);

  static const PropertyKey isNoAds = PropertyKey.setting("no_ads", tag: PropertyTags.ads);

  static const PropertyKey totalRevenue =
      PropertyKey.general("total_revenue", tag: PropertyTags.financial);

  /// 020的 revenue
  static const PropertyKey totalRevenue020 =
      PropertyKey.general("total_revenue_020", tag: PropertyTags.financial);

  static const PropertyKey userRewardedCount =
      PropertyKey.general("user_rewarded_count", tag: PropertyTags.ads);

  static const PropertyKey fakeInterstitialAds = UtilsPropertyKeys.fakeInterstitialAds;

  static const PropertyKey fakeRewardedAds = UtilsPropertyKeys.fakeRewardedAds;

  static const PropertyKey iapCount = PropertyKey.general("iap_count", tag: PropertyTags.iap);
  static const PropertyKey iapIgc = PropertyKey.general("iap_igc", tag: PropertyTags.iap);
  static const PropertyKey noIapIgc = PropertyKey.general("no_iap_igc", tag: PropertyTags.iap);

  static const PropertyKey subscriptionGraceCount =
      PropertyKey.general("subscription_grace_count", tag: PropertyTags.iap);
  static const PropertyKey admobConsentTestDeviceId =
      PropertyKey.general("admob_consent_test_device_id", tag: PropertyTags.ads);
  static const PropertyKey admobConsentDebugGeography =
      PropertyKey.general("admob_consent_debug_geography", tag: PropertyTags.ads);

  static const PropertyKey latestAnalyticsStrategy =
      PropertyKey.general("latest_analytics_strategy", tag: PropertyTags.analytics);

  static const PropertyKey subscriptionCount =
      PropertyKey.general("subs_count", tag: PropertyTags.iap);

  static PropertyKey buildGroupSubscriptionCount(String group) {
    return PropertyKey.general("subs_${group}_count", tag: PropertyTags.iap);
  }

  static PropertyKey buildSubscriptionCount(ProductId productId) {
    String key = "subs_${productId.iapEventName}_";
    if (productId.basePlan != null) {
      key += "${productId.basePlan}_";
    }

    if (productId.offerId != null) {
      key += "${productId.offerId}_";
    }
    return PropertyKey.general("${key}count", tag: PropertyTags.iap);
  }

  static PropertyKey buildReportFailedIapOrdersKey({String? overrideKey}) {
    return PropertyKey.general(overrideKey ?? "RFIO_${IdUtils.uuidV4()}",
        tag: PropertyTags.failedOrders);
  }

  static const PropertyKey bestLevel =
      PropertyKey.setting("best_level", tag: PropertyTags.analytics);

  static const PropertyKey analyticsAdId =
      PropertyKey.general("analytics_ad_id", tag: PropertyTags.analytics);
  static const PropertyKey analyticsFirebaseId =
      PropertyKey.general("analytics_firebase_id", tag: PropertyTags.analytics);
  static const PropertyKey analyticsAdjustId =
      PropertyKey.general("analytics_adjust_id", tag: PropertyTags.analytics);
  static const PropertyKey analyticsUserId =
      PropertyKey.general("analytics_user_id", tag: PropertyTags.analytics);
  static const PropertyKey analyticsDeviceId =
      PropertyKey.general("analytics_device_id", tag: PropertyTags.analytics);
  static const PropertyKey analyticsIdfa =
      PropertyKey.general("analytics_idfa", tag: PropertyTags.analytics);

  static const PropertyKey googleDma =
      PropertyKey.general("google_dma_result", tag: PropertyTags.analytics);

  static const PropertyKey currentIgcBalance =
      PropertyKey.general("current_balance", tag: PropertyTags.igc);
  static const PropertyKey currentIgcBalanceValidation =
      PropertyKey.general("16%98d1x9sr0a@d20xrng", tag: PropertyTags.igc);

  static PropertyKey buildABTestProperty(String key) {
    return PropertyKey.general("abtest_$key", tag: PropertyTags.guruAB);
  }

  static PropertyKey buildExperimentProperty(String key) {
    return PropertyKey.general("exp_$key", tag: PropertyTags.guruExperiment);
  }

  static PropertyKey requestNotificationPermissionTimes =
      const PropertyKey.general("request_notification_permission_times");

  static PropertyKey showNotificationPermissionTimes =
      const PropertyKey.general("show_notification_permission_times");

  static PropertyKey deniedNotificationPermissionTimes =
      const PropertyKey.general("denied_notification_permission_times");

  static PropertyKey buildAuthCredentialKey(AuthType authType) {
    return PropertyKey.general("${getAuthName(authType)}_auth_credential",
        tag: PropertyTags.account);
  }
}
