plugins{
    id "com.android.application"
    id "kotlin-android"
    id "org.jetbrains.kotlinx.kover"
    id "dev.flutter.flutter-gradle-plugin"
}

def exampleAppApplicationId = 'com.auth0.auth0_flutter_example'
def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

android {
    compileSdk 34
    if (project.android.hasProperty("namespace")) {
        namespace exampleAppApplicationId
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
        androidTest.java.srcDirs += 'src/androidTest/kotlin'
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId exampleAppApplicationId
        minSdkVersion 24
        targetSdk 34
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        manifestPlaceholders += [auth0Domain: "YOUR_DOMAIN",
                                auth0Scheme: "YOUR_SCHEME"]

        testOptions {
            unitTests.returnDefaultValues = true
            animationsDisabled = true
            buildConfigField "String", "USER_EMAIL", "\"$System.env.USER_EMAIL\""
            buildConfigField "String", "USER_PASSWORD", "\"$System.env.USER_PASSWORD\""
        }
    }

    buildFeatures {
        buildConfig true
    }

    buildTypes {
        debug {
            testCoverageEnabled true
        }
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }

    splits {
        abi {
            enable true
            reset()
            include 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
            universalApk true
        }
    }
}

flutter {
    source '../..'
}

dependencies {
    kover(project(":auth0_flutter"))
}

koverReport {
    androidReports("debug") {
        xml {
            setReportFile(layout.buildDirectory.file("coverage.xml"))
        }

        filters {
            includes {
                packages("com.auth0.auth0_flutter")
            }
        }
    }
}
