# Consumer rules: Gradle applies this file to every integrating app's shrunk
# build (consumerProguardFiles in build.gradle.kts). Nothing here is needed for
# the SDK's own build; the app's R8 is the only shrinker that ever sees these.
#
# Only two kinds of class are kept by name. Everything else under
# com.adshift.sdk is internal and the app's R8 may remove, inline, merge and
# rename it, which is what every mature library lets it do. Kotlin `internal`
# compiles to a public class, so `-keep public class com.adshift.sdk.**` would
# keep nearly all of the SDK and is not what is written here.

# 1. What integrators call.
#
# The list is the recorded public API in api/adshift-kotlin.api, which apiCheck
# holds the code to; ConsumerKeepRulesTest holds this list to the record, so a
# class cannot be added to the API without a keep here, or kept here after it
# left the API. Kept by name, not just from shrinking: integrators reach these
# through compiled references today, but a class kept by name also survives an
# app that calls the SDK through reflection, and stays readable in a crash
# report that arrives without the app's mapping file.
-keep public class com.adshift.sdk.core.ASAdRevenueData { public *; }
-keep public class com.adshift.sdk.core.ASInAppEventParameterName { public *; }
-keep public class com.adshift.sdk.core.ASInAppEventType { public *; }
-keep public class com.adshift.sdk.core.ASMediationNetwork { public *; }
-keep public class com.adshift.sdk.core.AdShiftConsent { public *; }
-keep public class com.adshift.sdk.core.AdShiftConsent$Companion { public *; }
-keep public class com.adshift.sdk.core.AdShiftLib { public *; }
-keep public class com.adshift.sdk.core.AdShiftRequestListener { public *; }
-keep public class com.adshift.sdk.core.AdShiftThirdPartySharing { public *; }
-keep public class com.adshift.sdk.core.AdShiftThirdPartySharing$Companion { public *; }
-keep public class com.adshift.sdk.core.ConsentHint { public *; }
-keep public class com.adshift.sdk.core.ConsentOptions { public *; }
-keep public class com.adshift.sdk.core.ConsentOptions$Companion { public *; }
-keep public class com.adshift.sdk.core.ConsentSnapshot { public *; }
-keep public class com.adshift.sdk.core.ConsentSource { public *; }
-keep public class com.adshift.sdk.core.IabPrefsProvider { public *; }
-keep public class com.adshift.sdk.core.deeplink.DeepLinkError { public *; }
-keep public class com.adshift.sdk.core.deeplink.DeepLinkListener { public *; }
-keep public class com.adshift.sdk.core.deeplink.DeepLinkResult { public *; }
-keep public class com.adshift.sdk.core.deeplink.DeepLinkStatus { public *; }
-keep public class com.adshift.sdk.utils.ASLogger { public *; }
-keep public class com.adshift.sdk.utils.ASLogger$LogLevel { public *; }

# 2. What the JSON library builds by reflection.
#
# Requests and responses go through Gson (via Retrofit), and the persistent
# event and click queues and the stored deferred link are Gson files on disk.
# Gson reads these classes' fields, their generic signatures and their no-arg
# constructors through reflection, and R8 in full mode treats a class it sees no
# `new` for as never instantiated. Kept whole and by name: version 3.0.0 shipped
# an R8 regression on exactly this layer, and a dozen small data classes are not
# where the size is. Field names matter twice over: ValidateApiKeyDto has no
# @SerializedName, so its field names are the wire names, and the persisted
# queues are read back by builds that will run after this one.
-keep class com.adshift.sdk.core.network.AdshiftInAppEventRequest { *; }
-keep class com.adshift.sdk.core.network.ValidateApiKeyDto { *; }
-keep class com.adshift.sdk.core.network.ApiKeyValidationResponse { *; }
-keep class com.adshift.sdk.core.network.DeepLinkResponse { *; }
-keep class com.adshift.sdk.core.network.ShortLinkResolveResponse { *; }
-keep class com.adshift.sdk.core.consent.ConsentPayload { *; }
-keep class com.adshift.sdk.core.consent.ThirdPartySharing { *; }
-keep class com.adshift.sdk.core.consent.ConsentData { *; }
-keep class com.adshift.sdk.core.consent.ConsentData$Manual { *; }
-keep class com.adshift.sdk.core.consent.ConsentData$TCF { *; }
-keep class com.adshift.sdk.core.consent.ConsentData$GPP { *; }
-keep class com.adshift.sdk.core.QueuedClick { *; }
-keep class com.adshift.sdk.core.deeplink.StoredDeepLink { *; }

# Net for a model added later without a line above: any SDK class with a
# @SerializedName field is kept (renamable, so its signature survives full
# mode) together with those fields and its no-arg constructor. These are the
# rules Gson 2.11+ ships; the Gson this SDK depends on ships none. A model that
# relies on field names is not covered by this and needs a line above.
-keepclassmembers,allowobfuscation class com.adshift.sdk.** {
    @com.google.gson.annotations.SerializedName <fields>;
}
-if class com.adshift.sdk.** { @com.google.gson.annotations.SerializedName <fields>; }
-keep,allowobfuscation class com.adshift.sdk.<1>
-if class com.adshift.sdk.** { @com.google.gson.annotations.SerializedName <fields>; }
-keepclassmembers,allowobfuscation,allowoptimization class com.adshift.sdk.<1> { <init>(); }

# The Retrofit service interfaces (AdShiftApi, DlAdShiftApi, ShortLinkApi) are
# not listed: Retrofit's own consumer rules keep every interface with
# @retrofit2.http methods and those methods' signatures, and they travel with
# the retrofit jar this SDK depends on. The OAID AIDL stubs are not listed
# either: the Binder descriptors and service components are string literals
# naming the vendor's package, so neither our class names nor their visibility
# take part in the bind.

# Keep generic signature of Call, Response (R8 full mode strips signatures from non-kept items).
 -keep,allowobfuscation,allowshrinking interface retrofit2.Call
 -keep,allowobfuscation,allowshrinking class retrofit2.Response

 # With R8 full mode generic signatures are stripped for classes that are not
 # kept. Suspend functions are wrapped in continuations where the type argument
 # is used.
 -keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation

# Queued payloads are stored as JSON and their element type is read back from a
# generic signature. These are the rules the JSON library ships for shrinkers.
# In full mode an attribute survives only on a class a keep rule also matches,
# so the keep on the token class itself is the load-bearing one: without it the
# subclass signature is rewritten without type arguments.
-keepattributes Signature
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault

-if class com.google.gson.reflect.TypeToken
-keep,allowobfuscation class com.google.gson.reflect.TypeToken
-keep,allowobfuscation class * extends com.google.gson.reflect.TypeToken

# Huawei SDK
-keep class com.huawei.hms.ads.** {*; }
-keep interface com.huawei.hms.ads.** {*; }

# Honor SDK
-keep class com.hihonor.ads.** {*; }
-keep interface com.hihonor.ads.** {*; }

