/**
 * This file was created using the `create_project.py` script located in the
 * `<AndroidX root>/development/project-creator` directory.
 *
 * Please use that script when creating a new project, rather than copying an existing project and
 * modifying its settings.
 */

import androidx.build.SoftwareType
import androidx.build.PlatformIdentifier
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
    id("AndroidXPlugin")
}

androidXMultiplatform {
    androidLibrary {
        namespace = "androidx.lifecycle.runtime"
        withJava()
        optimization {
            it.consumerKeepRules.publish = true
            it.consumerKeepRules.files.add(new File("proguard-rules.pro"))
        }
        androidResources.enable = true
        // Needed for api tasks and docs generation
        sourceSets {
            androidMain {
                kotlin.srcDirs += 'src/androidMain/java'
            }
        }
    }
    desktop()
    mac()
    linux()
    ios()
    watchos()
    tvos()
    mingwX64()
    js()
    wasmJs()

    defaultPlatform(PlatformIdentifier.ANDROID)

    sourceSets {
        commonMain {
            dependencies {
                api(libs.kotlinStdlib)
                api(project(":lifecycle:lifecycle-common"))
                api("androidx.annotation:annotation:1.9.1")
            }
        }

        commonTest {
            dependencies {
                implementation(project(":internal-testutils-lifecycle"))
                implementation(libs.kotlinCoroutinesTest)
                implementation(libs.kotlinTest)
                implementation(project(":kruth:kruth"))
                implementation(libs.atomicFu)
            }
        }

        jvmMain {
            dependsOn(commonMain)
            dependencies {
                api("androidx.arch.core:core-common:2.2.0")
            }
        }

        jvmTest {
            dependsOn(commonTest)
        }

        desktopMain {
            dependsOn(jvmMain)
        }

        desktopTest {
            dependsOn(jvmTest)
            dependencies {
                implementation(libs.kotlinCoroutinesSwing)
            }
        }

        androidMain {
            dependsOn(jvmMain)
            dependencies {
                api(libs.kotlinCoroutinesAndroid)
                api(libs.jspecify)
                implementation("androidx.core:core-viewtree:1.0.0")
                implementation("androidx.arch.core:core-runtime:2.2.0")
                implementation("androidx.profileinstaller:profileinstaller:1.4.0")
            }
        }

        androidUnitTest {
            dependsOn(jvmTest)
            dependencies {
                implementation(libs.junit)
                implementation(libs.mockitoCore4)
            }
        }

        androidInstrumentedTest {
            dependsOn(jvmTest)
            dependencies {
                implementation("androidx.core:core-viewtree:1.0.0")
                implementation(libs.junit)
                implementation(libs.truth)
                implementation(libs.testExtJunit)
                implementation(libs.testCore)
                implementation(libs.testRunner)
                implementation(libs.kotlinCoroutinesTest)
            }
        }

        nonJvmMain {
            dependsOn(commonMain)
        }

        nonJvmTest {
            dependsOn(commonTest)
        }

        nativeMain {
            dependsOn(nonJvmMain)

            // Required for WeakReference usage
            languageSettings.optIn("kotlin.experimental.ExperimentalNativeApi")
        }

        nativeTest {
            dependsOn(commonTest)
        }

        webMain {
            dependsOn(nonJvmMain)
        }

        webTest {
            dependsOn(nonJvmTest)
            dependencies {
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.9.0")
                implementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.9.0")
            }
        }

        targets.configureEach { target ->
            if (target.platformType == KotlinPlatformType.native) {
                target.compilations["main"].defaultSourceSet {
                    dependsOn(nativeMain)

                    // Required for WeakReference usage
                    languageSettings.optIn("kotlin.experimental.ExperimentalNativeApi")
                }
                target.compilations["test"].defaultSourceSet {
                    dependsOn(nativeTest)
                }
            } else if (target.platformType in [KotlinPlatformType.js, KotlinPlatformType.wasm]) {
                target.compilations["main"].defaultSourceSet.dependsOn(webMain)
                target.compilations["test"].defaultSourceSet.dependsOn(webTest)
            }
        }
    }
}

dependencies {
    lintPublish(project(":lifecycle:lifecycle-runtime-lint"))

    constraints {
        // Prevents symbols duplication with old versions of JetBrains' fork.
        // Starting with version 2.9.2, this module is published as empty artifact with dependency
        // to this androidx module.
        // TODO: update this constrain to 2.9.3 once out due to https://youtrack.jetbrains.com/issue/CMP-8765
        commonMainImplementation("org.jetbrains.androidx.lifecycle:lifecycle-runtime:2.9.2") {
            because "prevents symbols duplication"
        }
    }
}

androidx {
    name = "Lifecycle Runtime"
    type = SoftwareType.PUBLISHED_LIBRARY
    inceptionYear = "2017"
    description = "Android Lifecycle Runtime"
}
