/*
 * (C) Copyright IBM Deutschland GmbH 2021
 * (C) Copyright IBM Corp. 2021
 */

dependencies {
    ext {
        // ------------------------------------------------------------------------------------------------
        // Expose correct dependency version constraints, so our dependents can
        // leave out the version number and automatically get the correct version.
        // Additionally, we ensure a consistent set of versions here.
        // ------------------------------------------------------------------------------------------------
        versionConstraints = {
            api platform("org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.7.3")
            api platform("io.ktor:ktor-bom:1.6.8")
            api platform("com.ensody.reactivestate:reactivestate-bom:5.6.0")
            api platform("com.squareup.okhttp3:okhttp-bom:4.11.0")

            constraints {
                // While kotlin-stdlib and kotlin-stdlib-common are automatically set by the gradle plugin,
                // a few older dependencies still want kotlin-stdlib-jdk7 or kotlin-reflect based on a different Kotlin
                // version. Make everything consistent and prevent compilation warnings.
                api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
                api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
                api "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"

                api "org.conscrypt:conscrypt-android:2.5.2"

                def bouncyCastleVersion = "1.76"
                api "org.bouncycastle:bcprov-jdk15to18:$bouncyCastleVersion"
                api "org.bouncycastle:bcprov-jdk15on:$bouncyCastleVersion"
                api "org.bouncycastle:bcmail-jdk15to18:$bouncyCastleVersion"
                api "org.bouncycastle:bcmail-jdk15on:$bouncyCastleVersion"
                api "org.bouncycastle:bcpkix-jdk15to18:$bouncyCastleVersion"
                api "org.bouncycastle:bcpkix-jdk15on:$bouncyCastleVersion"

                api "com.upokecenter:cbor:4.5.2"
                api "com.augustcellars.cose:cose-java:1.1.0"
            }
        }
        // ------------------------------------------------------------------------------------------------

        testDependency = { dependency ->
            if (project.name.endsWith("-test")) {
                api dependency
            } else {
                testImplementation dependency
            }
        }

        base = {
            versionConstraints()

            testDependency "junit:junit:4.13.2"
            testDependency "org.jetbrains.kotlin:kotlin-test-junit"
            testDependency "org.jetbrains.kotlinx:kotlinx-coroutines-test"
            testDependency "io.mockk:mockk:1.13.7"
        }

        fragmentVersion = "1.6.1"
        baseAndroid = {
            base()
            api "androidx.annotation:annotation:1.6.0"
            api "androidx.core:core-ktx:1.10.1"

            testImplementation("org.robolectric:robolectric:4.10.3") {
                exclude group: "org.bouncycastle"
            }
            testImplementation "org.bouncycastle:bcprov-jdk15to18"
            testImplementation "org.bouncycastle:bcpkix-jdk15to18"
            testDependency "androidx.arch.core:core-testing:2.2.0"
            testDependency "androidx.fragment:fragment-testing:$fragmentVersion"

            def androidxTestVersion = "1.5.0"
            testDependency "androidx.test:core:$androidxTestVersion"
            testDependency "androidx.test:core-ktx:$androidxTestVersion"
            testDependency "androidx.test:runner:$androidxTestVersion"
            testDependency "androidx.test:rules:$androidxTestVersion"

            testDependency "androidx.test.ext:junit:1.1.3"
            testDependency "androidx.test.ext:junit-ktx:1.1.3"
        }

        reactiveState = {
            api "com.ensody.reactivestate:reactivestate"
            testDependency "com.ensody.reactivestate:reactivestate-test"
        }

        activityVersion = "1.8.0"
        androidUI = {
            baseAndroid()
            coroutines()

            api "com.google.android.material:material:1.7.0"
            api "androidx.appcompat:appcompat:1.6.1"

            api "androidx.activity:activity-ktx:$activityVersion"
            api "androidx.fragment:fragment-ktx:$fragmentVersion"

            def lifecycleVersion = "2.6.2"
            api "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
            api "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
            api "androidx.lifecycle:lifecycle-viewmodel-savedstate:$lifecycleVersion"
            api "androidx.lifecycle:lifecycle-process:$lifecycleVersion"
            constraints {
                api "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
                api "androidx.lifecycle:lifecycle-service:$lifecycleVersion"
            }

            api "androidx.constraintlayout:constraintlayout:2.1.4"
            api "com.airbnb.android:lottie:6.1.0"
        }

        conscrypt = {
            api "org.conscrypt:conscrypt-android"
        }

        coroutines = {
            api "org.jetbrains.kotlinx:kotlinx-coroutines-core"
            testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test"
        }

        timber = {
            implementation "com.jakewharton.timber:timber:5.0.1"
        }

        ktor = {
            coroutines()

            api "io.ktor:ktor-client-android"
            api "io.ktor:ktor-client-core"
            api "io.ktor:ktor-client-json-jvm"
            api "io.ktor:ktor-client-okhttp"
            api "io.ktor:ktor-client-serialization"

            api "com.squareup.okhttp3:okhttp"
            api "com.squareup.okhttp3:logging-interceptor"

            testImplementation "io.ktor:ktor-client-mock-jvm"
        }

        coseJava = {
            api("com.augustcellars.cose:cose-java") {
                exclude group: "org.bouncycastle"
            }
            bouncyCastle()
        }

        bouncyCastle = {
            api "org.bouncycastle:bcprov-jdk15to18"
            api "org.bouncycastle:bcpkix-jdk15to18"
        }

        zxing = {
            api "com.journeyapps:zxing-android-embedded:4.3.0"
            api "com.google.zxing:core:3.5.2"
        }

        camerax = {
            def cameraxVersion = "1.3.0"
            api "androidx.camera:camera-core:$cameraxVersion"
            api "androidx.camera:camera-camera2:$cameraxVersion"
            api "androidx.camera:camera-lifecycle:$cameraxVersion"
            api "androidx.camera:camera-view:$cameraxVersion"
        }

        def boofCVVersion = "1.0.0"
        boofCV = {
            api("org.boofcv:boofcv-core:$boofCVVersion") {
                exclude group: "xmlpull", module: "xmlpull"
                exclude group: "org.apache.commons", module: "commons-compress"
                exclude group: "com.thoughtworks.xstream", module: "commons-compress"
            }
            api "org.boofcv:boofcv-android:$boofCVVersion"
        }

        boofCVTest = {
            testDependency "org.boofcv:boofcv-core:$boofCVVersion"
            testDependency "org.boofcv:boofcv-android:$boofCVVersion"
        }

        cryptographic = {
            api "androidx.security:security-crypto:1.1.0-alpha03"
        }

        kotlinxSerialization = {
            def kotlinxSerializationVersion = "1.5.1"
            api "org.jetbrains.kotlinx:kotlinx-serialization-core:$kotlinxSerializationVersion"
            api "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$kotlinxSerializationVersion"
            api "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlinxSerializationVersion"
        }

        certLogic = {
            api "eu.ehn.dcc.certlogic:certlogic-kotlin:v0.11.2-kotlin"
            api "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.0"
        }

        inAppUpdate = {
            api "com.google.android.play:app-update-ktx:2.1.0"
        }

        room = {
            def roomVersion = "2.5.2"
            api "androidx.room:room-ktx:$roomVersion"
            api "androidx.room:room-runtime:$roomVersion"
            kapt "androidx.room:room-compiler:$roomVersion"
        }

        clockSync = {
            api "com.lyft.kronos:kronos-android:0.0.1-alpha11"
        }
    }
}
