# R8 rules for release builds (isMinifyEnabled = true).
#
# Most of what this app depends on ships its own consumer rules inside the AAR/JAR —
# Retrofit, OkHttp, Coil, Media3 and kotlinx.serialization all do. What follows is the
# part that is ours, plus a little insurance around reflection-shaped code.

# --- kotlinx.serialization -----------------------------------------------------------
# Every wire model is @Serializable and the gateway contract is pinned by field name, so
# a stripped or renamed serializer is a silent parse failure at runtime rather than a
# build error. The same models are also persisted to DataStore as JSON, which means an
# existing install decodes a blob written by the previous build.
#
# These rules match on the *annotation*, not on a package list. The previous version
# enumerated com.mattcohen.embyscreensaver.data.model — the package the app used through
# v0.1.53 — and so had quietly matched nothing at all. Serializable types today live in
# data.model, data and update; keying off @Serializable means moving one never breaks it.
-keepattributes *Annotation*, InnerClasses, Signature, RuntimeVisibleAnnotations, AnnotationDefault
-dontnote kotlinx.serialization.**

-keep @kotlinx.serialization.Serializable class com.ponzischeme89.memby.** { *; }
-keepclassmembers class com.ponzischeme89.memby.** {
    *** Companion;
}
-keepclasseswithmembers class com.ponzischeme89.memby.** {
    kotlinx.serialization.KSerializer serializer(...);
}
-keepclassmembers class **$$serializer { *; }
-keep,includedescriptorclasses class com.ponzischeme89.memby.**$$serializer { *; }

# --- Retrofit ------------------------------------------------------------------------
# The API interfaces are consumed reflectively; their generic return types must survive
# or Retrofit cannot work out what to deserialize into.
-keep,allowobfuscation interface com.ponzischeme89.memby.data.remote.EmbyApi
-keep,allowobfuscation interface com.ponzischeme89.memby.data.remote.GatewayApi
-keepattributes Exceptions

# --- Room (WorkManager's database) ---------------------------------------------------
# Room instantiates its generated `<Name>_Impl` with getDeclaredConstructor(), so the
# constructor is reachable only by reflection. R8 from AGP 9 removes it while keeping the
# class, and the failure is total: WorkManager builds its database from androidx.startup's
# ContentProvider, so the app dies in handleBindApplication with
# `NoSuchMethodException: androidx.work.impl.WorkDatabase_Impl.<init> []` before any Memby
# code runs — a launcher icon that does nothing, with no Memby frame ever drawn. Room's own
# consumer rules do not cover this on AGP 9. Written as `extends RoomDatabase` rather than
# naming WorkDatabase so a future Room database here is covered too.
-keep class * extends androidx.room.RoomDatabase { <init>(); }

# --- Media3 / coroutines -------------------------------------------------------------
-dontwarn androidx.media3.**
-dontwarn kotlinx.coroutines.**

# --- Crash readability ---------------------------------------------------------------
# Releases are self-hosted with no crash reporter, so a stack trace read off a TV over
# adb is the only diagnostic there is. Line numbers cost a little dex size and are worth
# it; SourceFile is renamed so it does not leak original paths.
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
