buildscript {
  repositories {
    flatDir{
      dirs 'libs'
    }
    google()
    mavenCentral()
  }

  dependencies {
    classpath "com.android.tools.build:gradle:7.2.1"
    classpath 'com.google.gms:google-services:4.3.14'
    
  }
}

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

apply plugin: "com.android.library"

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

def getExtOrDefault(name) {
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties["WebengagePersonalization_" + name]
}

def getExtOrIntegerDefault(name) {
  return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["WebengagePersonalization_" + name]).toInteger()
}

android {
  compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
  namespace "com.webengage.we_notificationinbox_rn"
  defaultConfig {
    minSdkVersion getExtOrIntegerDefault("minSdkVersion")
    targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
    manifestPlaceholders = [we_rn_ni_version: readVersion()]
    buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
  }
  buildTypes {
    release {
      minifyEnabled false
    }
  }

  lintOptions {
    disable "GradleCompatible"
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

}

repositories {
  mavenCentral()
  google()
}

String readVersion() {
    def version = new Properties()
    def stream
    try {
        stream = new FileInputStream(new File(projectDir, 'version.properties'))
        version.load(stream)
    } catch (FileNotFoundException ignore) {
    } finally {
        if (stream != null) stream.close()
    }
    // safety defaults in case file is missing
    if(!version['major']) version['major'] = "1"
    if(!version['minor']) version['minor'] = "0"
    if(!version['patch']) version['patch'] = "0"
    return "${version['major']}.${version['minor']}.${version['patch']}"
}

dependencies {
  implementation 'com.facebook.react:react-native:+'
  implementation 'androidx.cardview:cardview:1.0.0'
  implementation 'androidx.core:core:1.3.2'

  api 'com.webengage:android-sdk:[4.4,)'
  api 'com.webengage:we-notification-inbox:[1,)'

  // CoroutineScope
  api 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
  api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'
  api "org.jetbrains.kotlin:kotlin-stdlib:1.4.10"
}

if (isNewArchitectureEnabled()) {
  react {
    jsRootDir = file("../src/")
    libraryName = "WEPersonalizationView"
    codegenJavaPackageName = "com.webengagepersonalization"
  }
}
