# ProGuard/R8 consumer rules for Appstack Attribution SDK
#
# This file is packaged inside the AAR produced by the :sdk module.
# When an app depends on this AAR, its contents are automatically merged into
# the final R8/ProGuard rules applied during the consumer app's minification.
#
# These rules prevent runtime crashes (ClassNotFoundException, NoSuchMethodException)
# that occur when reflection-based or serialized classes are obfuscated.

# ================================================================================
# Appstack SDK Core Classes
# ================================================================================

# Keep all public API classes and their members
-keep class com.appstack.attribution.AppstackAttributionSdk { *; }
-keep class com.appstack.attribution.EventType { *; }
-keep class com.appstack.attribution.LogLevel { *; }
-keep class com.appstack.attribution.HttpException { *; }
-keep class com.appstack.attribution.AuthenticationException { *; }

# Keep listener interfaces
-keep interface com.appstack.attribution.InitListener { *; }

# Internal SDK config (constructed in code only; kept conservatively)
-keep class com.appstack.attribution.internal.core.Config { *; }

# ================================================================================
# Data Classes (Moshi JSON Serialization)
# ================================================================================

# Keep the data classes used in JSON serialization. Their adapters are generated at
# compile time by Moshi KSP codegen (@JsonClass); the generated *JsonAdapter classes
# read these constructors/fields, so they must survive R8.
-keep class com.appstack.attribution.internal.model.RemoteConfig { *; }
-keep class com.appstack.attribution.internal.model.UTMParameters { *; }
-keep class com.appstack.attribution.internal.model.UserData { *; }
-keep class com.appstack.attribution.internal.model.EventServerLogRequest { *; }
-keep class com.appstack.attribution.internal.model.EventUserData { *; }
-keep class com.appstack.attribution.internal.model.TransactionDetails { *; }

# Keep @Json annotated fields and constructors
-keepclassmembers class com.appstack.attribution.** {
    @com.squareup.moshi.Json <fields>;
    <init>(...);
}

# ================================================================================
# WorkManager
# ================================================================================
#
# No keep rules needed. The SDK no longer ships a Worker; its only WorkManager use is
# cancelUniqueWork(String) — a stable, non-reflective API — behind a guarded try/catch in
# AppstackAttributionSdk. WorkManager itself is a compileOnly dependency, so it isn't on the
# consumer's classpath unless the consumer ships it independently.

# ================================================================================
# Moshi
# ================================================================================

# Keep Moshi-generated adapters
-keep class com.appstack.attribution.**JsonAdapter { *; }

# Keep @JsonClass annotated classes
-keep @com.squareup.moshi.JsonClass class * { *; }

# Keep Kotlin metadata for Moshi
-keepclassmembers class * {
    @com.squareup.moshi.FromJson <methods>;
    @com.squareup.moshi.ToJson <methods>;
}

# ================================================================================
# Retrofit
# ================================================================================

# Keep generic signature of Retrofit service methods
-keepattributes Signature, InnerClasses, EnclosingMethod
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
-keepattributes AnnotationDefault

# Keep Retrofit service interfaces
-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}

# Retrofit does reflection on generic parameters
-keepclassmembers,allowshrinking,allowobfuscation interface * {
    @retrofit2.http.* <methods>;
}

# ================================================================================
# OkHttp
# ================================================================================

-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**

# Keep OkHttp platform classes
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase

# ================================================================================
# Kotlin Coroutines
# ================================================================================

-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}

# Keep Continuation for suspend functions
-keepclassmembers class kotlin.coroutines.Continuation { *; }

# ================================================================================
# Kotlin
# ================================================================================

# Keep Kotlin metadata (needed for reflection on Kotlin classes)
-keepattributes *Annotation*, Signature, Exception

# Keep Kotlin data class component functions
-keepclassmembers class com.appstack.attribution.** {
    public ** component*();
    public ** copy(...);
}

# ================================================================================
# Install Referrer
# ================================================================================

-keep class com.android.installreferrer.** { *; }
-keep interface com.android.installreferrer.** { *; }

