/*
 * Copyright 2022 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin"

android {
    compileSdkVersion rootProject.compileSdkVersion

    defaultConfig {
        // This ID uniquely identifies your app on the device and in Google Play Store
        applicationId "PUT_YOUR_APPLICATION_ID_HERE"

        minSdkVersion rootProject.minSdkVersion
        targetSdkVersion rootProject.targetSdkVersion
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
    }

    android {
        sourceSets {
            String sharedTestDir = 'src/sharedTest/java'
            test {
                java.srcDirs += sharedTestDir
            }
            androidTest {
                java.srcDirs += sharedTestDir
            }
        }
    }

    buildTypes {
        debug {
            minifyEnabled false
            testCoverageEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
            isDefault = true
        }
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
        }
    }

    flavorDimensions "default"

    // Always show the result of every unit test, even if it passes.
    testOptions.unitTests {
        includeAndroidResources = true

        all {
            testLogging {
                events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
            }
        }
    }

    buildFeatures {
        dataBinding = true
    }

    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }
}

/*
 Dependency versions are defined in the top level build.gradle file. This helps keeping track of
 all versions in a single place. This improves readability and helps managing project complexity.
 */
dependencies {

    // App dependencies
    implementation "androidx.appcompat:appcompat:$appCompatVersion"
    implementation "androidx.cardview:cardview:$cardVersion"
    implementation "com.google.android.material:material:$materialVersion"
    implementation "androidx.recyclerview:recyclerview:$recyclerViewVersion"
    implementation "androidx.annotation:annotation:$androidXAnnotations"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
    implementation "androidx.legacy:legacy-support-v4:$androidXLegacySupport"
    implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"
    kapt "androidx.room:room-compiler:$roomVersion"

    // Architecture Components
    implementation "androidx.room:room-runtime:$roomVersion"
    kapt "androidx.room:room-compiler:$roomVersion"
    implementation "androidx.room:room-ktx:$roomVersion"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$archLifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$archLifecycleVersion"
    implementation "androidx.navigation:navigation-fragment-ktx:$navigationVersion"
    implementation "androidx.navigation:navigation-ui-ktx:$navigationVersion"

    // Dependencies for local unit tests
    testImplementation "junit:junit:$junitVersion"
    testImplementation "org.mockito:mockito-core:$mockitoVersion"
    testImplementation "org.hamcrest:hamcrest-all:$hamcrestVersion"
    testImplementation "androidx.arch.core:core-testing:$archTestingVersion"
    testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
    testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"
    testImplementation "org.robolectric:robolectric:$robolectricVersion"
    testImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
    testImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
    testImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
    testImplementation "com.google.truth:truth:$truthVersion"

    // Dependencies for Android unit tests
    androidTestImplementation "junit:junit:$junitVersion"
    androidTestImplementation "org.mockito:mockito-core:$mockitoVersion"
    androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito:$dexMakerVersion"
    androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutinesVersion"

    // AndroidX Test - JVM testing
    testImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"
    testImplementation "androidx.test.ext:junit-ktx:$androidXTestExtKotlinRunnerVersion"
    testImplementation "androidx.test:rules:$androidXTestRulesVersion"
    // Once https://issuetracker.google.com/127986458 is fixed this can be testImplementation
    debugImplementation "androidx.fragment:fragment-testing:$fragmentVersion"
    implementation "androidx.test:core:$androidXTestCoreVersion"

    // AndroidX Test - Instrumented testing
    androidTestImplementation "androidx.test:core-ktx:$androidXTestCoreVersion"
    androidTestImplementation "androidx.test.ext:junit-ktx:$androidXTestExtKotlinRunnerVersion"
    androidTestImplementation "androidx.test:rules:$androidXTestRulesVersion"
    androidTestImplementation "androidx.room:room-testing:$roomVersion"
    androidTestImplementation "androidx.arch.core:core-testing:$archTestingVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
    androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
    androidTestImplementation "androidx.test.espresso:espresso-intents:$espressoVersion"
    androidTestImplementation "androidx.test.espresso.idling:idling-concurrent:$espressoVersion"
    androidTestImplementation "org.robolectric:annotations:$robolectricVersion"
    implementation "androidx.test.espresso:espresso-idling-resource:$espressoVersion"

    // Resolve conflicts between main and test APK:
    androidTestImplementation "androidx.annotation:annotation:$androidXAnnotations"
    androidTestImplementation "androidx.legacy:legacy-support-v4:$androidXLegacySupport"
    androidTestImplementation "androidx.recyclerview:recyclerview:$recyclerViewVersion"
    androidTestImplementation "androidx.appcompat:appcompat:$appCompatVersion"
    androidTestImplementation "com.google.android.material:material:$materialVersion"

    // Kotlin
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
    implementation "androidx.fragment:fragment-ktx:$fragmentKtxVersion"
}

/*configurations.all() {
    resolutionStrategy.force "org.antlr:antlr4-runtime:4.5.3"
    resolutionStrategy.force "org.antlr:antlr4-tool:4.5.3"
}*/
