plugins {
    id "com.android.application"
    id "kotlin-android"
    id "kotlin-kapt"
}
try {
    apply from: 'signing.config.gradle'
} catch (Throwable ignored) {
    println "Warning: No Signing Config found"
    ext.KEY_ALIAS = ""
    ext.KEY_PASSWORD = ""
    ext.STORE_PASSWORD = ""
    ext.KEYSTORE_FILE = ""
}

android {
    compileSdkVersion 31

    defaultConfig {
        applicationId "org.fnives.tiktokdownloader"
        minSdkVersion 23
        targetSdkVersion 33
        versionCode 2
        versionName "1.3.1"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    signingConfigs {
        release {
            keyAlias "$KEY_ALIAS"
            keyPassword "$KEY_PASSWORD"
            storeFile file("$KEYSTORE_FILE")
            storePassword "$STORE_PASSWORD"
        }
    }
    buildTypes {
        debug {
            versionNameSuffix "-dev"
            applicationIdSuffix ".debug"
            debuggable true
            shrinkResources false
            minifyEnabled false
        }
        release {
            signingConfig signingConfigs.release
            debuggable true
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = "1.8"
    }
    lintOptions {
        abortOnError true
    }

    testOptions.unitTests {
        includeAndroidResources = true
        all {
            useJUnitPlatform()
            testLogging {
                events 'started', 'passed', 'skipped', 'failed'
                exceptionFormat "full"
                showStandardStreams true
            }
        }
    }
}

tasks.configureEach { task ->
    if (task.taskIdentity.type.toString() == "class org.jetbrains.kotlin.gradle.tasks.KotlinCompile") {
        task.kotlinOptions {
            freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
        }
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "androidx.core:core-ktx:1.7.0"
    implementation "androidx.appcompat:appcompat:1.4.1"
    implementation "androidx.activity:activity-ktx:1.4.0"
    implementation "androidx.fragment:fragment-ktx:1.4.1"
    implementation "com.google.android.material:material:1.5.0"
    implementation "androidx.constraintlayout:constraintlayout:2.1.3"

    // Coroutines
    def coroutine_version = "1.6.0"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutine_version"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutine_version"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1"
    implementation "androidx.fragment:fragment-ktx:1.4.1"

    def glide_version = "4.11.0"
    implementation "com.github.bumptech.glide:glide:$glide_version"
    kapt "com.github.bumptech.glide:compiler:$glide_version"

    def okhttp_version = "4.9.3"
    implementation "com.squareup.retrofit2:retrofit:2.9.0"
    implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
    implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:11.0.1'

    def junit_version = "5.7.0"
    testImplementation "org.junit.jupiter:junit-jupiter-engine:$junit_version"
    testImplementation "org.junit.jupiter:junit-jupiter-params:$junit_version"
    testImplementation 'com.jraska.livedata:testing-ktx:1.2.0'
    testImplementation "org.mockito.kotlin:mockito-kotlin:4.0.0"
    testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version"
    testImplementation "commons-io:commons-io:2.8.0"
    testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutine_version"
    testImplementation "androidx.arch.core:core-testing:2.1.0"

    androidTestImplementation "androidx.test.ext:junit:1.1.3"
    androidTestImplementation "androidx.test.espresso:espresso-core:3.4.0"
}