plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id "com.google.devtools.ksp" version "1.8.10-1.0.9"
    id 'kotlinx-serialization'
}

apply from:rootProject.file('base.gradle')

android {

    signingConfigs {
        release {
            // 如果需要打release包，请在项目根目录下自行添加此文件
            /**
             *  STORE_FILE=yourAppStroe.keystore
                STORE_PASSWORD=yourStorePwd
                KEY_ALIAS=yourKeyAlias
                KEY_PASSWORD=yourAliasPwd
             */
            def props = new Properties()
            def propFile = new File("signing.properties")
            if (propFile.exists()) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(
                        new FileInputStream(propFile), "utf-8"))
                props.load(reader)

                storeFile file(props['STORE_FILE'])
                storePassword props['STORE_PASSWORD']
                keyAlias props['KEY_ALIAS']
                keyPassword props['KEY_PASSWORD']

                enableV1Signing true
                enableV2Signing true
                enableV3Signing true
            }
        }
    }

    defaultConfig {
        applicationId "com.funny.translation.tmp"
        minSdkVersion Versions.minSdkVersion
        targetSdk Versions.targetSdkVersion
        versionCode Versions.versionCode
        versionName Versions.versionName
        resourceConfigurations += ['zh-rCN', 'en']
        multiDexEnabled true
        ndk.abiFilters 'armeabi-v7a','arm64-v8a','x86_64'

        // KSP Room 配置
        ksp {
            arg('room.schemaLocation', "$projectDir/schemas")
            arg("room.incremental","true")
            arg("room.expandProjection","true")
        }
    }

    productFlavors {
        common {
        }
        google {
            applicationIdSuffix ".google"
            versionNameSuffix "-google"
        }
    }

    applicationVariants.configureEach { variant ->
//        def provider = variant.getPackageApplicationProvider().get()
//        provider.outputDirectory = new File("${rootDir}/output/${variant.flavorName}/")

        variant.outputs.configureEach { output ->
            output.outputFileName = "${variant.name}.apk"
        }

//        variant.assemble.doLast {
//            File out = new File("${rootDir}/output/${variant.buildType.name}/")
//            copy {
//                variant.outputs.forEach { file ->
//                    copy {
//                        from file.outputFile
//                        into out
//                    }
//                }
//            }
//        }
    }

    buildTypes {
        release {
            //临时可调式
//            debuggable true
            //开启代码混淆
            minifyEnabled true
            //Zipalign优化
            zipAlignEnabled true
            //移除无用的resource文件
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            applicationIdSuffix ".debug"
            minifyEnabled false
            signingConfig signingConfigs.release
        }

    }

    buildFeatures {
        compose true
        buildConfig true
    }

    namespace 'com.funny.translation.translate'
}

configurations.configureEach {
    resolutionStrategy {
        force "androidx.appcompat:appcompat:${Versions.appCompatVersion}"
    }
}

dependencies {
    def room_version = Versions.roomVersion
    implementation "androidx.room:room-runtime:$room_version"
    ksp "androidx.room:room-compiler:$room_version"

//    implementation "androidx.work:work-runtime-ktx:2.7.1"

//    implementation 'com.github.FunnySaltyFish:FunnyBottomNavigation:v1.1.1'
    implementation "com.airbnb.android:lottie-compose:4.2.0"
    implementation "com.github.skydoves:cloudy:0.1.2"
//    implementation 'com.github.jeziellago:compose-markdown:0.2.6'

    // 分页加载
    def paging_version = "3.2.0"
    implementation "androidx.paging:paging-compose:$paging_version"
    implementation "androidx.paging:paging-runtime-ktx:$paging_version"

    // CameraX core library using the camera2 implementation
    def camerax_version = "1.3.0-alpha02"
    // If you want to additionally use the CameraX View class
    implementation("androidx.camera:camera-view:${camerax_version}")
    implementation("androidx.camera:camera-camera2:${camerax_version}")
    // If you want to additionally use the CameraX Lifecycle library
    implementation("androidx.camera:camera-lifecycle:${camerax_version}")

    implementation "androidx.documentfile:documentfile:1.0.1"



    implementation 'com.github.princekin-f:EasyFloat:2.0.4'
    implementation 'com.github.thomhurst:RoundImageView:1.0.2'
    implementation "org.burnoutcrew.composereorderable:reorderable:0.7.4"
//    implementation "com.github.leavesCZY:Matisse:0.0.6"

    // 图片选择器
    implementation(platform("cn.qhplus.emo:bom:2023.08.00"))
    implementation "cn.qhplus.emo:photo-coil"
    // 图片裁剪
    implementation 'com.github.yalantis:ucrop:2.2.6'

    implementation("io.github.funnysaltyfish:partial-json-parser:1.0.2")

    // import Kotlin API client BOM
//    implementation platform('com.aallam.openai:openai-client-bom:3.2.5')
//
//    // define dependencies without versions
//    implementation 'com.aallam.openai:openai-client'
//    runtimeOnly 'io.ktor:ktor-client-okhttp'

    // To recognize Latin script
//    implementation 'com.google.mlkit:text-recognition:16.0.0-beta6'

    // Google Ad
//    implementation 'com.google.android.gms:play-services-ads:21.1.0'

    // 应用更新
    commonImplementation ('com.github.azhon:AppUpdate:3.0.6')

    implementation project(path: ":base-core")
    implementation project(path: ":codeeditor")
    implementation project(path: ":login")
    implementation project(path: ':jet-setting-core')
    implementation project(path: ":ai")
    // v2.6.0起不用了，但是它的效果还挺有趣的
    // 可以见 https://github.com/FunnySaltyFish/FunnyBottomNavigation
    // implementation project(path: ":bottom-navigation")

    testImplementation 'junit:junit:4.13.2'
    testImplementation 'org.json:json:20180813'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

afterEvaluate {
    // debug 和 release 时执行加密代码
    var signApkTask = project(":base-core").tasks.named("signApk")
    tasks.findAll {
        it.name.startsWith("assemble") && !it.name.endsWith("Test")
    }.forEach { task ->
//        println("find task name: " + task.name)
        // 打包前先加密下 Js
        task.dependsOn(":base-core:encryptFunnyJs")
        // 结束后签个名
        task.finalizedBy(signApkTask)
    }
}


