import groovy.xml.XmlParser
import java.text.SimpleDateFormat
import java.util.Date


plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.jetbrains.kotlin.android)
    id("com.google.gms.google-services")
    id("com.google.firebase.crashlytics")
}
// 生成时间戳（格式 MMddHHmm）
val timestamp: String = SimpleDateFormat("MMddHHmm").format(Date())

fun getAppNameFromStringsFile(): String {
    val stringsFile = file("src/main/res/values/strings.xml")
    if (!stringsFile.exists()) {
        return "UnknownApp"
    }

    val xmlParser = XmlParser()
    val rootNode = xmlParser.parse(stringsFile)

    return rootNode.children()
        .filterIsInstance<groovy.util.Node>()
        .find { it.attribute("name") == "app_name" }
        ?.text() ?: "UnknownApp"
}
android {
    namespace = "com.gogame.minesweeper"
    compileSdk = 36

    defaultConfig {
        applicationId = "com.gogame.minesweeper"
        minSdk = 24
        targetSdk = 36
        versionCode = 3
        versionName = "1.0.3"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

        setProperty("archivesBaseName", "${getAppNameFromStringsFile()}-$versionName($versionCode)-${timestamp}")
    }

    buildTypes {
        release {
            isMinifyEnabled = true
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = "11"
    }
    buildFeatures {
        viewBinding = true
    }
}

dependencies {
    implementation(files("libs/UpLoadLibrary_12_03_15_13-release.aar"))
    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.appcompat)
    implementation(libs.material)
    implementation(libs.androidx.constraintlayout)
    implementation(libs.androidx.navigation.fragment.ktx)
    implementation(libs.androidx.navigation.ui.ktx)
    testImplementation(libs.junit)
    androidTestImplementation(libs.androidx.junit)
    androidTestImplementation(libs.androidx.espresso.core)
    implementation(libs.gson)
    implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
    // Import the Firebase BoM
    implementation(platform("com.google.firebase:firebase-bom:34.6.0"))
    implementation("com.google.firebase:firebase-crashlytics-ndk")
    implementation("com.google.firebase:firebase-analytics")
    // google ads
    implementation ("com.google.android.gms:play-services-ads-identifier:18.0.1")
    // okhttp
    implementation ("com.squareup.okhttp3:okhttp:4.12.0")
    implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")

    //TU (Necessary)
    api("com.thinkup.sdk:core-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:interstitial-tpn:6.5.16")
    api("com.thinkup.sdk:rewardedvideo-tpn:6.5.16")
    api("com.thinkup.sdk:splash-tpn:6.5.16")
//Androidx (Necessary)
    api("androidx.appcompat:appcompat:1.6.1")
    api("androidx.browser:browser:1.4.0")
//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")
//UnityAds
    api("com.thinkup.sdk:adapter-tpn-unityads:6.5.16")
    api("com.unity3d.ads:unity-ads:4.14.0")
//Ironsource
    api("com.thinkup.sdk:adapter-tpn-ironsource:6.5.16")
    api("com.ironsource.sdk:mediationsdk:8.7.0")
    api("com.google.android.gms:play-services-appset:16.0.2")
    api("com.google.android.gms:play-services-ads-identifier:18.0.1")
    api("com.google.android.gms:play-services-basement:18.1.0")
//Bigo
    api("com.thinkup.sdk:adapter-tpn-bigo:6.5.16.1")
    api("com.bigossp:bigo-ads:5.5.1")
//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")
//Pangle
    api("com.thinkup.sdk:adapter-tpn-pangle:6.5.16.2")
    api("com.pangle.global:pag-sdk:7.6.0.2")
    api("com.google.android.gms:play-services-ads-identifier:18.0.1")
}