import org.apache.tools.ant.taskdefs.condition.Os

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "36.0.0"
        minSdkVersion = 24
        compileSdkVersion = 36
        targetSdkVersion = 36
        ndkVersion = "27.1.12297006"
        kotlinVersion = "2.1.20"
        // This specifies which LiteRT version to use for our vision-plugin.
        litertVersion = "1.4.0"
    }
    repositories {
        maven { url = uri("https://plugins.gradle.org/m2") }
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:11.6.3")
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin")
        classpath("com.google.gms:google-services:4.4.3")
        classpath("com.google.firebase:perf-plugin:2.0.1")
    }
}

apply plugin: "com.facebook.react.rootproject"

allprojects {
    repositories {
        // Detox Android setup
        maven {
          url("$rootDir/../node_modules/detox/Detox-android")
        }
    }
}

// Force minSdkVersion for libraries that hardcode a lower value than the project's
// (e.g. react-native-mail). This is needed for assembleAndroidTest (used by Detox)
// which builds per-module test APKs that would otherwise fail manifest merging.
subprojects { sub ->
    if (sub.state.executed) {
        if (sub.hasProperty('android') && sub.android.defaultConfig.minSdkVersion != null
            && sub.android.defaultConfig.minSdkVersion.apiLevel < rootProject.ext.minSdkVersion) {
            sub.android.defaultConfig.minSdkVersion rootProject.ext.minSdkVersion
        }
    } else {
        sub.afterEvaluate {
            if (it.hasProperty('android')) {
                if (it.android.defaultConfig.minSdkVersion != null
                    && it.android.defaultConfig.minSdkVersion.apiLevel < rootProject.ext.minSdkVersion) {
                    it.android.defaultConfig.minSdkVersion rootProject.ext.minSdkVersion
                }
            }
        }
    }
}
