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


buildscript {
    ext {
        kotlin_version = '1.8.22'
    }
    ext.safeExtGet = {prop, fallback ->
        rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
    }
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:8.1.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
    }
}

def isNewArchitectureEnabled() {
    // To opt-in for the New Architecture, you can either:
    // - Set `newArchEnabled` to true inside the `gradle.properties` file
    // - Invoke gradle with `-newArchEnabled=true`
    // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true`
    return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

if (isNewArchitectureEnabled()) {
    apply plugin: "com.facebook.react"
}

apply plugin: 'com.android.library'
apply plugin: "kotlin-android"

android {

    // Used to override the NDK path/version on internal CI or by allowing
    // users to customize the NDK path/version from their root project (e.g. for M1 support)
    if (rootProject.hasProperty("ndkPath")) {
        ndkPath rootProject.ext.ndkPath
    }
    if (rootProject.hasProperty("ndkVersion")) {
        ndkVersion rootProject.ext.ndkVersion
    }

    def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
    if (agpVersion >= 7) {
      namespace 'com.plaid'
    }
    compileSdkVersion 34

    defaultConfig {
        minSdkVersion rootProject.ext.has("minSdkVersion") ? rootProject.ext.minSdkVersion :  21
        targetSdkVersion 34
        versionCode 1
        versionName "0.0.1"
        buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
    }
    lintOptions {
        abortOnError false
    }

    if (agpVersion < 8) { 
      compileOptions {
          sourceCompatibility JavaVersion.VERSION_1_8
          targetCompatibility JavaVersion.VERSION_1_8
      }
    }

    sourceSets.main {
        java {
            if (!isNewArchitectureEnabled()) {
                    srcDirs += 'src/paper/java'
                }
            }
    }

    buildTypes {
        release {
            debuggable = false
        }
        debug {
            debuggable = true
        }
    }
}

repositories {
    google()
    mavenCentral()
    maven { url "$rootDir/../node_modules/react-native/android" }
}

dependencies {
    implementation "com.facebook.react:react-native:+"
    implementation "com.plaid.link:sdk-core:5.1.1"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
}
