# ──────────────────────────────────────────────────────────────────────────────
# Consumer R8 / ProGuard rules.
#
# Applied automatically to host apps that depend on this SDK. The library AAR
# itself is NOT minified (Android Gradle Plugin design): minification happens
# when the host assembles its release APK / bundle. Hence the goal here is
# **dual**:
#
#   1. Make the host's R8 keep what we need to expose to integrators
#      (the narrow public API + the JMRTD reflection surface).
#   2. Let R8 obfuscate everything else (engine, OCR, metering, internal UI).
#      The previous broad `-keep class co.datakeen.nfc.** { *; }` was wrong:
#      it disabled obfuscation for the very classes we want to hide.
#
# Verification: see scripts/verify-aar-obfuscation.sh — assembles the sample
# app in release with minify enabled and grep the dex for engine symbols.
# ──────────────────────────────────────────────────────────────────────────────

# ─── 1. JMRTD + SCUBA + Bouncy Castle ─────────────────────────────────────────
# These libs reflect heavily on data-group classes and crypto provider lookup.
-keep class org.jmrtd.** { *; }
-keep class net.sf.scuba.** { *; }
-keep class org.bouncycastle.** { *; }
# Bouncy Castle ships against several optional providers — keep R8 from
# erroring on the ones the host app doesn't link.
-dontwarn org.bouncycastle.**
-dontwarn java.nio.**
-dontwarn org.codehaus.**
-dontwarn javax.naming.**
-dontwarn org.ietf.jgss.**

# ─── 2. Public SDK API (what host code references directly) ───────────────────
# These names MUST stay stable across builds — host code calls them by name.
# Keep top-level entry points + the public data classes / sealed hierarchies.
-keep class co.datakeen.nfc.NfcScanner { *; }
-keep class co.datakeen.nfc.NfcScanner$* { *; }
-keep class co.datakeen.nfc.NfcScannerContract { *; }
-keep class co.datakeen.nfc.NfcScannerContract$* { *; }
-keep class co.datakeen.nfc.NfcScannerLauncher { *; }
-keep class co.datakeen.nfc.NfcScannerConfig { *; }
-keep class co.datakeen.nfc.NfcScannerTheme { *; }
-keep class co.datakeen.nfc.MeteringMode { *; }
-keep class co.datakeen.nfc.NfcProgress { *; }
-keep class co.datakeen.nfc.NfcReadStep { *; }
-keep interface co.datakeen.nfc.JwtProvider { *; }
# Compose entry point — host calls rememberNfcScannerLauncher(...) by name.
-keep class co.datakeen.nfc.NfcScannerKt {
    public static *** rememberNfcScannerLauncher(...);
}

# Public model types (returned via the result callback — exposed in host code).
-keep class co.datakeen.nfc.model.** { *; }
-keep enum co.datakeen.nfc.model.** { *; }

# Public flow types (sealed hierarchy passed by host to launch()).
-keep class co.datakeen.nfc.flow.** { *; }
-keep enum co.datakeen.nfc.flow.** { *; }

# Headless API used directly by native clients and by the Flutter wrapper.
-keep class co.datakeen.nfc.headless.** { *; }
-keep interface co.datakeen.nfc.headless.** { *; }

# Internal packages (engine, OCR pipeline, metering, UI, internal helpers) are
# intentionally NOT kept — R8 is free to rename them. They are referenced only
# through reflection by JMRTD (covered above) or by our own keep-rules on the
# public surface (covered above).

# ─── 3. kotlinx.serialization ─────────────────────────────────────────────────
# Required for the JSON envelope round-trip (NfcScanResult, metering DTOs).
-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.SerializationKt
-keep,includedescriptorclasses class co.datakeen.nfc.**$$serializer { *; }
-keepclassmembers class co.datakeen.nfc.** {
    *** Companion;
}
-keepclasseswithmembers class co.datakeen.nfc.** {
    kotlinx.serialization.KSerializer serializer(...);
}

# ─── 4. Runtime dependency rules ──────────────────────────────────────────────
# The JPEG2000 decoder initializes and drives its WASM sandbox asynchronously.
# Keep its entry points stable when the host application enables minification.
-keep class dev.keiji.** { *; }
-dontwarn dev.keiji.**

# Tink ships proto-lite messages reflectively loaded by name.
-keep class com.google.crypto.tink.proto.** { *; }
-dontwarn com.google.crypto.tink.**

# DataStore generates Parcelable-ish helpers — let R8 handle them, just keep
# the annotated fields.
-keepclassmembers class * {
    @androidx.datastore.preferences.protobuf.* <fields>;
}
