import io.github.droidkaigi.feeder.AppVersions
import io.github.droidkaigi.feeder.Dep
import io.github.droidkaigi.feeder.Versions

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
    id 'com.google.gms.google-services'
    id 'com.google.firebase.crashlytics'
    id 'com.google.android.gms.oss-licenses-plugin'
}

apply from: rootProject.file("gradle/compose.gradle")

android {
    compileSdkVersion 31
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "io.github.droidkaigi.feeder"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode AppVersions.versionCode
        versionName AppVersions.versionName

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    signingConfigs {
        debug {
            storeFile project.file("development.keystore")
            storePassword "android"
            keyAlias "androiddebugkey"
            keyPassword "android"
        }
        release {
            def signingPropertyFile = file('signing.properties')
            if (signingPropertyFile.exists()) {
                def fileInputStream = new FileInputStream(signingPropertyFile)
                def props = new Properties()
                props.load(fileInputStream)
                fileInputStream.close()

                storeFile file("release.keystore")
                storePassword props['storePassword']
                keyAlias props['keyAlias']
                keyPassword  props['keyPassword']
            }
        }
    }
    buildTypes {
        debug {
            debuggable true
            applicationIdSuffix ".debug"
            versionNameSuffix "-debug"
            signingConfig signingConfigs.debug

            firebaseCrashlytics {
                mappingFileUploadEnabled false
            }
        }
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }
    compileOptions {
        coreLibraryDesugaringEnabled true // https://github.com/DroidKaigi/conference-app-2021/issues/373
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    testOptions {
        unitTests {
            returnDefaultValues = true
            includeAndroidResources = true
        }
        unitTests.all {
            maxHeapSize = "4096m"
            maxParallelForks = Runtime.runtime.availableProcessors() / 2
            testLogging {
                exceptionFormat = "full"
                showCauses true
                showExceptions true
                showStackTraces true
                events = ["failed"]
            }
        }
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        buildConfig false
    }
}

hilt {
    enableExperimentalClasspathAggregation = true
}

dependencies {
    implementation projects.data.repository
    implementation projects.uicomponentCompose.main

    // Java 8+ API desugaring support
    coreLibraryDesugaring Dep.desugarJdkLibs

    // Hilt
    implementation Dep.Dagger.hiltAndroid
    kapt Dep.Dagger.hiltAndroidCompiler

    // For instrumentation tests
    androidTestImplementation Dep.Dagger.hiltAndroidTesting
    kaptAndroidTest Dep.Dagger.hiltAndroidCompiler

    // For local unit tests
    testImplementation Dep.Dagger.hiltAndroidTesting
    kaptTest Dep.Dagger.hiltAndroidCompiler

    implementation Dep.Jetpack.hiltCommon
    implementation Dep.Jetpack.hiltLifeCycleViewModel
    kapt Dep.Dagger.hiltAndroidCompiler

    implementation Dep.Compose.activity
    implementation Dep.Compose.runtime
    implementation Dep.Compose.ui

    implementation Dep.Kotlin.bom
    implementation Dep.Kotlin.stdlib

    implementation (Dep.Coroutines.core) {
        version {
            strictly Versions.coroutines
        }
    }

    implementation Dep.Jetpack.core
    implementation Dep.Jetpack.fragment
    implementation Dep.Jetpack.activity

    implementation Dep.Jetpack.appcompat
    implementation Dep.Jetpack.lifecycle
    implementation 'com.google.android.material:material:1.3.0'

    implementation Dep.FirebaseCrashlytics.android

    implementation Dep.firebaseAuth
    implementation Dep.firebaseMessaging
    implementation Dep.Jetpack.startup
    implementation Dep.Jetpack.browser

    // For Layout inspector
    debugImplementation Dep.Compose.tooling
    debugImplementation Dep.Kotlin.reflect

    debugImplementation Dep.Flipper.flipper
    debugImplementation Dep.Flipper.networkPlugin
    debugImplementation Dep.Flipper.soLoader

    testImplementation 'junit:junit:4.13.1'
    testImplementation Dep.Coroutines.test
    testImplementation 'io.kotest:kotest-assertions-core:4.3.2'
    // https://github.com/cashapp/turbine/issues/10
    testImplementation 'app.cash.turbine:turbine:0.2.1'

    androidTestImplementation Dep.Jetpack.Test.ext
    androidTestImplementation Dep.Jetpack.Test.espresso
}

