// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext {
        buildToolsVersion = "35.0.0"
        minSdkVersion = 24
        compileSdkVersion = 35
        targetSdkVersion = 35
        ndkVersion = "27.1.12297006"

        androidXCore = "1.0.2"
        multiDexEnabled = true
        googlePlayServicesVersion = "17.0.0"
        kotlinVersion = "2.0.21"

        // This property configures the type of Mapbox SDK used by the @rnmapbox/maps library.
        // "mapbox" indicates the usage of the Mapbox SDK.
        RNMapboxMapsImpl = "mapbox"
        reactNativeIncludedBuild = gradle.getIncludedBuilds().find { it.name == 'react-native' }
        // This is our custom extension that we defined in gradleUtils/PatchedArtifactsSettings.gradle
        // It enables us to use custom artifacts of patched react-native
        patchedArtifactsConfig = project.gradle.settings.extensions.findByName('patchedArtifacts')
    }
    repositories {
        google()
        mavenCentral()
        maven {url "https://maven.fullstory.com"}
    }
    dependencies {
        classpath("com.android.tools.build:gradle")
        classpath("com.facebook.react:react-native-gradle-plugin")
        classpath("com.google.gms:google-services:4.3.4")
        classpath("com.google.firebase:firebase-crashlytics-gradle:2.7.1")
        classpath("com.google.firebase:perf-plugin:1.4.1")
        // Fullstory integration
        classpath ("com.fullstory:gradle-plugin-local:1.64.2")

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
    }
}


allprojects {
    configurations.all {
        resolutionStrategy {
            force 'org.xerial:sqlite-jdbc:3.34.0'

            eachDependency { dependency ->
                if (dependency.requested.group == 'org.bouncycastle') {
                    println dependency.requested.module
                    dependency.useTarget 'org.bouncycastle:bcprov-jdk15to18:1.71'
                }
            }
        }
    }
    repositories {
        if (!patchedArtifactsConfig.buildFromSource) {
            maven {
                url "https://maven.pkg.github.com/Expensify/App"
                
                credentials {
                    username = patchedArtifactsConfig.githubUsername
                    password = patchedArtifactsConfig.githubToken
                }
            } 
        }
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            // Mapbox SDK requires authentication to download from Mapbox's private Maven repository.
            url 'https://api.mapbox.com/downloads/v2/releases/maven'
            authentication {
                basic(BasicAuthentication)
            }
            credentials {
                // 'mapbox' is the fixed username for Mapbox's Maven repository.
                username = 'mapbox'

                // The value for password is read from the 'MAPBOX_DOWNLOADS_TOKEN' gradle property.
                // Run "npm run setup-mapbox-sdk" to set this property in «USER_HOME»/.gradle/gradle.properties

                // Example gradle.properties entry:
                // MAPBOX_DOWNLOADS_TOKEN=YOUR_SECRET_TOKEN_HERE
                password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
            }
        }
    }
}

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

task buildReactNativeArtifacts {
    if (reactNativeIncludedBuild != null) {
        dependsOn(reactNativeIncludedBuild.task(':packages:react-native:ReactAndroid:build'))
    }
}

task publishReactNativeArtifacts {
    if(reactNativeIncludedBuild != null) {
        dependsOn(reactNativeIncludedBuild.task(':packages:react-native:ReactAndroid:publishReleasePublicationToMavenRepository'))
    }
}
