// Use the .github folder as a way to find the root directory.
// Without this, the plugins module will not be able to use this script without hacks.
File rootDirectory = rootDir
while (!rootDirectory.listFiles().any { it.isDirectory() && it.name == ".github" }) {
    rootDirectory = rootDirectory.parentFile
}

def kotlinVersion = '1.9.21'

def versions = [
        dagger                         : '2.45',
        kotlin                         : kotlinVersion,
        mviCore                        : '2.0.0',
        robolectric                    : '4.13',
        composeBom                     : '2023.10.01',
        composeCompiler                : '1.5.7',

        materialVersion                : '1.4.0', // https://github.com/material-components/material-components-android/releases
        androidxAnnotationVersion      : '1.2.0', // https://developer.android.com/jetpack/androidx/releases/annotation
        androidxAppCompatVersion       : '1.4.1', // https://developer.android.com/jetpack/androidx/releases/appcompat
        androidxArchCoreVersion        : '2.1.0', // https://developer.android.com/jetpack/androidx/releases/arch-core
        androidxBrowserVersion         : '1.3.0', // https://developer.android.com/jetpack/androidx/releases/browser
        androidxBroadcastVersion       : '1.0.0', // https://developer.android.com/jetpack/androidx/releases/localbroadcastmanager
        androidxCardViewVersion        : '1.0.0', // https://developer.android.com/jetpack/androidx/releases/cardview
        androidxCollectionVersion      : '1.0.0', // https://developer.android.com/jetpack/androidx/releases/collection
        androidxConstraintLayoutVersion: '1.1.3', // https://developer.android.com/jetpack/androidx/releases/constraintlayout & https://androidstudio.googleblog.com/
        androidxCoreVersion            : '1.9.0', // https://developer.android.com/jetpack/androidx/releases/core
        androidxExifVersion            : '1.1.0', // https://developer.android.com/jetpack/androidx/releases/exifinterface
        androidxFragmentVersion        : '1.3.6', // https://developer.android.com/jetpack/androidx/releases/fragment
        androidxActivityVersion        : '1.6.1', // https://developer.android.com/jetpack/androidx/releases/activity
        androidxGridLayoutVersion      : '1.0.0', // https://developer.android.com/jetpack/androidx/releases/gridlayout
        androidxLifecycleVersion       : '2.6.1', // https://developer.android.com/jetpack/androidx/releases/lifecycle
        androidxLoaderVersion          : '1.0.0', // https://developer.android.com/jetpack/androidx/releases/loader
        androidxPaletteVersion         : '1.0.0', // https://developer.android.com/jetpack/androidx/releases/palette
        androidxPercentLayoutVersion   : '1.0.0', // https://developer.android.com/jetpack/androidx/releases/percentlayout
        androidxRecyclerViewVersion    : '1.1.0', // https://developer.android.com/jetpack/androidx/releases/recyclerview
        androidxSavedStateVersion      : '1.2.0', // https://developer.android.com/jetpack/androidx/releases/savedstate
        androidxTestVersion            : '1.5.0', // https://developer.android.com/jetpack/androidx/releases/test
        androidxTestUiAutoVersion      : '2.2.0',
        retrofitVersion                : '2.11.0',
        okhttp                         : '3.14.7',
        leakCanary                     : '2.9.1',
        jacoco                         : '0.8.8',
        junit5                         : '5.7.1',
        coil                           : '1.3.1',
        appyx                          : '1.2.0',
]

def apt = [
        daggerCompiler: "com.google.dagger:dagger-compiler:${versions.dagger}",
        javax         : "javax.annotation:jsr250-api:1.0",
        javaxInject   : "javax.inject:javax.inject:1",
]

def agp = 'com.android.tools.build:gradle:8.9.1'

def build = [
        compileSdk      : 34,
        gradlePluginsUrl: "https://plugins.gradle.org/m2/",
        ci              : 'true' == System.getenv('CI'),
        minSdk          : 21,
        targetSdk       : 33,
        guava           : "com.google.guava:guava:20.0",
        gradlePlugins   : [
                android     : agp,
                kotlin      : "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}",
                detekt      : 'io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.21.0',
                jacoco      : "org.jacoco:org.jacoco.core:${versions.jacoco}"
        ]
]

