import dependencies.Dep
import dependencies.Packages
import dependencies.Versions

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'androidx.navigation.safeargs'
apply plugin: 'com.google.android.gms.oss-licenses-plugin'
apply plugin: 'io.fabric'
apply plugin: 'com.akaita.android.easylauncher'

android {
    compileSdkVersion Versions.androidCompileSdkVersion
    signingConfigs {
        debug {
            keyAlias 'droidkaigi_debug'
            keyPassword 'droidkaigi'
            storeFile file('debug.keystore')
            storePassword 'droidkaigi'
        }
        release {
            keyAlias System.getenv("RELEASE_KEY_ALIAS")
            keyPassword System.getenv("RELEASE_KEY_PASSWORD")
            storeFile file(System.getenv("RELEASE_KEY_STORE_FILE") ?: 'debug.keystore')
            storePassword System.getenv("RELEASE_KEY_STORE_PASSWORD")
        }
    }
    defaultConfig {
        applicationId Packages.name
        minSdkVersion Versions.androidMinSdkVersion
        targetSdkVersion 28
        versionCode Versions.androidVersionCode
        versionName Versions.androidVersionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        resConfigs "ja"
        if (!isCi && !isReleaseBuild) {
            // For Android Studio Gradle sync
            // gms plugin cannot parse google-service.json correctly if applicationIdSuffix is specified here
            applicationIdSuffix Packages.debugNameSuffix
        }
        manifestPlaceholders = [isCi: String.valueOf(isCi)]
    }
    buildTypes {
        debug {
            if (isCi || isReleaseBuild) {
                applicationIdSuffix Packages.debugNameSuffix
            }
            manifestPlaceholders = [appName: "@string/app_name_debug"]
            debuggable true
        }
        staging {
            if (isCi || isReleaseBuild) {
                applicationIdSuffix Packages.debugNameSuffix
            }
            manifestPlaceholders = [appName: "@string/app_name_staging"]
            debuggable true
            zipAlignEnabled true
            signingConfig = signingConfigs.debug
            matchingFallbacks = ['release']

            postprocessing {
                proguardFiles 'proguard-rules.pro'
                obfuscate = true
                // if we want to enable optimization, then codeShrinker must be proguard for now
                // That may be a bug of r8
                optimizeCode = false
                removeUnusedCode = true
                removeUnusedResources = true
                codeShrinker = 'r8'
            }
        }
        release {
            manifestPlaceholders = [appName: "@string/app_name"]
            debuggable false
            zipAlignEnabled true
            signingConfig = signingConfigs.release

            postprocessing {
                proguardFiles 'proguard-rules.pro', 'proguard-rules-production.pro'
                obfuscate = true
                // if we want to enable optimization, then codeShrinker must be proguard for now
                // That may be a bug of r8
                optimizeCode = false
                removeUnusedCode = true
                removeUnusedResources = true
                codeShrinker = 'r8'
            }
        }
    }
    dataBinding {
        enabled = true
    }
    lintOptions {
        lintConfig file("${project.projectDir}/lint.xml")

        xmlReport isCi
        htmlReport !isCi

        xmlOutput file("lint-results.xml")
        htmlOutput file("lint-results.html")

        checkReleaseBuilds !isCi
        abortOnError !isCi
    }
    packagingOptions {
        exclude 'META-INF/*.kotlin_module'
        exclude 'META-INF/*.version'
        exclude 'META-INF/proguard/*.pro'
    }
}

dependencies {
    implementation project(":model")
    implementation project(":feature:session")
    implementation project(":feature:about")
    implementation project(":feature:announcement")
    implementation project(":feature:floormap")
    implementation project(":feature:sponsor")
    implementation project(":feature:settings")
    implementation project(":feature:contributor")
    implementation project(":feature:staff")
    implementation project(':feature:user')
    implementation project(':feature:survey')
    implementation project(':feature:system')
    implementation project(':feature:notification')
    implementation project(':corecomponent:androidcomponent')
    implementation project(':data:db-room')
    implementation project(':data:repository-impl')
    implementation project(':data:firestore-impl')
    implementation project(':data:api-impl')
    implementation project(':data:device-impl')
    implementation project(':ext:log')

    implementation Dep.Kotlin.stdlibJvm
    api Dep.Kotlin.coroutines
    implementation Dep.Kotlin.androidCoroutinesDispatcher
    implementation Dep.OkHttp.okio

    implementation Dep.Firebase.fireStore

    implementation Dep.AndroidX.appCompat
    implementation Dep.AndroidX.constraint

    implementation Dep.AndroidX.Navigation.runtime
    implementation Dep.AndroidX.Navigation.fragment
    implementation Dep.AndroidX.Navigation.ui
    implementation Dep.AndroidX.Navigation.runtimeKtx
    implementation Dep.AndroidX.Navigation.fragmentKtx

    implementation Dep.AndroidX.coreKtx

    debugImplementation Dep.Stetho.stetho
    stagingImplementation Dep.Stetho.stetho

    debugImplementation Dep.LeakCanary.leakCanary
    debugImplementation Dep.LeakCanary.leakCanaryFragment
    stagingImplementation Dep.LeakCanary.leakCanaryNoOp
    releaseImplementation Dep.LeakCanary.leakCanaryNoOp

    implementation Dep.Firebase.core
    implementation Dep.Firebase.auth
    implementation Dep.Firebase.crashlytics

    api Dep.Dagger.core
    api Dep.Dagger.androidSupport
    api Dep.Dagger.android
    kapt Dep.Dagger.compiler
    kapt Dep.Dagger.androidProcessor
    compileOnly Dep.Dagger.assistedInjectAnnotations
    kapt Dep.Dagger.assistedInjectProcessor

    implementation Dep.Timber.android

    testImplementation Dep.Test.junit
    testImplementation Dep.Test.kotlinTestAssertions

    androidTestImplementation Dep.Test.testRunner
    androidTestImplementation Dep.Test.espressoCore

    Dep.Hyperion.hyperionPlugins.forEach {
        debugImplementation it
        stagingImplementation it
    }
}

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