# ProGuard / R8 consumer rules for the CMP Consent Android SDK.
#
# These rules are included in the AAR and applied automatically to the consuming
# app's build. They prevent R8 from stripping or renaming classes that must be
# preserved for correct SDK operation.

# ---------------------------------------------------------------------------
# CMP Consent SDK — keep all public API classes
# ---------------------------------------------------------------------------

# Main SDK entry point and public interfaces
-keep class com.consentos.ConsentOS { *; }
-keep interface com.consentos.ConsentOSListener { *; }

# Data models serialised to/from JSON via kotlinx.serialization
-keep class com.consentos.ConsentState { *; }
-keep class com.consentos.ConsentConfig { *; }
-keep class com.consentos.ConsentConfig$** { *; }
-keep class com.consentos.CachedConfig { *; }
-keep class com.consentos.ConsentPayload { *; }

# Enums used in public API (R8 may inline or remove them if not kept explicitly)
-keep enum com.consentos.ConsentCategory { *; }
-keep enum com.consentos.GCMConsentType { *; }
-keep enum com.consentos.GCMConsentStatus { *; }

# Storage and API protocols — allow apps to provide custom implementations
-keep interface com.consentos.ConsentStorageProtocol { *; }
-keep interface com.consentos.ConsentAPIProtocol { *; }
-keep interface com.consentos.GCMAnalyticsProvider { *; }
-keep class com.consentos.ConsentStorage { *; }
-keep class com.consentos.ConsentAPI { *; }
-keep class com.consentos.GCMBridge { *; }
-keep class com.consentos.NoOpGCMAnalyticsProvider { *; }
-keep class com.consentos.TCFStringEncoder { *; }

# Exceptions — keep for diagnostics / catch blocks in consuming apps
-keep class com.consentos.ConsentAPIException { *; }
-keep class com.consentos.ConsentAPIException$** { *; }

# UI components registered in the manifest
-keep class com.consentos.ui.ConsentBannerActivity { *; }
-keep class com.consentos.ui.ConsentBottomSheet { *; }
-keep class com.consentos.ui.BannerTheme { *; }

# Broadcast action constant
-keep class com.consentos.ConsentOSKt { *; }

# ---------------------------------------------------------------------------
# kotlinx.serialization
# ---------------------------------------------------------------------------

# Serialisation uses reflection to access serialisers; prevent R8 removing them.
-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.AnnotationsKt

-keepclassmembers class kotlinx.serialization.json.** {
    *** Companion;
}
-keepclasseswithmembers class kotlinx.serialization.json.** {
    kotlinx.serialization.KSerializer serializer(...);
}

# Keep all classes annotated with @Serializable
-keep @kotlinx.serialization.Serializable class * { *; }

# Serialiser lookup table generated by the Kotlin compiler
-keep class **$$serializer { *; }
-keepclassmembers class ** {
    *** Companion;
}
-keepclasseswithmembers class ** {
    public static ** INSTANCE;
}

# ---------------------------------------------------------------------------
# Kotlin coroutines
# ---------------------------------------------------------------------------

-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}

-keepclassmembernames class kotlinx.** {
    volatile <fields>;
}

# ---------------------------------------------------------------------------
# AndroidX Security (EncryptedSharedPreferences)
# ---------------------------------------------------------------------------

-keep class androidx.security.crypto.** { *; }

# ---------------------------------------------------------------------------
# Suppress common noise warnings
# ---------------------------------------------------------------------------

-dontwarn java.lang.instrument.ClassFileTransformer
-dontwarn sun.misc.SignalHandler
