ext {
    appAuthVersion = project.hasProperty('appAuthVersion') ? rootProject.ext.appAuthVersion : '0.9.1'
    androidxBrowserVersion = project.hasProperty('androidxBrowserVersion') ? rootProject.ext.androidxBrowserVersion : '1.5.0'
    junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
    commonsIoVersion = project.hasProperty('commonsIoVersion') ? rootProject.ext.commonsIoVersion : '2.10.0'
    androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
    junit5Version = project.hasProperty('junit5Version') ? rootProject.ext.junit5Version : '5.7.2'
    androidJunit5Version = project.hasProperty('androidJunit5Version') ? rootProject.ext.androidJunit5Version : '1.2.2'
    androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
}

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:8.0.0'
    }
}

apply plugin: 'com.android.library'

android {
    namespace "com.byteowls.capacitor.oauth2"
    compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 33
    defaultConfig {
        minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
        targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 33
        versionCode 1
        versionName "1.0"
        // 1) Make sure to use the AndroidJUnitRunner, or a subclass of it. This requires a dependency on androidx.test:runner, too!
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        // 2) Connect JUnit 5 to the runner
//        testInstrumentationRunnerArgument("runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder")
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_17
        targetCompatibility JavaVersion.VERSION_17
    }

    unitTestVariants.all {
        it.mergedFlavor.manifestPlaceholders += [
            appAuthRedirectScheme: "com.byteowls.capacitorapp"
        ]
    }

//    testOptions {
//        unitTests {
//            all {
//                include 'com.byteowls.capacitor.oauth2'
//            }
//        }
//    }
}

repositories {
    google()
    mavenCentral()
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation project(':capacitor-android')

    implementation "androidx.browser:browser:$androidxBrowserVersion"
    implementation "net.openid:appauth:$appAuthVersion"
    implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"

    // 4) Jupiter API & Test Runner, if you don't have it already
    testImplementation("org.junit.jupiter:junit-jupiter-params:${junit5Version}")
    testImplementation("org.junit.jupiter:junit-jupiter-api:${junit5Version}") {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    testImplementation "commons-io:commons-io:$commonsIoVersion"
}

// ###############
// ### AppAuth ###
// ###############

android.defaultConfig.manifestPlaceholders = [
    'appAuthRedirectScheme': 'com.byteowls.capacitorapp'
]
