plugins {
    alias(libs.plugins.androidLibrary)
    alias(libs.plugins.kotlinAndroid)
}


val appConfig = findProperty("app") as Map<*, *>
val adMobConfig = findProperty("admob") as Map<*, *>
val adMobUnitConfig = adMobConfig["adUnitIds"] as Map<*, *>
val pangleConfig = findProperty("pangle") as? Map<*, *>
val pangleUnitConfig = pangleConfig?.get("adUnitIds") as? Map<*, *>
val toponConfig = findProperty("topon") as? Map<*, *>
val toponUnitConfig = toponConfig?.get("adUnitIds") as? Map<*, *>

android {
    namespace = "com.remax.bill"
    compileSdk = appConfig["compileSdk"] as Int

    defaultConfig {
        minSdk = appConfig["minSdk"] as Int
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

        manifestPlaceholders["ADMOB_APPLICATION_ID"] = adMobConfig["applicationId"] as String
        buildConfigField("String", "ADMOB_SPLASH_ID", "\"${adMobUnitConfig["splash"]}\"")
        buildConfigField("String", "ADMOB_BANNER_ID", "\"${adMobUnitConfig["banner"]}\"")
        buildConfigField("String", "ADMOB_INTERSTITIAL_ID", "\"${adMobUnitConfig["interstitial"]}\"")
        buildConfigField("String", "ADMOB_NATIVE_ID", "\"${adMobUnitConfig["native"]}\"")
        buildConfigField("String", "ADMOB_FULL_NATIVE_ID", "\"${adMobUnitConfig["full_native"]}\"")
        buildConfigField("String", "ADMOB_REWARDED_ID", "\"${adMobUnitConfig["rewarded"]}\"")

        // Pangle配置
        buildConfigField("String", "PANGLE_APPLICATION_ID", "\"${pangleConfig!!["applicationId"]}\"")
        buildConfigField("String", "PANGLE_SPLASH_ID", "\"${pangleUnitConfig!!["splash"] ?: ""}\"")
        buildConfigField("String", "PANGLE_SPLASH_LANDSCAPE_ID", "\"${pangleUnitConfig["splash_landscape"] ?: ""}\"")
        buildConfigField("String", "PANGLE_BANNER_ID", "\"${pangleUnitConfig["banner"] ?: ""}\"")
        buildConfigField("String", "PANGLE_INTERSTITIAL_ID", "\"${pangleUnitConfig["interstitial"] ?: ""}\"")
        buildConfigField("String", "PANGLE_NATIVE_ID", "\"${pangleUnitConfig["native"] ?: ""}\"")
        buildConfigField("String", "PANGLE_FULL_NATIVE_ID", "\"${pangleUnitConfig["full_native"] ?: ""}\"")
        buildConfigField("String", "PANGLE_REWARDED_ID", "\"${pangleUnitConfig["rewarded"] ?: ""}\"")

        // TopOn配置
        val toponAppId = (toponConfig?.get("applicationId") as? String).orEmpty()
        val toponAppKey = (toponConfig?.get("appKey") as? String).orEmpty()
        val toponInterstitialId = (toponUnitConfig?.get("interstitial") as? String).orEmpty()
        val toponRewardedId = (toponUnitConfig?.get("rewarded") as? String).orEmpty()
        val toponNativeId = (toponUnitConfig?.get("native") as? String).orEmpty()
        val toponSplashId = (toponUnitConfig?.get("splash") as? String).orEmpty()
        val toponFullNativeId = (toponUnitConfig?.get("full_native") as? String).orEmpty()
        val toponBannerId = (toponUnitConfig?.get("banner") as? String).orEmpty()
        buildConfigField("String", "TOPON_APPLICATION_ID", "\"$toponAppId\"")
        buildConfigField("String", "TOPON_APP_KEY", "\"$toponAppKey\"")
        buildConfigField("String", "TOPON_INTERSTITIAL_ID", "\"$toponInterstitialId\"")
        buildConfigField("String", "TOPON_REWARDED_ID", "\"$toponRewardedId\"")
        buildConfigField("String", "TOPON_NATIVE_ID", "\"$toponNativeId\"")
        buildConfigField("String", "TOPON_SPLASH_ID", "\"$toponSplashId\"")
        buildConfigField("String", "TOPON_FULL_NATIVE_ID", "\"$toponFullNativeId\"")
        buildConfigField("String", "TOPON_BANNER_ID", "\"$toponBannerId\"")
    }

    buildTypes {
        debug {
            isMinifyEnabled = false
            isZipAlignEnabled = true
        }

        release {
            isMinifyEnabled = false
            isZipAlignEnabled = true
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = "11"
    }
    buildFeatures {
        viewBinding = true
        buildConfig = true
    }
}


dependencies {
    api(libs.kotlinx.coroutines.core)
    api(libs.kotlinx.coroutines.android)
    api(libs.androidx.lifecycle.runtime.ktx)
    //implementation(libs.gson)
    implementation(libs.utilcodex)
    implementation(libs.androidx.core.ktx)
    implementation(libs.appcompat)
    implementation(libs.material)
    implementation(libs.lottie)
    testImplementation(libs.junit)
    androidTestImplementation(libs.junit)
    androidTestImplementation(libs.espresso.core)
    implementation(project(":base"))

    // Admob SDK
    api(libs.play.services.ads)
    api("com.google.android.gms:play-services-ads-identifier:18.2.0")
    // Topon 三方适配器
    api("androidx.appcompat:appcompat:1.6.1")
    api("androidx.browser:browser:1.4.0")

    // Pangle 聚合SDK
    api ("com.pangle.global:pag-sdk-m:7.5.6.2")
    // Pangle 三方适配器
    // Admob
    api ("com.pangle.global:admob-adapter:24.4.0.5")
     // Mintegral
     api ("com.pangle.global:mintegral-adapter:16.9.91.1")
     // Google Ad Manager
     api ("com.pangle.global:google-ad-manager-adapter:24.5.0.3")

     // Topon 聚合SDK
     api("com.thinkup.sdk:core-tpn:6.5.16")
     api("com.thinkup.sdk:interstitial-tpn:6.5.16")
     api("com.thinkup.sdk:rewardedvideo-tpn:6.5.16")
     api("com.thinkup.sdk:nativead-tpn:6.5.16")
     api("com.thinkup.sdk:banner-tpn:6.5.16")
     api("com.thinkup.sdk:splash-tpn:6.5.16")

     // Vungle
     api("com.thinkup.sdk:adapter-tpn-vungle:6.5.16")
     api("com.vungle:vungle-ads:7.5.0")
     api("com.google.android.gms:play-services-basement:18.1.0")
     api("com.google.android.gms:play-services-ads-identifier:18.0.1")
     // Bigo
     api("com.thinkup.sdk:adapter-tpn-bigo:6.5.16.1")
     api("com.bigossp:bigo-ads:5.5.1")
     // Pangle
     api("com.thinkup.sdk:adapter-tpn-pangle:6.5.16.2")
     api("com.google.android.gms:play-services-ads-identifier:18.2.0")
     // Facebook
     api("com.thinkup.sdk:adapter-tpn-facebook:6.5.16")
     api("com.facebook.android:audience-network-sdk:6.20.0")
     api("androidx.annotation:annotation:1.0.0")
     // Admob
     api("com.thinkup.sdk:adapter-tpn-admob:6.5.16")
     api("com.google.android.gms:play-services-ads:24.4.0")
     // Mintegral
     api("com.thinkup.sdk:adapter-tpn-mintegral:6.5.16.1")
     api("com.mbridge.msdk.oversea:mbridge_android_sdk:16.9.91")
     api("androidx.recyclerview:recyclerview:1.1.0")
     // Tramini
     api("com.thinkup.sdk:tramini-plugin-tpn:6.5.16")
}