plugins {
    id 'com.android.application'
    id 'dagger.hilt.android.plugin'
    id 'stringfog'
    id 'com.google.firebase.crashlytics'
    id 'com.google.gms.google-services'
}

def LOCAL = "local", TEST = "test", PROD = "prod"

def getServerHost(String env) {
    switch (env) {
        case "local":
            return "$local_server_host";
        case "test":
            return "$test_server_host";
        case "prod":
            return "$prod_server_host";
        default:
            return "$prod_server_host";
    }
}

android {
    namespace 'com.atmob.voiceai'
    compileSdk rootProject.compileSdkVersion

    defaultConfig {
        applicationId rootProject.applicationId
        minSdk rootProject.minSdkVersion
        targetSdk rootProject.targetSdkVersion
        versionCode rootProject.versionCode
        versionName rootProject.versionName

        ndk {
            //noinspection ChromeOsAbiSupport
            abiFilters "arm64-v8a"
        }
    }

    signingConfigs {
        debug {
            storeFile file("keystore/voiceAI.jks")
            storePassword "voice888"
            keyAlias "voice"
            keyPassword "voice888"
        }
        release {
            storeFile file("keystore/voiceAI.jks")
            storePassword "voice888"
            keyAlias "voice"
            keyPassword "voice888"
        }
    }


    def env_release = PROD
    def env_debug = PROD

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release

            buildConfigField "String", "ENV", "\"$env_release\""
            buildConfigField "String", "HOST", "\"${getServerHost(env_release)}\""
            buildConfigField "String", "LOCAL", "\"$LOCAL\""
            buildConfigField "String", "TEST", "\"$TEST\""
            buildConfigField "String", "PROD", "\"$PROD\""
            buildConfigField "String", "KOCHAVA", "\"$kochava_guid\""
        }

        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.debug

            buildConfigField "String", "ENV", "\"$env_debug\""
            buildConfigField "String", "HOST", "\"${getServerHost(env_debug)}\""
            buildConfigField "String", "LOCAL", "\"$LOCAL\""
            buildConfigField "String", "TEST", "\"$TEST\""
            buildConfigField "String", "PROD", "\"$PROD\""
            buildConfigField "String", "KOCHAVA", "\"$kochava_guid\""
        }


    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    buildFeatures {
        viewBinding true
        dataBinding true
    }


    applicationVariants.configureEach { variant ->
        def date = new Date().format("YYMMddHHmmss")
        def server = variant.buildType.name == "release" ? env_release : env_debug
        variant.outputs.configureEach {
            def fileName = "${defaultConfig.applicationId}" +
                    "-v${defaultConfig.versionName}" +
                    "-${variant.buildType.name}" +
                    "-${server}" +
                    "-${date}" +
                    ".apk"
            outputFileName = fileName
        }
    }

    sourceSets {
        main { jniLibs.srcDirs = ['libs'] }
    }

    configurations.configureEach {
        resolutionStrategy {
            // don't cache changing modules at all
            cacheChangingModulesFor 10, 'seconds'
        }
    }
}

import com.github.megatronking.stringfog.plugin.kg.RandomKeyGenerator

stringfog {
    implementation 'com.github.megatronking.stringfog.xor.StringFogImpl'
    fogPackages = ['com.atmob.voiceai']
    debug false
    enable true
    kg new RandomKeyGenerator()
    mode base64
}

dependencies {
    //jar or aar
    implementation fileTree(include: ['*.jar', '*.aar'], dir: 'libs')

    //Atmob SDK
    implementation 'extra.common:base:1.0.0-SNAPSHOT'
    implementation "extra.pack:channel:1.1.0-SNAPSHOT"
    implementation "extra.common:core:2.0.3-SNAPSHOT" //base utils
    implementation "extra.common:network:1.1.0-SNAPSHOT"
    implementation "extra.common:rxjava:1.1.0-SNAPSHOT"
    implementation "extra.common:user:1.0.1-SNAPSHOT" //get user data(includes device info)
    implementation("plus.pay:pay:1.1.0-SNAPSHOT") {
        exclude group: 'third.pay', module: 'ali'
    }
    api 'com.alipay.sdk:alipaysdk-android:15.8.16@aar'

    //AppCompat
    implementation "androidx.appcompat:appcompat:$rootProject.appcompat_version"

    //Material
    implementation "com.google.android.material:material:$rootProject.material_version"

    //RecyclerView
    implementation "androidx.recyclerview:recyclerview:$rootProject.recyclerview_version"

    //ConstraintLayout
    implementation "androidx.constraintlayout:constraintlayout:$rootProject.constraintlayout_version"

    //Gson
    implementation "com.google.code.gson:gson:$rootProject.gson_version"

    //Lifecycle
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-livedata:$rootProject.lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-reactivestreams:$rootProject.lifecycle_version"
    implementation "androidx.lifecycle:lifecycle-process:$rootProject.lifecycle_version"

    //Hilt
    implementation "com.google.dagger:hilt-android:$rootProject.hilt_version"
    annotationProcessor "com.google.dagger:hilt-compiler:$rootProject.hilt_version"

    //Glide
    implementation "com.github.bumptech.glide:glide:$rootProject.glide_version"
    annotationProcessor "com.github.bumptech.glide:compiler:$rootProject.glide_version"

    //MMKV
    implementation "com.tencent:mmkv:$rootProject.mmkv_version"

    //immersionbar
    implementation "com.gyf.immersionbar:immersionbar:$rootProject.immersionbar_version"
    implementation "com.gyf.immersionbar:immersionbar-components:$rootProject.immersionbar_version"

    //字符串加密算法
    implementation "com.github.megatronking.stringfog:xor:$rootProject.stringfog_version"

    //音频播放
    implementation "androidx.media3:media3-exoplayer:$rootProject.media3_version"

    //VapPlayer 动效
    implementation "io.github.tencent:vap:2.0.28"

    //lottie
    implementation "com.airbnb.android:lottie:$rootProject.lottie_version"

    //google结算库
    implementation "com.android.billingclient:billing:$rootProject.billing_version"

    //设备检查
    implementation "extra.common:checker:1.2.1-SNAPSHOT"

    //Kochava
    dependencies {
        def kochava_tracker_version = "4.3.0"
        implementation("com.kochava.tracker:tracker:$kochava_tracker_version") // Required
        implementation("com.kochava.tracker:events:$kochava_tracker_version") // Optional
        implementation("com.kochava.tracker:engagement:$kochava_tracker_version") // Optional
        implementation("com.kochava.tracker:datapointnetwork:$kochava_tracker_version") // Optional
        implementation("com.kochava.tracker:legacyreferrer:$kochava_tracker_version") // Optional
    }

    //firebase
    implementation platform('com.google.firebase:firebase-bom:30.4.1')
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-messaging'
}