apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs"
apply plugin: 'kotlin-parcelize'
apply plugin: 'org.jlleitschuh.gradle.ktlint'
apply plugin: 'dagger.hilt.android.plugin'

buildscript {
    repositories {
        maven { url "https://plugins.gradle.org/m2/" }
    }

    dependencies {
        classpath "org.jlleitschuh.gradle:ktlint-gradle:10.1.0"
    }
}

def STRING = 'String'
def BUILD_TIME = 'BUILD_TIME'


repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url 'https://jitpack.io' }
    maven { url 'https://maven.google.com' }
    mavenCentral()
}

android {
    compileSdkVersion Configs.compileSdkVersion
    buildToolsVersion Configs.buildToolsVersion

    defaultConfig {
        applicationId Configs.applicationId
        minSdkVersion Configs.minSdkVersion
        targetSdkVersion Configs.targetSdkVersion
        versionCode Configs.versionCode
        versionName Configs.versionName
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        buildConfigField STRING, BUILD_TIME, "\"${Configs.buildTime}\""

        setProperty("archivesBaseName", "${Configs.archivesBaseName}")
    }
    buildTypes {
        release {
            minifyEnabled true
            zipAlignEnabled true
            shrinkResources true
            debuggable false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testCoverageEnabled false

            signingConfig signingConfigs.debug
        }
        debug {
            ext.enableCrashlytics = false
            testCoverageEnabled true
        }
    }
    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/atomicfu.kotlin_module'
        exclude 'META-INF/rxjava.properties'
    }
    buildFeatures {
        buildConfig = true
        dataBinding = true
    }
    testOptions {
        unitTests {
            includeAndroidResources = true
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kapt {
        correctErrorTypes = true
    }
}

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

    // kotlin
    implementation Dependencies.kotlin
    implementation Dependencies.kotlinReflect

    // android supports
    implementation Dependencies.supportv4
    implementation Dependencies.appCompat
    implementation Dependencies.materialDesign
    implementation Dependencies.recyclerView
    implementation Dependencies.cardView
    implementation Dependencies.coreKtx

    // architecture components
    implementation Dependencies.navigationUI
    implementation Dependencies.navigationFragment
    implementation Dependencies.lifecycleExt
    kapt Dependencies.lifecycleAnnotation
    implementation Dependencies.liveDataKtx
    implementation Dependencies.lifecycleViewModelKtx
    implementation Dependencies.roomRuntime
    kapt Dependencies.roomCompiler

    // di
    implementation Dependencies.hilt
    kapt Dependencies.hiltKapt

    // rx
    implementation Dependencies.rxJava
    implementation Dependencies.rxKotlin
    implementation Dependencies.rxAndroid
    implementation Dependencies.rxAnimations

    // network
    implementation Dependencies.retrofit
    implementation Dependencies.okHttp
    implementation Dependencies.moshi
    implementation Dependencies.moshiConverter
    implementation Dependencies.moshiKotlin
    kapt Dependencies.moshiKapt
    implementation Dependencies.rxJavaAdapter

    // image
    implementation Dependencies.picasso

    // debug
    implementation Dependencies.stethoCore
    implementation Dependencies.stethoOkHttp
    implementation Dependencies.stethoUrlConnection
    implementation Dependencies.timber

    // shadow view
    implementation Dependencies.shadowView

    // date & time
    implementation Dependencies.threetenabp

    // search
    implementation Dependencies.algolia

    // test
    testImplementation Dependencies.junit
    testImplementation Dependencies.junitTestExt
    androidTestImplementation Dependencies.androidxTestRunner
    androidTestImplementation Dependencies.androidxTestRules
    androidTestImplementation Dependencies.espressoCore
    testImplementation Dependencies.truthExt
    testImplementation Dependencies.truth
    testImplementation Dependencies.mockK
    testImplementation Dependencies.coreTesting
    testImplementation Dependencies.robolectric
}

ktlint {
    android = true
    outputToConsole = true
    ignoreFailures = true
    enableExperimentalRules = true
    version = Versions.klintVersion
    kotlinScriptAdditionalPaths {
        include fileTree("scripts/")
    }
    filter {
        exclude("**/generated/**")
        include("**/kotlin/**")
        include("**/java/**")
    }
}

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