import groovy.json.JsonSlurper

def sdkVersions = new JsonSlurper().parse file("../sdk-versions.json")

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:8.5.0")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.21")
    }
}

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

// Define helper functions for Kotlin version management (RN 0.77.3 requires 2.0.21)
def getKotlinVersion() {
    return rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : "2.0.21"
}

def getKotlinGradlePluginVersion() {
    return rootProject.ext.has("kotlinGradlePluginVersion") ? rootProject.ext.get("kotlinGradlePluginVersion") : "2.0.21"
}

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

android {
    namespace 'com.reactnativehmssdk'
    buildToolsVersion = "35.0.0"
    compileSdkVersion safeExtGet('Hmssdk_compileSdkVersion', 35)
    defaultConfig {
        minSdkVersion safeExtGet('Hmssdk_minSdkVersion', 24)
        targetSdkVersion safeExtGet('Hmssdk_targetSdkVersion', 35)
        versionCode 1
        versionName "1.0"
    }

    lint {
        disable 'GradleCompatible'
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }
    kotlinOptions {
        jvmTarget = "17"
    }
}

repositories {
    mavenLocal()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url("$rootDir/../node_modules/react-native/android")
    }
    google()
    mavenCentral()
    gradlePluginPortal( )
    maven { url 'https://jitpack.io' }
}

dependencies {
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"
    implementation "com.google.code.gson:gson:2.11.0"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:${getKotlinVersion()}"
    implementation "androidx.core:core-ktx:1.13.1"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1"
    implementation "androidx.constraintlayout:constraintlayout:2.1.4"
    implementation "androidx.appcompat:appcompat:1.7.0"

    implementation "live.100ms:android-sdk:${sdkVersions["android"]}"
    implementation "live.100ms:video-view:${sdkVersions["android"]}"
    implementation "live.100ms:hls-player:${sdkVersions["android"]}"
    implementation "live.100ms:hms-noise-cancellation-android:${sdkVersions["android"]}"
}