-if class com.appstack.attribution.internal.model.EventServerLogRequest
-keepnames class com.appstack.attribution.internal.model.EventServerLogRequest
-if class com.appstack.attribution.internal.model.EventServerLogRequest
-keep class com.appstack.attribution.internal.model.EventServerLogRequestJsonAdapter {
    public <init>(com.squareup.moshi.Moshi);
}
-if class com.appstack.attribution.internal.model.EventServerLogRequest
-keepnames class kotlin.jvm.internal.DefaultConstructorMarker
-if class com.appstack.attribution.internal.model.EventServerLogRequest
-keepclassmembers class com.appstack.attribution.internal.model.EventServerLogRequest {
    public synthetic <init>(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.util.Map,com.appstack.attribution.internal.model.TransactionDetails,java.lang.String,java.lang.String,java.lang.String,java.lang.String,com.appstack.attribution.internal.model.EventUserData,java.lang.String,int,kotlin.jvm.internal.DefaultConstructorMarker);
}

-if class com.appstack.attribution.internal.model.EventUserData
-keepnames class com.appstack.attribution.internal.model.EventUserData
-if class com.appstack.attribution.internal.model.EventUserData
-keep class com.appstack.attribution.internal.model.EventUserDataJsonAdapter {
    public <init>(com.squareup.moshi.Moshi);
}
-if class com.appstack.attribution.internal.model.EventUserData
-keepnames class kotlin.jvm.internal.DefaultConstructorMarker
-if class com.appstack.attribution.internal.model.EventUserData
-keepclassmembers class com.appstack.attribution.internal.model.EventUserData {
    public synthetic <init>(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Long,java.lang.Long,int,kotlin.jvm.internal.DefaultConstructorMarker);
}

-if class com.appstack.attribution.internal.model.RemoteConfig
-keepnames class com.appstack.attribution.internal.model.RemoteConfig
-if class com.appstack.attribution.internal.model.RemoteConfig
-keep class com.appstack.attribution.internal.model.RemoteConfigJsonAdapter {
    public <init>(com.squareup.moshi.Moshi);
}
-if class com.appstack.attribution.internal.model.RemoteConfig
-keepnames class kotlin.jvm.internal.DefaultConstructorMarker
-if class com.appstack.attribution.internal.model.RemoteConfig
-keepclassmembers class com.appstack.attribution.internal.model.RemoteConfig {
    public synthetic <init>(java.lang.String,boolean,java.lang.String,java.lang.Integer,int,kotlin.jvm.internal.DefaultConstructorMarker);
}

-if class com.appstack.attribution.internal.model.TransactionDetails
-keepnames class com.appstack.attribution.internal.model.TransactionDetails
-if class com.appstack.attribution.internal.model.TransactionDetails
-keep class com.appstack.attribution.internal.model.TransactionDetailsJsonAdapter {
    public <init>(com.squareup.moshi.Moshi);
}

-if class com.appstack.attribution.internal.model.UTMParameters
-keepnames class com.appstack.attribution.internal.model.UTMParameters
-if class com.appstack.attribution.internal.model.UTMParameters
-keep class com.appstack.attribution.internal.model.UTMParametersJsonAdapter {
    public <init>(com.squareup.moshi.Moshi);
}
-if class com.appstack.attribution.internal.model.UTMParameters
-keepnames class kotlin.jvm.internal.DefaultConstructorMarker
-if class com.appstack.attribution.internal.model.UTMParameters
-keepclassmembers class com.appstack.attribution.internal.model.UTMParameters {
    public synthetic <init>(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.Long,java.lang.Long,int,kotlin.jvm.internal.DefaultConstructorMarker);
}

-if class com.appstack.attribution.internal.model.UserData
-keepnames class com.appstack.attribution.internal.model.UserData
-if class com.appstack.attribution.internal.model.UserData
-keep class com.appstack.attribution.internal.model.UserDataJsonAdapter {
    public <init>(com.squareup.moshi.Moshi);
}
-if class com.appstack.attribution.internal.model.UserData
-keepnames class kotlin.jvm.internal.DefaultConstructorMarker
-if class com.appstack.attribution.internal.model.UserData
-keepclassmembers class com.appstack.attribution.internal.model.UserData {
    public synthetic <init>(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.util.Map,java.util.Map,java.util.Map,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,int,kotlin.jvm.internal.DefaultConstructorMarker);
}
