# =================================================================================================
# WiseTrack core — consumer rules
#
# Shipped inside the AAR and applied by R8 in every app that uses the SDK. They are also included
# in the SDK's own release build (see proguard-rules.pro), so everything listed here is guaranteed
# to survive both passes.
#
# Keep this file minimal: every rule here also constrains the host app. Libraries the SDK depends
# on (OkHttp/Okio, WorkManager, Lifecycle, coroutines, AndroidX) ship their own rules.
# =================================================================================================

# ---- Attributes needed at runtime ---------------------------------------------------------------
# Signature: Gson reads generic types (RequestRecord.parameters, TypeToken<List<RequestRecord>>).
# Runtime annotations: @SerializedName, and @WTNoTrack / @WTScreenName placed on the app's own
# Activities and Fragments.
-keepattributes Signature,InnerClasses,EnclosingMethod,Exceptions
-keepattributes RuntimeVisibleAnnotations,RuntimeVisibleParameterAnnotations,AnnotationDefault

# ---- Public API ---------------------------------------------------------------------------------
# Used by apps and by the Flutter / Unity / React Native plugins and the web bridge. Unity calls
# these through JNI by name, so they must not be renamed or removed even when the app's own code
# never references them.
# Only the static (@JvmStatic) API and INSTANCE; `internal` test hooks stay obfuscated.
-keep class io.wisetrack.sdk.core.WiseTrack { public static *; }
-keep interface io.wisetrack.sdk.core.resources.WTLoggerOutput { *; }
-keep class io.wisetrack.sdk.core.utils.utils.WTParametersValidationException { public *; }
-keep class io.wisetrack.sdk.core.utils.wrapper.ResourceWrapper { public *; }

# Models: public API and also persisted with Gson (WTInitialConfig, WTScreen, enums by name).
-keep class io.wisetrack.sdk.core.models.** { *; }

# Screen tracking API.
-keep class io.wisetrack.sdk.core.screen.WTNavigationTracker { public *; }
-keep class io.wisetrack.sdk.core.screen.WTViewPagerTracker { public *; }
-keep class io.wisetrack.sdk.core.screen.WTTrackedWebViewClient { public *; }
-keep class io.wisetrack.sdk.core.screen.WTTrackedWebViewClientKt { public *; }
-keep interface io.wisetrack.sdk.core.screen.WTScreenDataProvider { *; }
-keep class io.wisetrack.sdk.core.screen.WTScreenAutoTrackingConfig { *; }
-keep @interface io.wisetrack.sdk.core.screen.WTNoTrack
-keep @interface io.wisetrack.sdk.core.screen.WTScreenName { *; }

# ---- Data read/written by name at runtime -------------------------------------------------------
# Gson data classes (server DTOs, WTApiResponse, RequestRecord, WTAdIdInfo, WTReferrerInfo, …):
# every field carries @SerializedName, so JSON keys (and the data stored by previous SDK versions)
# never depend on field names. They are matched by annotation, not by class name, because the SDK's
# own R8 pass renames and repackages them before the app sees them. Keeping the class and its
# constructors tells R8 that Gson instantiates it; otherwise R8 full mode may assume it is never
# created and strip its field reads.
-keepclasseswithmembers,allowobfuscation class io.wisetrack.sdk.core.** {
    @com.google.gson.annotations.SerializedName <fields>;
    <init>(...);
}

# Enum constants are stored by name (e.g. RequestRecord.endpoint, RequestState).
-keepclassmembers enum io.wisetrack.sdk.core.** {
    <fields>;
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Gson: generic type tokens and annotated fields.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
-keepclassmembers,allowobfuscation class * {
    @com.google.gson.annotations.SerializedName <fields>;
}

# WorkManager stores the worker class name in its database for already-scheduled work: it must
# stay identical across SDK versions and app builds.
-keep class io.wisetrack.sdk.core.services.WTHeartbeatWorker {
    public <init>(android.content.Context, androidx.work.WorkerParameters);
}

# ---- Optional dependencies ----------------------------------------------------------------------
# The SDK checks these with Class.forName("<name>") before using them, so their names must survive
# the app's R8 pass when the app includes them.
-keepnames class com.google.android.gms.common.GoogleApiAvailability
-keepnames class com.google.android.gms.common.GooglePlayServicesNotAvailableException
-keepnames class com.google.android.gms.common.GooglePlayServicesRepairableException
-keepnames class com.google.android.gms.ads.identifier.AdvertisingIdClient
-keepnames class com.google.android.gms.appset.AppSet
-keepnames class com.google.firebase.installations.FirebaseInstallations
-keepnames class androidx.fragment.app.FragmentActivity
-keepnames class com.google.android.material.bottomsheet.BottomSheetDialogFragment

# WiseTrack OAID / referrer add-ons (published unminified, without their own rules).
-keep class io.wisetrack.sdk.oaid.** { *; }
-keep class io.wisetrack.sdk.referrer.** { *; }

# Optional (compileOnly) dependencies may be absent from the app.
-dontwarn com.google.android.gms.**
-dontwarn com.google.firebase.installations.**
-dontwarn com.google.android.material.**
-dontwarn androidx.fragment.**
-dontwarn androidx.navigation.**
-dontwarn androidx.viewpager2.**
-dontwarn io.wisetrack.sdk.oaid.**
-dontwarn io.wisetrack.sdk.referrer.**
-dontwarn javax.annotation.**
-dontwarn java.lang.invoke.StringConcatFactory
