/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * 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

plugins {
    id("AndroidXPlugin")
    id("AndroidXComposePlugin")
    alias(libs.plugins.kotlinSerialization)
}

androidXMultiplatform {
    androidLibrary {
        compileSdk = 35
        namespace = "androidx.lifecycle.viewmodel.compose"
    }
    jvmStubs()
    linuxX64Stubs()

    defaultPlatform(PlatformIdentifier.ANDROID)

    sourceSets {
        commonMain {
            dependencies {
                api(project(":lifecycle:lifecycle-common"))
                api(project(":lifecycle:lifecycle-viewmodel"))
                api("androidx.annotation:annotation:1.9.1")
                api("androidx.compose.runtime:runtime:1.9.0")
                api(libs.kotlinSerializationCore)
                implementation(libs.kotlinStdlib)
            }
        }

        commonTest {
            dependencies {
                implementation(project(":lifecycle:lifecycle-viewmodel-savedstate"))
                implementation(project(":lifecycle:lifecycle-viewmodel-testing"))
                implementation(project(":lifecycle:lifecycle-runtime-testing"))
            }
        }

        androidMain {
            dependsOn(commonMain)
            dependencies {
                api(project(":lifecycle:lifecycle-viewmodel-savedstate"))
                api("androidx.compose.ui:ui:1.9.0")
                // Converting `lifecycle-viewmodel-compose` to KMP and including a transitive
                // dependency on `lifecycle-livedata-core` triggered a Gradle bug. Adding the
                // `livedata` dependency directly works around the issue.
                // See https://github.com/gradle/gradle/issues/14220 for details.
                compileOnly(project(":lifecycle:lifecycle-livedata-core"))
            }
        }

        androidInstrumentedTest {
            dependsOn(commonTest)
            dependencies {
                implementation(project(":compose:ui:ui-test-junit4"))
                implementation(project(":compose:test-utils"))
                implementation(libs.testRules)
                implementation(libs.testRunner)
                implementation(libs.junit)
                implementation(libs.truth)
                implementation("androidx.fragment:fragment:1.3.0")
                implementation("androidx.appcompat:appcompat:1.3.0")
                // old version of common-java8 conflicts with newer version, because both have
                // DefaultLifecycleEventObserver.
                // Outside of androidx this is resolved via constraint added to lifecycle-common,
                // but it doesn't work in androidx.
                // See aosp/1804059
                implementation(project(":lifecycle:lifecycle-common-java8"))
                implementation("androidx.activity:activity-compose:1.10.1")
            }
        }

        nonAndroidMain {
            dependsOn(commonMain)
        }

        jvmStubsMain {
            dependsOn(nonAndroidMain)
        }

        linuxx64StubsMain {
            dependsOn(nonAndroidMain)
        }
    }
}

dependencies {
    lintPublish(project(":lifecycle:lifecycle-viewmodel-compose-lint"))
}

androidx {
    name = "Lifecycle ViewModel Compose"
    type = SoftwareType.PUBLISHED_LIBRARY_ONLY_USED_BY_KOTLIN_CONSUMERS
    inceptionYear = "2021"
    description = "Compose integration with Lifecycle ViewModel"
    samples(project(":lifecycle:lifecycle-viewmodel-compose:lifecycle-viewmodel-compose-samples"))
}
