buildscript {
  ext.getExtOrDefault = {name ->
    return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['RAVEN_' + name]
  }

  repositories {
    google()
    mavenCentral()
  }

  dependencies {
    classpath "com.android.tools.build:gradle:8.3.0"
    // noinspection DifferentKotlinGradleVersion
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
  }
}


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

apply plugin: "com.facebook.react"

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

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

android {
  namespace "com.ravenclient"

  compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

  defaultConfig {
    minSdkVersion getExtOrIntegerDefault("minSdkVersion")
    targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
    buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
    externalNativeBuild {
      cmake {
        arguments "-DNODE_MODULES=${rootDir}/../node_modules","-DANDROID_STL=c++_shared"
        cppFlags "-O2 -frtti -fexceptions -Wall -fstack-protector-all"
        abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
      }
    }
  }

  externalNativeBuild {
    cmake {
      path "CMakeLists.txt"
    }
  }

  buildFeatures {
    buildConfig true
  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }

  lintOptions {
    disable "GradleCompatible"
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  sourceSets {
    main {
      if (isNewArchitectureEnabled()) {
        java.srcDirs += [
          "src/newarch",
          "generated/java",
          "generated/jni"
        ]
      } else {
        java.srcDirs += ["src/oldarch"]
      }
    }
  }
}

  repositories {
    maven {
      name = "GitHubPackages"
      url = uri("https://maven.pkg.github.com/dream11/ds-comms-android-sdk")
      credentials {
        username = System.getenv("GITHUB_USERNAME") ?: ""
        password = System.getenv("GITHUB_TOKEN") ?: ""
      }
    }
    google()
    mavenCentral()
  }

def kotlin_version = getExtOrDefault("kotlinVersion")

dependencies {
  implementation "com.facebook.react:react-android"
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  implementation 'com.tencent:mmkv:1.3.0'
  implementation "com.dscomms:android-sdk:0.0.7"
}

react {
  jsRootDir = file("../src/")
  libraryName = "RavenClient"
  codegenJavaPackageName = "com.ravenclient"
}
