################################################################################
# DoorstepAI Tracking SDK — consumer ProGuard / R8 keep rules.
#
# Shipped INSIDE the AAR (see `consumerProguardFiles` in build.gradle.kts) so a
# host app that enables R8 / minification in its own release build cannot strip
# or rename the SDK's reflection-dependent code or its public API. These rules
# are applied automatically in the integrator's build — the SDK library itself
# is not minified.
#
# Covered reflective surfaces:
#   - kotlinx.serialization @Serializable models + generated $$serializer classes
#   - Room @Entity / @Dao / @Database + generated *_Impl classes
#   - WorkManager ListenableWorker subclasses (constructed reflectively)
#   - the public DoorstepAI API surface host apps call into
################################################################################

# ---- Public API surface (host apps reference these directly) -----------------
# The public façade package (NOT `.internal.**`, which may be shrunk/renamed
# freely except where the rules below keep specific reflective classes).
-keep public class com.doorstepai.sdks.tracking.* { public protected *; }
-keep public class com.doorstepai.sdks.tracking.*$* { public protected *; }
# Enums are frequently used as serialized values / public parameters — keep them.
-keep public enum com.doorstepai.sdks.tracking.** { *; }

# ---- kotlinx.serialization ---------------------------------------------------
# kotlinx-serialization-json ships its own framework keep rules; these protect
# the SDK's OWN @Serializable classes and their compiler-generated serializers.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault,InnerClasses
-if @kotlinx.serialization.Serializable class com.doorstepai.sdks.tracking.**
-keep,allowobfuscation,allowshrinking class <1>
-keepclassmembers class com.doorstepai.sdks.tracking.** {
    *** Companion;
    kotlinx.serialization.KSerializer serializer(...);
}
-keep,includedescriptorclasses class com.doorstepai.sdks.tracking.**$$serializer { *; }

# ---- Room --------------------------------------------------------------------
# Room ships its own consumer rules; these are belt-and-suspenders for the SDK's
# own entities / DAOs / database and the generated implementation classes.
-keep @androidx.room.Entity class com.doorstepai.sdks.tracking.** { *; }
-keep @androidx.room.Dao class com.doorstepai.sdks.tracking.** { *; }
-keep @androidx.room.Database class com.doorstepai.sdks.tracking.** { *; }
-keep class com.doorstepai.sdks.tracking.**_Impl { *; }

# ---- WorkManager -------------------------------------------------------------
# Workers are instantiated reflectively by WorkManager via their
# (Context, WorkerParameters) constructor.
-keep class com.doorstepai.sdks.tracking.** extends androidx.work.ListenableWorker {
    public <init>(android.content.Context, androidx.work.WorkerParameters);
}

# ---- WebView JS bridge (Doorstep Go embed view) -------------------------------
# DoorstepEmbedView registers a nested bridge object via addJavascriptInterface;
# the page calls its @JavascriptInterface methods BY NAME from JavaScript. The
# class itself may be renamed (the instance is passed directly), but the method
# names must survive host R8 even when the host does not use the AGP default
# proguard-android-optimize.txt (which carries an equivalent rule).
-keepclassmembers class com.doorstepai.sdks.tracking.** {
    @android.webkit.JavascriptInterface <methods>;
}

# ---- SDK BuildConfig ---------------------------------------------------------
# Read at runtime for the fallback base URLs and SDK version.
-keep class com.doorstepai.sdks.tracking.BuildConfig { *; }

# ---- Protobuf (v3 telemetry wire format) -------------------------------------
# protobuf-javalite is R8-friendly but the generated message classes use
# reflection in a few paths (newInstance / dynamicMethod); keep them and the
# GeneratedMessageLite machinery so a host app's minifier can't break encoding.
-keep class com.doorstepai.sdks.tracking.proto.** { *; }
-keep class * extends com.google.protobuf.GeneratedMessageLite { *; }
-keepclassmembers class * extends com.google.protobuf.GeneratedMessageLite {
    <fields>;
}
-dontwarn com.google.protobuf.**
