@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 = 1
        versionName = "1.0"

        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"
        }
    }

    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
        }
        getByName("debug") {
            isMinifyEnabled = false
            proguardFiles(
                getDefaultProguardFile("proguard-android-optimize.txt"),
                "proguard-rules.pro"
            )
            signingConfig=signConfig
        }
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    buildFeatures {
        compose = true
    }
    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())
    }

    android.applicationVariants.all {variant->
       variant.outputs.all {output->
           val versionName = variant.versionName
           val versionCode = variant.versionCode
           val variantName = variant.name
           val apkName = "Manage_App-$variantName-$versionName-$versionCode-${releaseTime()}.apk"
           output.outputFile.renameTo(File(output.outputFile.parentFile,apkName))
       }
    }
}

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")
    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)
}