/*
 * Copyright 2024 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
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.konan.target.Family

plugins {
    id("AndroidXPlugin")
}

androidXMultiplatform {
    androidLibrary {
        namespace = "androidx.lifecycle.viewmodel.testing"
    }
    desktop()
    mac()
    linux()
    ios()
    watchos()
    tvos()
    mingwX64()
    js()
    wasmJs()

    defaultPlatform(PlatformIdentifier.ANDROID)

    sourceSets {
        commonMain {
            dependencies {
                api(project(":lifecycle:lifecycle-viewmodel"))
                api(libs.kotlinStdlib)
                api(libs.kotlinCoroutinesCore)
                implementation(project(":lifecycle:lifecycle-runtime"))
                implementation(project(":lifecycle:lifecycle-runtime-testing"))
                implementation(project(":lifecycle:lifecycle-viewmodel-savedstate"))
            }
        }

        commonTest {
            dependencies {
                implementation(project(":kruth:kruth"))
                implementation(libs.kotlinTest)
                implementation(libs.kotlinCoroutinesTest)
            }
        }

        jvmMain {
            dependsOn(commonMain)
        }

        jvmTest {
            dependsOn(commonTest)
        }

        androidMain {
            dependsOn(commonMain)
            dependsOn(jvmMain)
        }

        androidUnitTest {
            dependsOn(commonTest)
            dependsOn(jvmTest)
            dependencies {
            }
        }

        androidInstrumentedTest {
            dependsOn(commonTest)
            dependsOn(jvmTest)
            dependencies {
                implementation("androidx.core:core-ktx:1.2.0")
                implementation(libs.testExtJunit)
                implementation(libs.testCore)
                implementation(libs.testRunner)
            }
        }

        nonAndroidMain {
            dependsOn(commonMain)
        }

        nonAndroidTest {
            dependsOn(commonTest)
        }

        desktopMain {
            dependsOn(jvmMain)
            dependsOn(nonAndroidMain)
        }

        desktopTest {
            dependsOn(jvmTest)
            dependsOn(nonAndroidTest)
        }

        nativeMain {
            dependsOn(commonMain)
            dependsOn(nonAndroidMain)
        }

        nativeTest {
            dependsOn(commonTest)
            dependsOn(nonAndroidTest)
        }

        darwinMain {
            dependsOn(nativeMain)
        }

        darwinTest {
            dependsOn(nativeTest)
        }

        linuxMain {
            dependsOn(nativeMain)
        }

        linuxTest {
            dependsOn(nativeTest)
        }

        mingwMain {
            dependsOn(nativeMain)
        }

        mingwTest {
            dependsOn(nativeTest)
        }

        webMain {
            dependsOn(nonAndroidMain)
        }

        webTest {
            dependsOn(nonAndroidTest)
            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) {
                if (target.konanTarget.family.appleFamily) {
                    target.compilations["main"].defaultSourceSet.dependsOn(darwinMain)
                    target.compilations["test"].defaultSourceSet.dependsOn(darwinTest)
                } else if (target.konanTarget.family == Family.LINUX) {
                    target.compilations["main"].defaultSourceSet.dependsOn(linuxMain)
                    target.compilations["test"].defaultSourceSet.dependsOn(linuxTest)
                } else if (target.konanTarget.family == Family.MINGW) {
                    target.compilations["main"].defaultSourceSet.dependsOn(mingwMain)
                    target.compilations["test"].defaultSourceSet.dependsOn(mingwTest)
                } else {
                    target.compilations["main"].defaultSourceSet.dependsOn(nativeMain)
                    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)
            }
        }
    }
}

androidx {
    name = "Lifecycle ViewModel Testing"
    type = SoftwareType.PUBLISHED_TEST_LIBRARY
    inceptionYear = "2024"
    description = "Testing utilities for 'lifecycle-viewmodel' artifact"
    enableRobolectric()
}