def android = [
        annotations     : "androidx.annotation:annotation:${versions.androidxAnnotationVersion}",
        appCompat       : "androidx.appcompat:appcompat:${versions.androidxAppCompatVersion}",
        lifecycleCommon : "androidx.lifecycle:lifecycle-common-java8:${versions.androidxLifecycleVersion}",
        constraintLayout: "androidx.constraintlayout:constraintlayout:${versions.androidxConstraintLayoutVersion}",
        design          : "com.google.android.material:material:${versions.materialVersion}",
        percent         : "androidx.percentlayout:percentlayout:${versions.androidxPercentLayoutVersion}",
        runner          : "androidx.test:runner:${versions.androidxTestVersion}",
        recyclerView    : "androidx.recyclerview:recyclerview:${versions.androidxRecyclerViewVersion}",
        rules           : "androidx.test:rules:${versions.androidxTestVersion}",
        activity        : "androidx.activity:activity-ktx:${versions.androidxActivityVersion}",
        fragment        : "androidx.fragment:fragment-ktx:${versions.androidxFragmentVersion}",
        browser         : "androidx.browser:browser:${versions.androidxBrowserVersion}",
        archCoreTesting : "androidx.arch.core:core-testing:${versions.androidxArchCoreVersion}",
        savedState      : "androidx.savedstate:savedstate:${versions.androidxSavedStateVersion}",
]

def compose = [
        bom : "androidx.compose:compose-bom:${versions.composeBom}"
]

def test = [
        junit4        : "junit:junit:4.12",
        junitApi      : "org.junit.jupiter:junit-jupiter-api:${versions.junit5}",
        junitParams   : "org.junit.jupiter:junit-jupiter-params:${versions.junit5}",
        junitEngine   : "org.junit.jupiter:junit-jupiter-engine:${versions.junit5}",
        junitVintage  : "org.junit.vintage:junit-vintage-engine:${versions.junit5}",
        mockitoKotlin : "org.mockito.kotlin:mockito-kotlin:5.4.0",
        assertj       : "org.assertj:assertj-core:2.9.1", // 2.x version is Android compatible
]

def androidTest = [
        espresso       : 'androidx.test.espresso:espresso-core:3.5.0',
        espressoIntents: 'androidx.test.espresso:espresso-intents:3.5.0',
        runner         : "androidx.test:runner:${versions.androidxTestVersion}",
        rules          : "androidx.test:rules:${versions.androidxTestVersion}"
]

def external = [
        kotlinStdlib       : "org.jetbrains.kotlin:kotlin-stdlib-jdk7",
        dagger             : "com.google.dagger:dagger:${versions.dagger}",
        mviCore            : "com.github.badoo.mvicore:mvicore:${versions.mviCore}",
        mviCoreAndroid     : "com.github.badoo.mvicore:mvicore-android:${versions.mviCore}",
        mviCoreBinder      : "com.github.badoo.mvicore:binder:${versions.mviCore}",
        mviCoreDiff        : "com.github.badoo.mvicore:mvicore-diff:${versions.mviCore}",
        rxjava3            : "io.reactivex.rxjava3:rxjava:3.1.10",
        rxrelay3           : "com.jakewharton.rxrelay3:rxrelay:3.0.1",
        rxandroid3         : "io.reactivex.rxjava3:rxandroid:3.0.2",
        roboelectricBase   : "org.robolectric:robolectric:${versions.robolectric}",
        coil               : "io.coil-kt:coil:${versions.coil}",
        leakCanary         : "com.squareup.leakcanary:leakcanary-android:${versions.leakCanary}",
        appyxCustomisations: "com.bumble.appyx:customisations:${versions.appyx}",
]

def retrofit = [
        retrofit                : "com.squareup.retrofit2:retrofit:${versions.retrofitVersion}",
        rxjavaAdapter           : "com.squareup.retrofit2:adapter-rxjava3:${versions.retrofitVersion}",
        moshiConverter          : "com.squareup.retrofit2:converter-moshi:${versions.retrofitVersion}",
        okhttp                  : "com.squareup.okhttp3:okhttp:${versions.okhttp}",
        okhttpLoggingInterceptor: "com.squareup.okhttp3:logging-interceptor:${versions.okhttp}",
        moshiKotlin             : "com.squareup.moshi:moshi-kotlin:1.11.0",
]

ext.deps = [
        "apt"        : apt,
        "build"      : build,
        "compose"    : compose,
        "external"   : external,
        "android"    : android,
        "test"       : test,
        "androidTest": androidTest,
        "versions"   : versions,
        "retrofit"   : retrofit,
]
