# ============================================
# OBFUSCATION RULES FOR finos.sdk.ekyc
# Tương tự easyCA.aar - chỉ giữ public API, obfuscate internal code
# ============================================

# Remove all Log class calls (Log.d, Log.e, Log.w, etc.)
#noinspection ShrinkerUnresolvedReference
-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
    public static *** i(...);
    public static *** w(...);
    public static *** e(...);
    public static *** println(...);
}

# Giữ lại các annotation để parse JSON đúng
-keepattributes *Annotation*
-keepattributes Signature
-keepattributes Exceptions
-keepattributes InnerClasses,EnclosingMethod
-keepattributes SourceFile,LineNumberTable

# Global options (-dontskipnonpubliclibraryclasses, -renamesourcefileattribute,
# -keeppackagenames) đã được chuyển sang proguard-rules_app.pro vì AGP cấm dùng
# trong consumerProguardFiles (sẽ override config của app downstream).

# ============================================
# PUBLIC API CLASSES - CHỈ GIỮ LẠI CÁC CLASS NÀY
# ============================================

# Main SDK Entry Points
-keep @androidx.annotation.Keep class finos.sdk.ekyc.FinOSeKYC { *; }
-keep @androidx.annotation.Keep class finos.sdk.ekyc.SDKEkycApplication { *; }
# Host applications can embed/preview these documented SDK UI types directly.
-keep class finos.sdk.ekyc.sdkui.ui.finos.base.EKBaseFragment { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.design.SDKTheme { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.design.SDKTheme$* { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.result.EKSuccessFragment { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.result.EKVerificationSummaryFragment { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.nfc.EKNFCBottomSheet { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.nfc.EKNFCBottomSheet$* { *; }
# Referenced by demo/android PreviewActivity (screen previews); R8 in the host app fails
# with "Missing class" if the library AAR strips/renames them.
-keep class finos.sdk.ekyc.sdkui.ui.finos.components.EKLoadingOverlay { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.design.EKTypeKt { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.welcome.EKWelcomeFragment { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.ocr.EKOCRReviewFragment { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.nfc.EKNFCIntroFragment { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.liveness.EKLivenessIntroFragment { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.liveness.EKLivenessIntroFragment$* { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.result.EKFailureFragment { *; }
-keep class finos.sdk.ekyc.sdkui.ui.finos.screens.result.EKFailureFragment$* { *; }

# Init Classes (cần cho Koin DI)
-keep class finos.sdk.ekyc.SDKEkycInit { *; }
-keep class finos.sdk.ekyc.SDKEkycInitKt { *; }
-keep class finos.sdk.c06.SDKC06Init { *; }
-keep class finos.sdk.c06.SDKC06InitKt { *; }
-keep class finos.sdk.faceservice.SDKFaceServiceInit { *; }
-keep class finos.sdk.faceservice.SDKFaceServiceInitKt { *; }
-keep class finos.sdk.liveness.SDKLivenessInit { *; }
-keep class finos.sdk.liveness.SDKLivenessInitKt { *; }
-keep class finos.sdk.nfc.SDKNfcInit { *; }
-keep class finos.sdk.nfc.SDKNfcInitKt { *; }
-keep class finos.sdk.ocr.SDKOcrInit { *; }
-keep class finos.sdk.ocr.SDKOcrInitKt { *; }
-keep class finos.sdk.smsotp.SDKSmsOtpServiceInit { *; }
-keep class finos.sdk.smsotp.SDKSmsOtpServiceInitKt { *; }

# Public Service Classes (giữ lại để client có thể inject)
-keep class finos.sdk.core.service.SDKEkycService { *; }
-keep class finos.sdk.core.service.SDKBackOfficeKyc { *; }
-keep class finos.sdk.core.service.SDKSmsOtpService { *; }
# Android adapters are referenced from separately published feature AARs. They must
# retain a stable ABI across each module's independent R8 pass.
-keep class finos.sdk.core.service.android.SDKEkycService { *; }
-keep class finos.sdk.core.service.android.SDKBackOfficeKyc { *; }
-keep class finos.sdk.core.service.android.SDKSmsOtpService { *; }
-keep class finos.sdk.core.callback.EkycErrorCallback { *; }
-keep class finos.sdk.core.callback.EkycSuccessCallback { *; }
-keep class finos.sdk.core.security.EKSecurityManager { *; }
-keep class finos.sdk.core.security.EKMicroTremorTracker { *; }
-keep class finos.sdk.core.security.EKMicroTremorTracker$* { *; }
-keep @androidx.annotation.Keep class finos.sdk.smsotp.FinOSOtp { *; }

# Public SDK Entry Points cho các module (có @Keep annotation)
# Chỉ giữ lại các class public, không có logic code bên trong
-keep @androidx.annotation.Keep class finos.sdk.nfc.FinOSeKYCNfc { *; }
-keep @androidx.annotation.Keep class finos.sdk.ocr.FinOSeKYCOcr { *; }
-keep @androidx.annotation.Keep class finos.sdk.c06.FinOSeKYCC06 { *; }
-keep @androidx.annotation.Keep class finos.sdk.liveness.FinOSeKYCLiveness { *; }
-keep @androidx.annotation.Keep class finos.sdk.faceservice.FinOSeKYCFaceService { *; }

# Internal Implementation Classes - cho phép obfuscate hoàn toàn
-keep,allowobfuscation class finos.sdk.nfc.FinOSeKYCNfcImpl { *; }
-keep,allowobfuscation class finos.sdk.ocr.FinOSeKYCOcrImpl { *; }
-keep,allowobfuscation class finos.sdk.c06.FinOSeKYCC06Impl { *; }
-keep,allowobfuscation class finos.sdk.liveness.FinOSeKYCLivenessImpl { *; }
-keep,allowobfuscation class finos.sdk.faceservice.FinOSeKYCFaceServiceImpl { *; }

# Tự động giữ lại tất cả các class có @Keep annotation
-keep @androidx.annotation.Keep class finos.sdk.** { *; }

# Define & Constant Classes (cần cho callbacks, config, defaults)
-keep @androidx.annotation.Keep class finos.sdk.core.define.** { *; }
-keep class finos.sdk.core.define.*Serializer { *; }
-keep class finos.sdk.core.constant.GeneratedDevConfig { *; }
-keep class finos.sdk.core.constant.GeneratedSdkDefaults { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.constant.** { *; }
# AppIDType, SDKType, SDKBundleEvent, SDKApiCode và SDKStepType (không có @Keep nhưng cần cho các module)
-keep class finos.sdk.core.define.AppIDType { *; }
-keep class finos.sdk.core.define.SDKType { *; }
-keep class finos.sdk.core.define.SDKBundleEvent { *; }
-keep class finos.sdk.core.define.SDKApiCode { *; }
-keep class finos.sdk.core.define.SDKStepType { *; }

# Model Classes (có @Keep annotation - cần cho serialization)
-keep @androidx.annotation.Keep class finos.sdk.core.model.** { *; }
# EkycStateModel và nested class
-keep @androidx.annotation.Keep class finos.sdk.core.model.sdk.EkycStateModel { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.model.sdk.EkycStateModel$* { *; }
-keep class finos.sdk.core.model.sdk.EkycStateModel$FileEKYCModel { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.model.request.** { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.model.response.** { *; }
# Request/Response Models - giữ lại tất cả nested classes
-keep class finos.sdk.core.model.request.CheckC06Request { *; }
-keep class finos.sdk.core.model.request.AuditNfcRequest { *; }
-keep class finos.sdk.core.model.request.AuditNfcRequest$* { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.model.response.CheckC06Response { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.model.response.CheckC06Response$* { *; }
-keep class finos.sdk.core.model.response.CheckC06Response$C06CheckResult { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.model.response.CheckFaceResponse { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.model.response.CheckFaceResponse$* { *; }
-keep class finos.sdk.core.model.response.CheckFaceResponse$FaceVerifyResult { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.model.response.CheckLivenessResponse { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.model.response.CheckLivenessResponse$* { *; }
-keep class finos.sdk.core.model.response.CheckLivenessResponse$LivenessCheckResult { *; }
# Giữ lại tất cả nested classes trong response models
-keep @androidx.annotation.Keep class finos.sdk.core.model.response.**$* { *; }
# CheckOcrResponse và tất cả nested classes (có nhiều level nested)
-keep @androidx.annotation.Keep class finos.sdk.core.model.response.CheckOcrResponse { *; }
-keep @androidx.annotation.Keep class finos.sdk.core.model.response.CheckOcrResponse$* { *; }
-keep class finos.sdk.core.model.response.CheckOcrResponse$OcrCheckResult { *; }
-keep class finos.sdk.core.model.response.CheckOcrResponse$OcrCheckResult$* { *; }
-keep class finos.sdk.core.model.response.CheckOcrResponse$OcrCheckResult$Detail { *; }
-keep class finos.sdk.core.model.response.CheckOcrResponse$OcrCheckResult$Detail$* { *; }
-keep class finos.sdk.core.model.response.CheckOcrResponse$OcrCheckResult$Detail$FieldsExtracted { *; }
-keep class finos.sdk.core.model.response.CheckOcrResponse$OcrCheckResult$Detail$FieldsExtracted$* { *; }
-keep class finos.sdk.core.model.response.CheckOcrResponse$OcrCheckResult$Detail$FieldsExtracted$MrzString { *; }
# CheckSummaryResponse
-keep class finos.sdk.core.model.response.CheckSummaryResponse { *; }
-keep class finos.sdk.core.model.response.CheckSummaryResponse$* { *; }
# SDKListTransactionResponse và nested classes
-keep class finos.sdk.core.model.response.SDKListTransactionResponse { *; }
-keep class finos.sdk.core.model.response.SDKListTransactionResponse$* { *; }
-keep class finos.sdk.core.model.response.SDKListTransactionResponse$ResultWrapper { *; }
-keep class finos.sdk.core.model.response.SDKListTransactionResponse$ResultWrapper$* { *; }
-keep class finos.sdk.core.model.response.SDKListTransactionResponse$ResultWrapper$Details { *; }
-keep class finos.sdk.core.model.response.SDKListTransactionResponse$ResultWrapper$Details$* { *; }
-keep class finos.sdk.core.model.response.SDKListTransactionResponse$ResultWrapper$Details$Transactions { *; }
# SDKImageResultModel
-keep class finos.sdk.core.model.response.SDKImageResultModel { *; }
# NFC model classes (cần cho NFC module)
-keep class finos.sdk.core.model.response.nfc.** { *; }
-keep class finos.sdk.core.model.response.nfc.DG13File { *; }
-keep class finos.sdk.core.model.response.nfc.NFCData { *; }
-keep class finos.sdk.core.model.response.nfc.NfcInfo { *; }
-keep @androidx.annotation.Keep class finos.sdk.nfc.model.** { *; }

# Config Classes (có @Keep annotation)
-keep @androidx.annotation.Keep class finos.sdk.core.model.sdk.config.** { *; }
# LivenessConfig (không có @Keep nhưng cần cho NFC module)
-keep class finos.sdk.core.model.sdk.config.LivenessConfig { *; }

# Core Utils (cần cho public API)
-keep class finos.sdk.core.utils.** { *; }
-keep class finos.sdk.core.utils.FileUtils { *; }
-keep class finos.sdk.core.utils.UtilsKt { *; }

# EKYCErrorResult - giữ lại class, nested objects, companion object và nested classes
# Giữ lại toàn bộ class và tất cả nested classes (không có điều kiện @Keep để đảm bảo R8 không bỏ sót)
-keep class finos.sdk.core.define.EKYCErrorResult { *; }
-keep class finos.sdk.core.define.EKYCErrorResult$* { *; }
# Giữ lại tên của tất cả nested classes
-keepnames class finos.sdk.core.define.EKYCErrorResult$* { *; }
# Giữ lại tất cả members của class và nested classes
-keepclassmembers class finos.sdk.core.define.EKYCErrorResult {
    *;
}
-keepclassmembers class finos.sdk.core.define.EKYCErrorResult$* {
    *;
}

# Camera Helper (public API)
-keep class finos.sdk.ekyc.core.camera.preview.** { *; }
-keep class finos.sdk.ekyc.core.camera.liveness.FaceUtils { *; }

# Activity Classes — declared in AndroidManifest, kept automatically by AGP's
# manifest-component keep rules; explicit rule here for defense-in-depth
-keep class finos.sdk.ekyc.sdkui.EKFinosActivity { *; }

# ============================================
# INTERNAL CLASSES - CHO PHÉP OBFUSCATE
# ============================================

# ViewModel - cho phép obfuscate internal ViewModels
-keep class finos.sdk.liveness.SDKLivenessViewModel { *; }
-keep class finos.sdk.nfc.SDKNfcViewModel { *; }
-keep class finos.sdk.nfc.exception.** { *; }
-keep,allowobfuscation class finos.sdk.ekyc.SDKMainViewModel { *; }
-keep,allowobfuscation class finos.sdk.**.**ViewModel { *; }

# Internal implementation classes - cho phép obfuscate
-keep,allowobfuscation class finos.sdk.core.di.** { *; }
# AppModuleKt cần cho Koin DI
-keep class finos.sdk.core.di.AppModuleKt { *; }
-keep,allowobfuscation class finos.sdk.core.base.** { *; }

# ============================================
# KOIN DI - CẦN GIỮ LẠI
# ============================================
# Koin modules - giữ lại để DI hoạt động
#noinspection ShrinkerUnresolvedReference
-keep class org.koin.dsl.module.ModuleDSLKt { *; }
-keepclassmembers class **Kt {
    public static ** sdkViewModel*;
}

# Koin annotations
-keepattributes RuntimeVisibleAnnotations
-keepclassmembers class * {
    @org.koin.core.annotation.* <methods>;
    @org.koin.core.annotation.* <fields>;
}

# Singleton instances
-keepclassmembers class ** {
    public static ** INSTANCE;
}

# Kotlin coroutines
-keep class kotlinx.coroutines.** { *; }
-keep class kotlin.coroutines.** { *; }
-keepclassmembers class ** {
    suspend *;
}

# Kotlin metadata
-keepattributes RuntimeVisibleAnnotations,RuntimeVisibleParameterAnnotations
-keepclassmembers class ** {
    * lambda*(...);
}

# ============================================
# WARNINGS - BỎ QUA CÁC WARNING KHÔNG CẦN THIẾT
# ============================================
-dontwarn java.lang.management.ManagementFactory
-dontwarn java.lang.management.RuntimeMXBean
-dontwarn java.lang.management.ThreadMXBean
-dontwarn kotlin.uuid.ExperimentalUuidApi
-dontwarn kotlin.uuid.Uuid$Companion
-dontwarn kotlin.uuid.Uuid
-dontwarn java.lang.invoke.StringConcatFactory

# Retrofit/Moshi/Serialization
-keepclassmembers class * {
    @retrofit2.* <methods>;
}
-keep class retrofit2.** { *; }
-keep class com.squareup.moshi.** { *; }
-keep class kotlinx.serialization.** { *; }
-keepclassmembers class * {
    @com.squareup.moshi.* <fields>;
    @kotlinx.serialization.* <fields>;
}
# Scoped to the SDK: these ship as consumerProguardFiles, an unscoped `class *` would keep
# every Companion / $$serializer in the customer's app.
-keepclassmembers class finos.sdk.** {
    *** Companion;
}
-keepclasseswithmembers class finos.sdk.** {
    *** Companion;
}
-keep class finos.sdk.**$$serializer { *; }
-keepclassmembers class finos.sdk.** {
    kotlinx.serialization.KSerializer serializer(...);
}
-keepclassmembers class finos.sdk.** implements kotlinx.serialization.KSerializer {
    <init>(...);
    <fields>;
    <methods>;
}
# If using reflection-based type adapters
#noinspection ShrinkerUnresolvedReference
-keep class com.google.gson.reflect.TypeToken { *; }
-keep class * extends com.google.gson.reflect.TypeToken
# Kotlin coroutines debug probes
-keep class kotlinx.coroutines.debug.* { *; }



# ============================================
# SMS OTP SERVICE - PUBLIC API
# ============================================
# SMS OTP Service - Public API methods
-keepclassmembers class finos.sdk.smsotp.FinOSOtp {
    public static void sendOtp(...);
    public static void verifyOtp(...);
    public static void resendOtp(...);
}

# SMS OTP ViewModel - cho phép obfuscate internal nhưng giữ public methods
-keep,allowobfuscation class finos.sdk.smsotp.SDKSmsOtpServiceViewModel {
    public void sendOtp(...);
    public void verifyOtp(...);
    public void resendOtp(...);
}

# ============================================
# EasyCA SDK - ĐÃ ĐƯỢC OBFUSCATE SẴN TRONG AAR
# ============================================
-keep class vn.softdreams.easyca.sdk.** { *; }
-keep class vn.softdreams.easyca.sdk.R { *; }
-keepclassmembers class vn.softdreams.easyca.sdk.R$* { *; }
-dontwarn vn.softdreams.easyca.sdk.**

# ============================================
# THIRD-PARTY LIBRARIES
# ============================================

# ===== ML Kit Barcode & Face =====
-keep class com.google.mlkit.** { *; }
-keep interface com.google.mlkit.** { *; }
-keep class com.google.firebase.components.ComponentRegistrar
-keep class com.google.mlkit.vision.barcode.BarcodeScanning { *; }
-keep class com.google.mlkit.vision.common.InputImage { *; }
-dontwarn com.google.mlkit.vision.barcode.**
-dontwarn com.google.mlkit.vision.common.**

# ===== CameraX =====
-keep class androidx.camera.** { *; }
-keep interface androidx.camera.** { *; }
-keep class androidx.camera.view.** { *; }

# ===== Lifecycle =====
-keep class androidx.lifecycle.** { *; }
-keep interface androidx.lifecycle.** { *; }

# ===== TensorFlow Lite =====
-keep class org.tensorflow.lite.** { *; }
-dontwarn org.tensorflow.lite.**

# ===== SpongyCastle (com.madgag.spongycastle:prov) =====
-keep class org.spongycastle.** { *; }
-keepnames class org.spongycastle.** { *; }
-dontwarn org.spongycastle.**
-keep class org.spongycastle.jce.provider.BouncyCastleProvider {
    public <init>();
    public static final java.lang.String PROVIDER_NAME;
}
-keep class org.bouncycastle.** { *; }
-dontwarn org.bouncycastle.**

# SPI / JCE
-keep class javax.crypto.Mac { *; }
-keep class javax.crypto.MacSpi { *; }

# ===== JMRTD & Scuba =====
-keep class org.jmrtd.** { *; }
-dontwarn org.jmrtd.**
-keep class net.sf.scuba.** { *; }
-dontwarn net.sf.scuba.**

# EasyCA SDK Rules
-dontwarn com.google.gson.Gson
-dontwarn okhttp3.Interceptor
-dontwarn okhttp3.MediaType
-dontwarn okhttp3.OkHttpClient$Builder
-dontwarn okhttp3.OkHttpClient
-dontwarn retrofit2.Converter$Factory
-dontwarn retrofit2.Retrofit$Builder
-dontwarn retrofit2.Retrofit
-dontwarn retrofit2.converter.gson.GsonConverterFactory

# EasyCA
-keep class vn.softdreams.easyca.sdk.** { *; }

# Retrofit + Gson
-keep class com.google.gson.** { *; }
-keepattributes Signature
-keepattributes *Annotation*

# Kotlin coroutine
-dontwarn kotlinx.coroutines.**
