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

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    def taskRequests = getGradle().getStartParameter().getTaskRequests().toString().toLowerCase()
    def isPlay = !taskRequests.contains("foss")

    ext {
        buildToolsVersion = "31.0.0"
        minSdkVersion = 23
        compileSdkVersion = 31
        targetSdkVersion = 31
        if (System.properties['os.arch'] == "aarch64") {
            // For M1 Users we need to use the NDK 24 which added support for aarch64
            ndkVersion = "24.0.8215888"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }
        glideVersion = "4.11.0"
        kotlin_version = "1.6.10"
        kotlinVersion = '1.6.10'
        supportLibVersion = "28.0.0"
        libre_build = !(isPlay.toBoolean())
        jitsi_url = "https://github.com/RocketChat/jitsi-maven-repository/raw/master/releases"
        jitsi_version = "3.7.0"
    }

    repositories {
        mavenLocal()
        google()
        maven {
            url 'https://maven.fabric.io/public'
        }
        mavenCentral()
    }

    dependencies {
        if (isPlay) {
            classpath 'com.google.gms:google-services:4.3.8'
            classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.0'
            classpath 'com.bugsnag:bugsnag-android-gradle-plugin:7.+'
        }
        classpath("com.android.tools.build:gradle:7.0.4")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("de.undercouch:gradle-download-task:4.1.2")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        maven {
            url "$rootDir/../node_modules/detox/Detox-android"
        }

        maven {
            url jitsi_url
        }
        mavenCentral {
            content {
                excludeGroup "com.facebook.react"
            }
        }

        google()
        maven { url 'https://maven.google.com' }
        maven { url 'https://www.jitpack.io' }
    }
}