# =============================================================================
# ComplyCube SDK — consumer ProGuard/R8 rules
# =============================================================================
# These rules are applied by every app that depends on the ComplyCube SDK AAR.
# They must protect every type listed in the Binary Compatibility Validator
# dumps (api/sdk.api, api/sdk-nonNfc.api) from being stripped or obfuscated
# in the consumer's release build.
#
# To audit alignment with the .api surface, run:
#     python3 sdk/scripts/audit_consumer_rules.py
# The script will list any public type from .api that is not covered by a
# -keep rule below. CI should fail on uncovered types.
#
# When you change the public API (adding/removing a public class or member):
#   1. Run `./gradlew apiDump` to refresh api/*.api
#   2. Re-run the audit script
#   3. If it reports gaps, add targeted -keep rules here
# =============================================================================


# -----------------------------------------------------------------------------
# Public API surface
# -----------------------------------------------------------------------------
# Keep every class in the SDK namespace plus all of its members. The public
# .api surface spans seven subpackages and 370 types (Compose presentation
# layer, data models, themes, analytics, etc.), so we keep the namespace
# wholesale rather than maintaining a list that drifts from BCV. The audit
# script guarantees everything in .api is still covered.
-keep class com.complycube.sdk.** { *; }
-keep interface com.complycube.sdk.** { *; }
-keep enum com.complycube.sdk.** { *; }

# Inner classes (Builder, SdkResultContract, Companion, $serializer, etc.)
-keep class com.complycube.sdk.**$* { *; }

# Preserve original class/member names so that ClassNotFoundException and
# reflective lookups (e.g. Class.forName, KClass.qualifiedName) keep working
# for consumers who wire the SDK in from configuration.
-keepnames class com.complycube.sdk.**
-keepnames interface com.complycube.sdk.**


# -----------------------------------------------------------------------------
# kotlinx.serialization
# -----------------------------------------------------------------------------
# SDK models annotated with @Serializable rely on companion-based serializer
# lookup. Without these rules R8 can strip the synthetic Companion / $serializer
# members even though the enclosing class is kept, causing SerializationException
# at runtime in the consumer app.

# Keep `Companion` object fields of serializable classes.
-if @kotlinx.serialization.Serializable class **
-keepclassmembers class <1> {
    static <1>$Companion Companion;
}

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

# Keep `INSTANCE.serializer()` on serializable `object` declarations.
-if @kotlinx.serialization.Serializable class ** {
    public static ** INSTANCE;
}
-keepclassmembers class <1> {
    public static <1> INSTANCE;
    kotlinx.serialization.KSerializer serializer(...);
}


# -----------------------------------------------------------------------------
# Gson reflective TypeToken usage
# -----------------------------------------------------------------------------
# Some SDK code paths deserialize generic types through Gson's TypeToken.
# Anonymous TypeToken subclasses must retain their generic signature.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken**
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken**
-keepattributes Signature


# -----------------------------------------------------------------------------
# Annotations on the public API
# -----------------------------------------------------------------------------
# Compose uses invisible runtime annotations (@Composable, @Stable, @Immutable)
# for behavioural guarantees; strip them and the consumer's Compose compiler
# output can diverge from the SDK's. Visible annotations are kept for any
# reflective framework the consumer may plug in.
-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes AnnotationDefault
-keepattributes InnerClasses
-keepattributes EnclosingMethod


# -----------------------------------------------------------------------------
# Third-party warnings surfaced through the SDK classpath
# -----------------------------------------------------------------------------
# These come from optional transitive dependencies (Regula NFC reader,
# BouncyCastle) that are only reachable in specific flavors. Silence the
# warnings so consumer builds don't fail on -dontwarn-less setups.
-dontwarn com.regula.documentreader.api.errors.DocumentReaderException
-dontwarn com.regula.documentreader.api.params.rfid.PKDCertificate
-dontwarn com.regula.documentreader.api.results.DocumentReaderResults
-dontwarn org.bouncycastle.**
-keep class org.bouncycastle.** { *; }
