plugins {
    id 'com.android.application'

    id 'com.google.devtools.ksp'
    id 'com.google.dagger.hilt.android'
    id 'com.google.firebase.crashlytics'
    id 'com.google.firebase.firebase-perf'

    id 'kotlin-android'
}

android {
    compileSdk 36

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    defaultConfig {
        applicationId "com.toolsboox"
        minSdkVersion 26
        targetSdkVersion 36

        versionCode parentVersionCode
        versionName parentVersionName

        multiDexEnabled = true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }

    applicationVariants.configureEach {
        variant ->
            variant.outputs.each {
                output ->
                    output.outputFileName = "${applicationName}-${variant.flavorName}-${variant.buildType.name}-${defaultConfig.versionName}.apk"
            }
    }


    buildFeatures {
        viewBinding = true
        buildConfig = true
    }

    ext {
        appName = 'toolboox'
    }

    flavorDimensions = ['tier']
    productFlavors {
        dev {
            resValue "string", "app_name", "Tools for Boox - Dev"
            applicationIdSuffix ""
            dimension 'tier'
        }
        prod {
            resValue "string", "app_name", "Tools for Boox"
            applicationIdSuffix ""
            dimension 'tier'
        }
    }

    signingConfigs {
        release {
            storeFile file("../keystore.jks")
            if (project.hasProperty('toolBooxStorePassword')) {
                storePassword project.property('toolBooxStorePassword').toString()
            } else {
                storePassword System.getenv("KEYSTORE_PASSWORD")
            }
            keyAlias "key0"
            if (project.hasProperty('toolBooxKeyPassword')) {
                keyPassword project.property('toolBooxKeyPassword').toString()
            } else {
                keyPassword System.getenv("KEY_PASSWORD")
            }
        }
    }

    buildTypes {
        debug {
            minifyEnabled false
            shrinkResources false
            debuggable true

            applicationIdSuffix ".debug"
            resValue "string", "app_name", "Tools for Boox (debug)"

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

            resValue("string", "ad_unit_id_dashboard", "ca-app-pub-3940256099942544/6300978111")
        }
        release {
            minifyEnabled false
            shrinkResources false
            debuggable false

            signingConfig signingConfigs.release

            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            proguardFiles fileTree('proguard').asList().toArray()

            resValue("string", "ad_unit_id_dashboard", "ca-app-pub-2136545277716623/7789111670")
        }
    }


    packagingOptions {
        jniLibs {
            pickFirsts += [
                    'lib/arm64-v8a/libc++_shared.so',
                    'lib/armeabi-v7a/libc++_shared.so',
                    'lib/x86/libc++_shared.so',
                    'lib/x86_64/libc++_shared.so']
        }
        resources {
            excludes += ['META-INF/DEPENDENCIES', 'META-INF/INDEX.LIST']
        }
    }

    namespace 'com.toolsboox'
    lint {
        disable 'MissingTranslation', 'MissingQuantity', 'GestureBackNavigation'
    }
}

dependencies {
    // Commons
    implementation 'com.jakewharton.timber:timber:5.0.1'

    // Google clients and libraries
    implementation 'com.android.billingclient:billing:8.0.0'
    implementation 'com.android.billingclient:billing-ktx:8.0.0'
    implementation 'com.google.android.gms:play-services-ads:24.6.0'
    implementation 'com.google.android.gms:play-services-auth:21.4.0'
    implementation 'com.google.android.play:review:2.0.2'
    implementation 'com.google.android.play:review-ktx:2.0.2'
    implementation 'com.google.api-client:google-api-client-android:2.8.1'
    implementation 'com.google.apis:google-api-services-drive:v3-rev20250829-2.0.0'
    implementation 'com.google.mlkit:digital-ink-recognition:19.0.0'

    // AndroidX dependencies
    implementation "androidx.activity:activity-ktx:1.11.0"
    implementation 'androidx.gridlayout:gridlayout:1.1.0'
    implementation 'androidx.navigation:navigation-fragment-ktx:2.9.4'
    implementation 'androidx.navigation:navigation-ui-ktx:2.9.4'
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

    // Dagger and Hilt DI and its dependency
    ksp 'com.google.dagger:hilt-android-compiler:2.57.1'
    implementation 'com.google.dagger:hilt-android:2.57.1'

    // Onyx SDK
    implementation 'com.onyx.android.sdk:onyxsdk-base:1.8.2.1'
    implementation 'com.onyx.android.sdk:onyxsdk-device:1.3.1.3'
    implementation ('com.onyx.android.sdk:onyxsdk-pen:1.5.0.4') {
        exclude group: "com.onyx.android.sdk", module: "onyxsdk-geometry"
    }

    // OkHttp, Retrofit and GSON
    ksp 'com.squareup.moshi:moshi-kotlin-codegen:1.15.2'
    implementation 'com.squareup.moshi:moshi:1.15.2'
    implementation 'com.squareup.retrofit2:converter-gson:3.0.0'
    implementation 'com.squareup.retrofit2:converter-scalars:3.0.0'
    // Deprecated, use suspend functions
    implementation 'com.jakewharton.retrofit:retrofit2-kotlin-coroutines-adapter:0.9.2'

    // Firebase integrations
    implementation platform('com.google.firebase:firebase-bom:34.2.0')
    implementation 'com.google.firebase:firebase-analytics'
    implementation 'com.google.firebase:firebase-crashlytics'
    implementation 'com.google.firebase:firebase-perf'

    // Test dependencies
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:core:1.7.0'
    androidTestImplementation 'androidx.test.ext:junit:1.3.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.7.0'

    // Temporary (?) fix for https://github.com/gaborauth/toolsboox-android/issues/305
    implementation 'org.lsposed.hiddenapibypass:hiddenapibypass:6.1'
}

apply plugin: 'com.google.gms.google-services'
