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

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

  dependencies {
    //classpath "com.android.tools.build:gradle:8.7.3"
    // noinspection DifferentKotlinGradleVersion
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
    classpath "com.facebook.react:react-native-gradle-plugin:0.81.0"  // Added version to fix resolution
  }
}

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["SahhaReactNative_" + name]).toInteger()
}

android {
  namespace "com.sahhareactnative"

  compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")

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

  buildFeatures {
    buildConfig true
  }

  buildTypes {
    release {
      minifyEnabled false
    }
  }

  lintOptions {
    disable "GradleCompatible"
  }

  compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
  }

  sourceSets {
    main {
      java.srcDirs += [
        "generated/java",
        "generated/jni"
      ]
    }
  }
}

repositories {
  mavenCentral()
  google()
  maven { url "$rootProject.projectDir/../node_modules/react-native/android" }  // Added for local RN resolution
}

def kotlin_version = getExtOrDefault("kotlinVersion")

dependencies {
  implementation "com.facebook.react:react-native:0.83.1"  // Pinned to your RN version
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
  implementation "com.google.code.gson:gson:2.13.2"
  implementation "ai.sahha.android:sahha-api:1.4.0-beta.2"
}