# R8/ProGuard rules for the release build (app/build.gradle.kts:isMinifyEnabled = true).
# Default rules from proguard-android-optimize.txt are layered in first.

# ─── kotlinx.serialization ────────────────────────────────────────────────────
# All @Serializable data classes (UserProfile, FoodEntry, WeightEntry,
# ChatMessage, WidgetSnapshot, FoodAnalysis, etc.) are reflected at runtime to
# locate their generated KSerializer$$serializer companion. Strip those and the
# DataStore + widget-snapshot JSON layer breaks at runtime with NoSuchMethodError
# on `serializer()`.
-keepattributes *Annotation*, InnerClasses, Signature
-dontnote kotlinx.serialization.AnnotationsKt

-keepclassmembers class kotlinx.serialization.json.** {
    *** Companion;
}
-keepclasseswithmembers class kotlinx.serialization.json.** {
    kotlinx.serialization.KSerializer serializer(...);
}

# All app-package serializable classes + their generated $$serializer.
-keep,includedescriptorclasses class app.chompass.**$$serializer { *; }
-keepclassmembers class app.chompass.** {
    *** Companion;
}
-keepclasseswithmembers class app.chompass.** {
    kotlinx.serialization.KSerializer serializer(...);
}
# Enum @Serializable lookups need their members preserved for KSerializer.
-keepclassmembers enum app.chompass.** { *; }

# ─── Glance widgets ───────────────────────────────────────────────────────────
# CalorieAppWidget / ProteinAppWidget + their *Receiver classes are loaded by
# the OS via reflection from AndroidManifest. Default Android rules cover the
# Receiver subclasses, but Glance also reflects on the GlanceAppWidget subclass
# itself.
-keep class app.chompass.widget.** { *; }
-keep class * extends androidx.glance.appwidget.GlanceAppWidget { *; }
-keep class * extends androidx.glance.appwidget.GlanceAppWidgetReceiver { *; }

# ─── WorkManager + Room (transitive Glance dependency) ───────────────────────
# Glance widget updates run through WorkManager, which in turn uses Room for its
# WorkDatabase. R8 strips both unless we keep the @Database class and the Worker
# subclasses — without these the app crashes on Application.onCreate with
# "Failed to create an instance of androidx.work.impl.WorkDatabase" the first
# time AppContainer wires the snapshot writer.
-keep class * extends androidx.room.RoomDatabase { *; }
-keep @androidx.room.Database class * { *; }
-keepclassmembers @androidx.room.Database class * { *; }
-keep class androidx.work.impl.** { *; }
-keep class androidx.work.WorkerParameters { *; }
-keep class * extends androidx.work.Worker { *; }
-keep class * extends androidx.work.ListenableWorker { *; }
-dontwarn androidx.work.**
-dontwarn androidx.room.paging.**

# ─── Health Connect ───────────────────────────────────────────────────────────
# The androidx.health.connect.client AAR ships consumer rules that should
# survive R8, but defensively keep WeightRecord / NutritionRecord field access.
-keep class androidx.health.connect.client.records.** { *; }

# ─── Crash reporting ──────────────────────────────────────────────────────────
# Keep line numbers so release crash reports stay readable, but rename
# the original source file name so we don't leak internal file structure.
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
