# Kontext Ads SDK consumer ProGuard rules.
#
# Packaged in the AAR; auto-applied by R8 in the consuming app's release
# build. Their only job is to stop R8 from breaking what the SDK can't
# defend itself: public API names that consumer code references in
# strings (intent class names, reflection, JS bridges) and serializer
# classes generated by kotlinx.serialization.
#
# Mirrors what sdk-swift gets for free from `@objc` / module exports —
# Android needs the rules explicit because R8 is more aggressive.

# ---------------------------------------------------------------------------
# Public API: top-level entry points
# ---------------------------------------------------------------------------
-keep public class so.kontext.ads.KontextAds { public *; }
-keep public class so.kontext.ads.Session { public *; }
-keep public class so.kontext.ads.Ad { public *; }

# Top-level Compose `InlineAd(...)` function lives on the synthetic
# `InlineAdKt` class — Kotlin compiles top-level fns into a `<File>Kt`.
-keep public class so.kontext.ads.ui.InlineAdKt { public *; }

# ---------------------------------------------------------------------------
# Public UI components
# ---------------------------------------------------------------------------
# View-based wrapper for non-Compose hosts.
-keep public class so.kontext.ads.ui.InlineAdView { public *; }

# Activity referenced by class name in the manifest + via Intent class
# lookup at launch time. Dropping it would NPE Context.startActivity.
-keep public class so.kontext.ads.ui.InterstitialAdActivity { public *; }

# ---------------------------------------------------------------------------
# Public model types
# ---------------------------------------------------------------------------
# Blanket the `model` package so adding a new public type doesn't
# silently get pruned. Currently covers: AdEvent (sealed, with Viewed /
# Clicked / RenderStarted / RenderCompleted / Error / RewardGranted /
# VideoStarted / VideoCompleted / Generic subtypes), AdOptions,
# AddMessageOptions, Character, Message, Regulatory, Role, SessionOptions,
# MutablePublisherOptions, UserEventName, plus AdEventHandler and
# DebugEventHandler typealiases.
#
# Sealed-class subtypes especially need this — consumer `when` blocks
# reference them, but R8 can prune unused subtypes if a publisher's
# code only handles a subset.
-keep public class so.kontext.ads.model.** { public *; }

# ---------------------------------------------------------------------------
# WebView JS bridge (called reflectively from injected JavaScript)
# ---------------------------------------------------------------------------
# Bridges are `private inner class`es on the host views. R8 can rename
# the methods even though the enclosing class is kept — pin the
# `@JavascriptInterface` members specifically. The narrow `class X`
# scope (vs `class *`) means we don't accidentally cement the
# consumer app's own JS bridges.
-keepclassmembers class so.kontext.ads.ui.InterstitialAdActivity$ModalBridgeInterface {
    @android.webkit.JavascriptInterface <methods>;
}
-keepclassmembers class so.kontext.ads.ui.AdWebView$BridgeInterface {
    @android.webkit.JavascriptInterface <methods>;
}

# ---------------------------------------------------------------------------
# kotlinx.serialization — DTOs under network/dto/
# ---------------------------------------------------------------------------
# Only the DTOs are @Serializable; domain `model` types are plain
# data classes and don't need these rules.
-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.AnnotationsKt

# Generated `$$serializer` class for every @Serializable DTO — looked
# up by name at runtime by the serialization framework.
-keep,includedescriptorclasses class so.kontext.ads.network.dto.**$$serializer { *; }

# Each @Serializable type's `Companion.serializer(...)` method.
-keepclassmembers class so.kontext.ads.network.dto.** {
    *** Companion;
}
-keepclasseswithmembers class so.kontext.ads.network.dto.** {
    kotlinx.serialization.KSerializer serializer(...);
}
