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

// We dynamically add the dependencies to avoid failures
tasks.build.dependsOn = []

android {
    compileSdkVersion 29
    buildToolsVersion buildToolsLevel

    dataBinding {
        enabled = true
    }

    repositories {
        mavenCentral()
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "ar.gob.coronavirus"
        minSdkVersion minSdkLevel
        targetSdkVersion targetSdkLevel
        versionCode 142
        versionName "3.5.6" + (project.hasProperty("VERSION_CLASSIFIER") ? "-" + project.property("VERSION_CLASSIFIER") : "")

        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments clearPackageData: 'true'

        buildConfigField("String", "APP_NAME", "\"CuidAR\"")

        // Pin certificates
        buildConfigField("String", "CERTIFICADO_SHA1", "\"sha256/UXt/pC5LL5LT5C2ajleIfKh8FUrseWflM+tcO+284+o=\"")
        buildConfigField("String", "CERTIFICADO_SHA2", "\"sha256/JSMzqOOrtyOT1kmau6zKhgT676hGgczD5VMdRMyJZFA=\"")
        buildConfigField("String", "CERTIFICADO_SHA3", "\"sha256/++MBgDH5WGvL9Bcn5Be30cRcL0f5O+NyoXuWtQdX1aI=\"")
    }

    buildTypes {
        debug {
            applicationIdSuffix ".qa"
            versionNameSuffix "-QA"
            resValue "string", "app_name", "Covid19-AR (QA)"
        }

        opensource {
            debuggable true
            signingConfig signingConfigs.debug
            applicationIdSuffix ".opensource"
            versionNameSuffix "-OPENSOURCE"
            resValue "string", "app_name", "Covid19-AR (Open Source)"
        }

        staging {
            debuggable true
            signingConfig signingConfigs.debug
            applicationIdSuffix ".stg"
            versionNameSuffix "-STG"
            resValue "string", "app_name", "Covid19-AR (Staging)"
        }

        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            resValue "string", "app_name", "Covid19-AR"
        }
    }

    buildTypes.each {
        if (project.file("./src/${it.name}/build.gradle").exists()) {
            apply from: "./src/${it.name}/build.gradle"
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }

    testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR'
    }
    useLibrary 'android.test.runner'
    useLibrary 'android.test.base'
    useLibrary 'android.test.mock'
}

apply plugin: 'com.google.gms.google-services'

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

    //Android
    implementation "androidx.multidex:multidex:$multidexVersion"
    implementation "androidx.appcompat:appcompat:$appCompatVersion"
    implementation "androidx.legacy:legacy-support-v4:$legacySupportVersion"
    implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
    implementation "androidx.fragment:fragment-ktx:$fragmentKtxVersion"
    implementation "androidx.navigation:navigation-fragment:$navVersion"
    implementation "androidx.navigation:navigation-ui:$navVersion"
    implementation "androidx.security:security-crypto:$securityCryptoVersion"
    implementation "androidx.room:room-runtime:$roomVersion"
    implementation "androidx.room:room-rxjava2:$roomVersion"
    kapt "androidx.room:room-compiler:$roomVersion"
    implementation "com.google.android.material:material:$androidMaterialVersion"
    implementation "com.google.android.gms:play-services-location:$playServicesLocationVersion"

    //Firebase
    implementation "com.google.firebase:firebase-core:$firebaseCoreVersion"
    implementation "com.google.firebase:firebase-messaging:$firebaseMessagingVersion"

    //RxJava
    implementation "io.reactivex.rxjava2:rxjava:$rxJavaVersion"
    implementation "io.reactivex.rxjava2:rxandroid:$rxAndroidVersion"

    //Retrofit
    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofitVersion"
    implementation "com.squareup.okhttp3:logging-interceptor:$loggingInterceptorVersion"

    implementation "org.koin:koin-androidx-viewmodel:$koinVersion"

    //Otras
    implementation "com.github.bumptech.glide:glide:$glideVersion"
    implementation "com.jakewharton.timber:timber:$timberVersion"
    implementation "net.zetetic:android-database-sqlcipher:$sqlCipherVersion"
    implementation "commons-codec:commons-codec:$commonsCodecVersion"
    implementation "com.newrelic.agent.android:android-agent:$newRelicVersion"
    implementation "com.google.zxing:core:$zxingVersion"
    implementation("com.journeyapps:zxing-android-embedded:$zxingEmbeddedVersion") { transitive = false }

    //TEST
    testImplementation "junit:junit:$junitVersion"
    testImplementation "org.koin:koin-test:$koinVersion"
    testImplementation "io.mockk:mockk:$mockkVersion"
    testImplementation "com.squareup.okhttp3:mockwebserver:$mockWebServerVersion"

    androidTestUtil "androidx.test:orchestrator:$testOrchestrator"
    androidTestImplementation "androidx.test.ext:junit:$junitAndroidVersion"
    androidTestImplementation "androidx.test.espresso:espresso-core:$espressoCoreVersion"
    androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoCoreVersion"
    androidTestImplementation "androidx.test:runner:$junitRunnerVersion"
    androidTestImplementation "androidx.test:rules:$junitRulesVersion"
    androidTestImplementation "com.squareup.okhttp3:mockwebserver:$mockWebServerVersion"
    androidTestImplementation "org.koin:koin-test:$koinVersion"
}
