/**
 * 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.LibraryType
import androidx.build.PlatformIdentifier
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

plugins {
    id("AndroidXPlugin")
    id("com.android.library")
    id("androidx.baselineprofile")
}
androidXMultiplatform {
    android()
    desktop()
    mac()
    linux()
    ios()

    defaultPlatform(PlatformIdentifier.ANDROID)

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

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

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

        desktopMain {
            dependsOn(jvmCommonMain)
        }

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

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

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

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

        nonJvmCommonMain {
            dependsOn(commonMain)
        }

        nativeMain {
            dependsOn(nonJvmCommonMain)

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

        nativeTest {
            dependsOn(commonTest)
        }

        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)
                }
            }
        }
    }
}

dependencies {
    api(libs.jspecify)
    lintPublish(project(":lifecycle:lifecycle-runtime-lint"))
}

android {
    buildTypes.configureEach {
        consumerProguardFiles "proguard-rules.pro"
    }

    // Include `*.java` files into the build
    sourceSets["main"].java.srcDir("src/androidMain/java")
    sourceSets["test"].java.srcDir("src/androidUnitTest/kotlin")
    namespace = "androidx.lifecycle.runtime"
    // TODO(b/345531033)
    experimentalProperties["android.lint.useK2Uast"] = false
}

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