// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        min_sdk = 21
        target_sdk = 33
        app_version_name = ''
        app_version_code = 0

        accompanist_version = '0.28.0'
        amplitude_version = '1.6.1'
        appcompat_version = '1.6.1'
        coil_version = '2.2.2'
        compose_version = '1.3.3'
        core_ktx_version = '1.9.0'
        coroutines_version = '1.6.4'
        daggerhilt_version = '2.44.2'
        firebase_bom = '31.2.0'
        kotlin_version = '1.8.10'
        ktlint_version = '0.48.2'
        lifecycle_version = '2.5.1'
        markwon_version = '4.6.2'
        moshi_version = '1.14.0'
        navigation_version = '2.5.3'
        okhttp_version = '4.10.0'
        play_wearables_version = '18.0.0'
        play_auth_version = '20.4.1'
        preferences_version = '1.2.0'
        realm_version = '1.0.2'
        retrofit_version = '2.9.0'
        recyclerview_version = '1.2.1'
    }

    repositories {
        google()
        maven { url "https://plugins.gradle.org/m2/" }
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.4.1'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.google.gms:google-services:4.3.15'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.2'
        classpath "io.realm:realm-gradle-plugin:10.11.0"
        classpath("io.realm.kotlin:gradle-plugin:$realm_version")
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.19.0"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version"
        classpath 'com.google.firebase:perf-plugin:1.4.2'
        classpath "com.google.dagger:hilt-android-gradle-plugin:$daggerhilt_version"
        classpath "org.jlleitschuh.gradle:ktlint-gradle:11.1.0"
    }
}

apply plugin: 'io.gitlab.arturbosch.detekt'

allprojects {
    apply plugin: "org.jlleitschuh.gradle.ktlint"
    repositories {
        google()
        mavenCentral()
    }
}

Properties props = new Properties()
def propFile = new File('version.properties')
if (propFile.canRead()) {
    props.load(new FileInputStream(propFile))

    if (props != null && props.containsKey('NAME') && props.containsKey('CODE') ) {
        ext.app_version_name = props['NAME']
        ext.app_version_code = props['CODE'] as Integer
    } else {
        println 'signing.properties found but some entries are missing'
        android.buildTypes.release.signingConfig = null
    }
} else {
    println 'signing.properties not found'
    android.buildTypes.release.signingConfig = null
}

detekt {
    source = files("Habitica/src/main/java")
    config = files("detekt.yml")
    baseline = file("${rootProject.projectDir}/detekt_baseline.xml")
    reports {
        xml {
            enabled = true
            destination = file("build/reports/detekt.xml")
        }
        html {
            enabled = true
            destination = file("build/reports/detekt.html")
        }
        sarif {
            enabled = true
            destination = file("build/reports/detekt.sarif")
        }
    }
}

tasks.named("detekt").configure {
    reports {
        xml.required.set(false)
        html.required.set(true)
        html.outputLocation.set(file("build/reports/detekt.html"))
        txt.required.set(false)
        sarif.required.set(true)
        sarif.outputLocation.set(file("build/reports/detekt.sarif"))
    }
}