plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'kotlin-kapt'
    id 'dagger.hilt.android.plugin'
    id 'kotlin-parcelize'
    id "org.jlleitschuh.gradle.ktlint"
    id "io.gitlab.arturbosch.detekt"
    id "com.diffplug.spotless"
    id 'jacoco'
    id 'org.jetbrains.dokka'
}

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {

    reports {
        xml.enabled = true
        html.enabled = true
    }

    def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
    def debugTree = fileTree(dir: "${buildDir}/intermediates/classes/debug", excludes: fileFilter)
    def mainSrc = "${project.projectDir}/src/main/java"

    sourceDirectories.setFrom(files([mainSrc]))
    classDirectories.setFrom(files([debugTree]))
    executionData.setFrom(fileTree(dir: "$buildDir", includes: [
            "jacoco/testDebugUnitTest.exec",
            "outputs/code-coverage/connected/*coverage.ec"
    ]))
}

android {
    compileSdk 32

    defaultConfig {
        applicationId "com.example.livescore"
        minSdk 21
        targetSdk 32
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        vectorDrawables {
            useSupportLibrary true
        }
    }

    testOptions {
        unitTests.all {
            jacoco {
                includeNoLocationClasses = true
                excludes = ['jdk.internal.*']
            }
        }
        unitTests.returnDefaultValues = true
    }

    buildTypes {
        debug {
            testCoverageEnabled true
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
    buildFeatures {
        compose true
    }



    composeOptions {
        kotlinCompilerExtensionVersion compose_version
    }
    packagingOptions {
        resources {
            excludes += '/META-INF/{AL2.0,LGPL2.1}'
        }
    }
}

dependencies {

    implementation 'androidx.core:core-ktx:1.7.0'
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
    implementation 'androidx.activity:activity-compose:1.3.1'

    // Compose dependencies
    implementation "androidx.lifecycle:lifecycle-viewmodel-compose:1.0.0-alpha07"
    implementation "androidx.navigation:navigation-compose:2.4.0-alpha08"
    implementation "com.google.accompanist:accompanist-flowlayout:0.17.0"

    //leak canary to detect memory leaks
    debugImplementation("com.squareup.leakcanary:leakcanary-android:2.7")

    // Coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1'

    // Coroutine Lifecycle Scopes
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
    implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.3.1"

    //detect static analysis
    detekt "io.gitlab.arturbosch.detekt:detekt-formatting:1.18.1"
    detekt("io.gitlab.arturbosch.detekt:detekt-cli:1.18.1")

    //Dagger - Hilt
    implementation "com.google.dagger:hilt-android:2.38.1"
    kapt "com.google.dagger:hilt-android-compiler:2.37"
    implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
    kapt "androidx.hilt:hilt-compiler:1.0.0"
    implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha03'

    //chucker
    debugImplementation("com.github.chuckerteam.chucker:library:3.5.2")
    releaseImplementation("com.github.chuckerteam.chucker:library-no-op:3.5.2")

    // Retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation "com.squareup.okhttp3:okhttp:5.0.0-alpha.2"
    implementation "com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2"

    implementation "com.google.accompanist:accompanist-swiperefresh:0.24.2-alpha"

    implementation "com.google.accompanist:accompanist-navigation-animation:0.16.0"

    implementation 'androidx.palette:palette:1.0.0'

    implementation"io.coil-kt:coil-compose:2.1.0"
    implementation("io.coil-kt:coil-gif:2.1.0")

    implementation "androidx.room:room-runtime:2.4.2"
    kapt "androidx.room:room-compiler:2.4.2"

   debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
    
    // Kotlin Extensions and Coroutines support for Room
    implementation "androidx.room:room-ktx:2.4.2"
    implementation 'com.google.code.gson:gson:2.9.0'

    implementation "com.google.accompanist:accompanist-pager:0.13.0"
    implementation "com.google.accompanist:accompanist-pager-indicators:0.13.0"

    // Testing

    androidTestImplementation "junit:junit:4.13.2"
    androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4"
    androidTestImplementation "androidx.arch.core:core-testing:2.1.0"
    androidTestImplementation "com.google.truth:truth:1.1.3"
    androidTestImplementation 'androidx.test:core-ktx:1.4.0'
    androidTestImplementation "com.squareup.okhttp3:mockwebserver:4.9.1"
    testImplementation 'org.mockito:mockito-android:3.10.0'
    testImplementation "org.mockito:mockito-inline:3.11.2"
    testImplementation "org.mockito.kotlin:mockito-kotlin:3.2.0"
    testImplementation "io.mockk:mockk:1.12.7"
    testImplementation 'org.mockito:mockito-core:3.11.2'
    androidTestImplementation 'org.mockito:mockito-android:3.10.0'
    androidTestImplementation 'com.google.dagger:hilt-android-testing:2.42'
    kaptAndroidTest 'com.google.dagger:hilt-android-compiler:2.38.1'
    testImplementation 'junit:junit:4.13.2'
    testImplementation "androidx.test:runner:1.4.0"
    testImplementation "com.google.truth:truth:1.1.3"
    testImplementation 'androidx.test:core-ktx:1.4.0'
    testImplementation "org.robolectric:robolectric:4.5.1"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4"
    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'
    androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
    debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
    debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
}