# ─────────────────────────────────────────────────────────────────────────────
# Ketoy runtime — consumer R8/ProGuard rules.
#
# Shipped inside the ketoy-runtime AAR (consumerProguardFiles) and applied
# automatically in any minified consumer build, so hosts get correct R8 behaviour
# for free — no hand-written keeps required.
#
# The KBC interpreter does two things R8's static call-graph analysis cannot see:
#   1. Resolves @KetoyEntryPoint modules via java.util.ServiceLoader.
#   2. Reflectively dispatches a closed stdlib set (INVOKE_VIRTUAL) on runtime
#      receivers and operates dynamically over its own bytecode + heap model.
# Keep the SPI implementations and the runtime / bytecode / bundle model so the
# members reached only through those dynamic paths survive minification.
# ─────────────────────────────────────────────────────────────────────────────

# ServiceLoader-discovered entry-point modules (KSP-generated, in the consumer's
# own package) + the SPI interface. Registered via META-INF/services and
# instantiated reflectively, so the no-arg constructor must be kept.
-keep,allowobfuscation class * implements dev.ketoy.runtime.compose.KetoyEntryPointModule {
    public <init>();
}
-keep interface dev.ketoy.runtime.compose.KetoyEntryPointModule

# Runtime VM + Compose bridge + bytecode model + bundle format. The interpreter
# constructs/handles these dynamically (heap objects, KBCValue variants, decoded
# instructions) and several are @Serializable wire types whose reflective access
# R8 cannot trace. These packages are small; keeping them whole is the
# correctness-first choice and does not pull in the heavy transitive crypto deps.
-keep class dev.ketoy.runtime.** { *; }
-keep class dev.ketoy.bytecode.** { *; }
-keep class dev.ketoy.bundle.** { *; }

# kotlinx.serialization metadata for the SDK's @Serializable wire types.
-keepattributes RuntimeVisibleAnnotations,AnnotationDefault,*Annotation*
-keepclassmembers class dev.ketoy.** {
    *** Companion;
    kotlinx.serialization.KSerializer serializer(...);
}
-keep,includedescriptorclasses class dev.ketoy.**$$serializer { *; }

# Optional transitive deps reached through direct, typed APIs (no reflection):
# Ed25519 bundle verification (BouncyCastle) and KBC CODE-section decompression
# (Brotli). Silence R8 warnings WITHOUT pinning them, so R8 still shrinks each to
# exactly what's reachable. Do NOT blanket-keep org.bouncycastle.** — that pins
# the entire provider (incl. post-quantum Picnic), adding ~5 MB of dead DEX.
-dontwarn org.bouncycastle.**
-dontwarn org.brotli.**
