buildscript {
  // Buildscript is evaluated before everything else so we can't use safeExtGet
  def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : "1.8.0"

  repositories {
    maven {
      url "https://plugins.gradle.org/m2/"
    }
    mavenCentral()
    google()
  }

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

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

def isNewArchitectureEnabled() {
  return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true"
}

if (isNewArchitectureEnabled()) {
  apply plugin: "com.facebook.react"
}
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

repositories {
  google()
  mavenCentral()
}

android {
  // Conditional for compatibility with AGP <4.2.
  if (project.android.hasProperty("namespace")) {
    namespace = "com.dorianmazur.keychain"
  }
  compileSdkVersion safeExtGet('compileSdkVersion', 33)
  buildToolsVersion safeExtGet('buildToolsVersion', '33.0.0')

  defaultConfig {
    minSdkVersion safeExtGet('minSdkVersion', 23)
    compileSdkVersion safeExtGet('compileSdkVersion', 33)
    targetSdkVersion safeExtGet('targetSdkVersion', 33)
    buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  buildFeatures {
    buildConfig true
  }

  lintOptions {
    disable "GradleCompatible"
    abortOnError false
  }

  testOptions {
    unitTests {
      includeAndroidResources = true
    }
  }
}

repositories {
  mavenCentral()
}

def kotlin_version = safeExtGet('kotlinVersion', '1.8.0')

dependencies {
  //noinspection GradleDynamicVersion
  implementation "com.facebook.react:react-android:+"

  implementation 'androidx.appcompat:appcompat:1.6.1'
  implementation 'androidx.legacy:legacy-support-v4:1.0.0'

  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

  // Used to store encrypted data
  implementation("androidx.datastore:datastore-preferences:1.0.0")

  // https://mvnrepository.com/artifact/androidx.biometric/biometric
  implementation 'androidx.biometric:biometric:1.1.0@aar'

  // https://mvnrepository.com/artifact/androidx.lifecycle/lifecycle-viewmodel
  // Needed for BiometricPrompt in androidx.biometric
  implementation "androidx.lifecycle:lifecycle-viewmodel:2.3.1@aar"

  // https://mvnrepository.com/artifact/androidx.fragment/fragment
  // Needed for BiometricPrompt in androidx.biometric
  implementation "androidx.fragment:fragment:1.3.2@aar"

  /* version higher 1.1.3 has problems with included soloader packages,
      https://github.com/facebook/conceal/releases */
  implementation "com.facebook.conceal:conceal:1.1.3@aar"
}

if (isNewArchitectureEnabled()) {
  react {
    jsRootDir = file("../src/")
    libraryName = "RNKeychainManager"
    codegenJavaPackageName = "com.dorianmazur.keychain"
  }
}

