buildscript {
    if (project == rootProject) {
        repositories {
            google()
            mavenCentral()
        }

        dependencies {
            classpath("com.android.tools.build:gradle:8.12.0")
            classpath("com.facebook.react:react-native-gradle-plugin:0.86.0")
        }
    }
}

apply plugin: 'com.android.library'
apply plugin: 'com.facebook.react'

def safeExtGet(prop, fallback) {
    if (rootProject.ext.has(prop)) {
        return rootProject.ext.get(prop)
    }

    rootProject.hasProperty(prop) ? rootProject.property(prop) : fallback
}

def telematicsCompileSdk = safeExtGet('TelematicsSdk_compileSdkVersion', 37).toString().toInteger()

android {
    namespace "com.reactnativetelematicssdk"
    compileSdk telematicsCompileSdk
    defaultConfig {
        minSdk safeExtGet('TelematicsSdk_minSdkVersion', 24)
        targetSdk safeExtGet('TelematicsSdk_targetSdkVersion', 36)
        versionCode 3
        versionName "1.0"

        def isNewArchEnabled = (project.findProperty("newArchEnabled") ?: "false").toString().toBoolean()
        buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchEnabled.toString()
        }

    packaging {
        resources {
            excludes += [
                'META-INF/INDEX.LIST',
                'META-INF/io.netty.versions.properties',
                'META-INF/versions/9/OSGI-INF/MANIFEST.MF'
            ]
        }
    }

    buildTypes {
        release {
            minifyEnabled false
        }
    }
    lint {
        disable.add('GradleCompatible')
    }
    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    buildFeatures {
        buildConfig true
    }
}

if (telematicsCompileSdk < 37) {
    throw new GradleException(
        "react-native-telematics requires compileSdk 37 or higher because " +
        "com.telematicssdk:tracking:4.1.0 requires Android API 37. " +
        "Set TelematicsSdk_compileSdkVersion (or the app compileSdk) to 37 or higher."
    )
}


repositories {
    maven {
        url "https://s3.us-east-2.amazonaws.com/android.telematics.sdk.production/"
    }
}

dependencies {
    //noinspection GradleDynamicVersion
    coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:2.1.5"
    implementation("com.facebook.react:react-android")
    implementation("com.telematicssdk:tracking:4.1.0")
}
