# This file defines consumer ProGuard rules for the "core-api" module.
# Be very specific here on keeping ONLY SDK related classes.
#
# Reason:
# When ProGuard processes an app, it aggregates rules from the app’s own ProGuard configuration
# and from each SDK’s "consumer-proguard-rules.pro" file.
# If we have too broad or generic rules in our consumer files, they may inadvertently match classes
# from app's code and it's dependent libraries, leading to enormous increase in its final APK size.

##---------- Begin: ProGuard rules for kotlinx serialization ----------
# Keep `Companion` object fields of serializable classes.
# This avoids serializer lookup through `getDeclaredClasses` as done for named companion objects.
-if @kotlinx.serialization.Serializable class com.linkedin.audiencenetwork.core.**
-keepclassmembers class <1> {
   static <1>$Companion Companion;
}

# Keep `serializer()` on companion objects (both default and named) of serializable classes.
-if @kotlinx.serialization.Serializable class com.linkedin.audiencenetwork.core.** {
   static **$* *;
}
-keepclassmembers class <2>$<3> {
   kotlinx.serialization.KSerializer serializer(...);
}

# Keep `INSTANCE.serializer()` of serializable objects.
-if @kotlinx.serialization.Serializable class com.linkedin.audiencenetwork.core.** {
   public static ** INSTANCE;
}
-keepclassmembers class <1> {
   public static <1> INSTANCE;
   kotlinx.serialization.KSerializer serializer(...);
}

# @Serializable and @Polymorphic are used at runtime for polymorphic serialization.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault
##---------- End: ProGuard rules for kotlinx serialization ----------

# Post AGP 8.0 default value of android.r8.failOnMissingClasses has been set to true
# which was false earlier by befault.
# Hence, below missing classes were causing build failure with AGP 8.0+.
# android.r8.failOnMissingClasses is not configurable anymore, hence they have been added here.
# reference: https://developer.android.com/build/releases/past-releases/agp-8-0-0-release-notes#enforced-changes
-dontwarn javax.annotation.concurrent.GuardedBy
-dontwarn com.google.errorprone.annotations.RestrictedApi
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
-dontwarn com.google.errorprone.annotations.CheckReturnValue
-dontwarn com.google.errorprone.annotations.Immutable

# TODO(rkhinda): We aren't using reflection anymore, evaluate if we should delete these rules.
# These classes are accessed using reflection while initialising the SDK, hence adding rule to
# prevent it from being obfuscating
-keep class com.linkedin.audiencenetwork.core.logging.* { public *; }
-keep class com.linkedin.audiencenetwork.core.networking.* { public *; }

# Added so we can keep certain parts of our Data classes which are serialized/deserialized using GSON.
# Unfortunately, "-keep class * implements com.linkedin.audiencenetwork.core.data.DataModel { *; }" doesn't work.
# Refer: https://github.com/linkedin-multiproduct/android-audience-network/pull/94#issuecomment-2427368936
-keep public class com.linkedin.audiencenetwork.core.** {
    public protected *;
    <fields>;
}

# TODO(rkhinda): Evaluate if we should delete these "-dontwarn" rules.
-dontwarn com.google.api.client.http.GenericUrl
-dontwarn com.google.api.client.http.HttpHeaders
-dontwarn com.google.api.client.http.HttpRequest
-dontwarn com.google.api.client.http.HttpRequestFactory
-dontwarn com.google.api.client.http.HttpResponse
-dontwarn com.google.api.client.http.HttpTransport
-dontwarn com.google.api.client.http.javanet.NetHttpTransport$Builder
-dontwarn com.google.api.client.http.javanet.NetHttpTransport
-dontwarn com.google.errorprone.annotations.InlineMe
-dontwarn org.joda.time.Instant
