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

  repositories {
    google()
    mavenCentral()
  }

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


apply plugin: "com.android.library"
// AGP 9 ships built-in Kotlin support and registers the `kotlin` extension
// itself. Applying the Kotlin plugin on top of it fails configuration with
// "Cannot add extension with name 'kotlin'". Only apply it when nothing has
// registered that extension yet.
if (project.extensions.findByName('kotlin') == null) {
  apply plugin: "kotlin-android"
}

apply plugin: "kotlin-parcelize"

apply plugin: "com.facebook.react"

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

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

android {
  namespace "io.getstream.rn.callingx"

  compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

  defaultConfig {
    minSdkVersion getExtOrIntegerDefault("minSdkVersion")
    targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
  }

  buildFeatures {
    buildConfig true
  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }

  lint {
    disable "GradleCompatible"
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_11
    targetCompatibility JavaVersion.VERSION_11
  }

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

repositories {
  mavenCentral()
  google()
}

def kotlin_version = getExtOrDefault("kotlinVersion")

dependencies {
  implementation "com.facebook.react:react-android"
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  implementation "androidx.core:core-telecom:1.0.1"
  // Compile-time only dependency so StreamMessagingService can reference RemoteMessage.
  // The consuming app (via @react-native-firebase/messaging) must provide the actual runtime version.
  compileOnly "com.google.firebase:firebase-messaging:24.1.2"
  // Optional: use Firebase native code when the app has react-native-firebase installed (peer deps)
  implementation project(':react-native-firebase_app')
  implementation project(':react-native-firebase_messaging')
}
