import io.github.droidkaigi.feeder.Dep
import io.github.droidkaigi.feeder.Versions

plugins {
    id("kotlin-multiplatform")
    id("kotlinx-serialization")
    id("kotlin-kapt")
    id("com.android.library")
}

apply from: rootProject.file("gradle/android.gradle")

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile.class).all {
    kotlinOptions {
        jvmTarget = "1.8"
        freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
        freeCompilerArgs += ["-Xallow-jvm-ir-dependencies"]
    }
}

kotlin {
    android()

    // The multiplatform libraries do not support hierarchical structures, which breaks the IDE's completion.
    // https://kotlinlang.org/docs/mpp-share-on-platforms.html#share-code-on-similar-platforms
    def iosTargets = [
            iosArm64(),
            iosX64("ios")
    ]
    iosTargets.forEach {
        it.binaries.forEach {
            it.linkerOpts.add("-lsqlite3")
        }
    }

    sourceSets {
        commonMain.dependencies {
            api projects.model
            api projects.data.api
            api projects.data.db

            implementation Dep.Coroutines.bom
            implementation (Dep.Coroutines.core) {
                version {
                    strictly Versions.coroutines
                }
            }
        }
        commonTest.dependencies {
            implementation Dep.KotlinTest.common
            implementation Dep.KotlinTest.annotationCommon
        }
//        jvmMain
//        jvmTest.dependencies {
//            implementation Dep.KotlinTest.junit
//            implementation Dep.Kotlin.reflect
//            implementation Dep.ktlint
//        }
        androidMain.dependencies {
            // Hilt
            implementation Dep.Dagger.hiltAndroid

            // For local unit tests
//            testImplementation "com.google.dagger:hilt-android-testing:2.31.2-alpha"
//            kaptTest Dep.Dagger.hiltAndroidCompiler
        }
        androidTest.dependencies {
            implementation Dep.KotlinTest.junit
            implementation Dep.Kotlin.reflect
            implementation Dep.ktlint
        }
        androidAndroidTest {
            kotlin {
                srcDir 'src/androidTest'
            }
        }
        iosMain.dependencies {
            implementation Dep.Koin.core
        }
        iosArm64Main.dependsOn(iosMain)
    }
}

dependencies {
    kapt Dep.Dagger.hiltAndroidCompiler
}
