@file:Suppress("CAST_NEVER_SUCCEEDS")

import java.text.SimpleDateFormat
import java.util.Date

@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed
plugins {
    alias(libs.plugins.androidApplication)
    alias(libs.plugins.kotlinAndroid)
}

android {
    namespace = "com.xhkjedu.manageapp"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.xhkjedu.manageapp"
        minSdk = 24
        targetSdk = 30
        versionCode = 28
        versionName = "1.0.28"

        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary = true
        }
        ndk{
            abiFilters += listOf("armeabi","armeabi-v7a","arm64-v8a","x86","x86_64")
        }
    }
    viewBinding{
        enable=true
    }

    signingConfigs {
        create("keystore") {
            keyAlias = "xinghuo"
            keyPassword = "xhkjedu"
            storeFile = file("xinghuo.keystore")
            storePassword = "xhkjedu"
        }
    }
    buildFeatures {
        compose = true
        buildConfig=true
    }
    buildTypes {
     /*   release {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
        }*/
        val signConfig=signingConfigs.getByName("keystore")
        getByName("release") {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
            signingConfig=signConfig
            buildConfigField("boolean", "IS_DEBUG", "false")
        }
        getByName("debug") {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
            signingConfig=signConfig
            buildConfigField("boolean", "IS_DEBUG", "true")
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }

    composeOptions {
        kotlinCompilerExtensionVersion = "1.4.3"
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
    lint {
        abortOnError=false
    }

    fun releaseTime(): String {
        val dateFormat = SimpleDateFormat("yyyyMMdd")
        return dateFormat.format(Date())
    }

    applicationVariants.all{
        val versionName = this.versionName
        val versionCode = this.versionCode
        val variantName = this.name
        outputs.all {
            if (this is com.android.build.gradle.internal.api.ApkVariantOutputImpl){
                val fileName =  "星火管控桌面-$variantName-$versionName-$versionCode-${releaseTime()}.apk"
                this.outputFileName=fileName
            }
        }
    }
  /*  applicationVariants.all(
        object : Action<com.android.build.gradle.api.ApplicationVariant> {
            override fun execute(variant: com.android.build.gradle.api.ApplicationVariant) {
                println("variant: $variant")
                variant.outputs.all(
                    object : Action<com.android.build.gradle.api.BaseVariantOutput> {
                        override fun execute(
                            output: com.android.build.gradle.api.BaseVariantOutput
                        ) {
                            val versionName = variant.versionName
                            val versionCode = variant.versionCode
                            val variantName = variant.name
                            val outputImpl = output as com.android.build.gradle.internal.api.BaseVariantOutputImpl
                            val fileName =  "Manage_App-$variantName-$versionName-$versionCode-${releaseTime()}.apk"
                            println("output file name: $fileName")
                            outputImpl.outputFileName = fileName
                        }
                    }
                )
            }
        }
    )*/
}

dependencies {

    implementation(libs.core.ktx)
    implementation(libs.lifecycle.runtime.ktx)
    implementation(libs.activity.compose)
    implementation(platform(libs.compose.bom))
    implementation(libs.ui)
    implementation(libs.ui.graphics)
    implementation(libs.ui.tooling.preview)
    implementation(libs.material3)
    implementation(libs.appcompat)
    implementation(libs.androidx.recyclerview)
    implementation(project(mapOf("path" to ":websocket")))
    implementation(libs.androidx.cardview)
    testImplementation(libs.junit)
    implementation("com.baidu.lbsyun:BaiduMapSDK_Location_All:9.3.7")
    implementation("com.tencent.bugly:crashreport:latest.release")
    //第三方cardview
    implementation("org.linwg1988:lcardview:1.5.4")
    androidTestImplementation(libs.androidx.test.ext.junit)
    androidTestImplementation(libs.espresso.core)
    androidTestImplementation(platform(libs.compose.bom))
    androidTestImplementation(libs.ui.test.junit4)
    debugImplementation(libs.ui.tooling)
    debugImplementation(libs.ui.test.manifest)
}