ext {
    junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
    androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
    androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
    androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
}

def javaVersion = project.hasProperty('javaVersion') ? rootProject.ext.javaVersion : JavaVersion.VERSION_1_8

buildscript {
    def kotlinVersion = null

    if (project.hasProperty('kotlinVersion')) {
        kotlinVersion = project.kotlinVersion
    } else if (project.hasProperty('kotlin_version')) {
        kotlinVersion = project.kotlin_version
    } else if (rootProject.ext.has('kotlinVersion')) {
        kotlinVersion = rootProject.ext.kotlinVersion
    } else if (rootProject.ext.has('kotlin_version')) {
        kotlinVersion = rootProject.ext.kotlin_version
    }

    if (!kotlinVersion) {
        def gradleMajor = gradle.gradleVersion.tokenize('.')[0] as int
        if (gradleMajor >= 8) {
            kotlinVersion = '1.9.10'
        } else if (gradleMajor >= 7) {
            kotlinVersion = '1.7.10'
        } else {
            kotlinVersion = '1.4.32'
        }
    }

    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}"
    }
}

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

android {
    namespace "com.uxcam.capacitor"
    compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
    defaultConfig {
        minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
        targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    compileOptions {
        sourceCompatibility javaVersion
        targetCompatibility javaVersion
    }
    kotlinOptions {
        jvmTarget = javaVersion.toString()
    }
}

repositories {
    google()
    mavenCentral()
    maven { url 'https://sdk.uxcam.com/android/' }
}

// Propagate UXCam maven repository to the root project so dependency resolution works
rootProject.allprojects {
    repositories {
        maven { url 'https://sdk.uxcam.com/android/' }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':capacitor-android')
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
    implementation 'com.uxcam:uxcam:3.8.14'

    testImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
}
