/*
 * 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.KotlinTarget
import androidx.build.LibraryType
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"
        withAndroidTestOnDeviceBuilder {
            it.compilationName = "instrumentedTest"
            it.defaultSourceSetName = "androidInstrumentedTest"
            it.sourceSetTreeName = "test"
        }
        withAndroidTestOnJvmBuilder {
            it.defaultSourceSetName = "androidUnitTest"
            it.compilationName = "unitTest"
        }
    }
    desktop()
    mac()
    linux()
    ios()

    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 {
                implementation(libs.robolectric)
            }
        }

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

        targets.configureEach { target ->
            if (target.platformType == org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType.native) {
                target.compilations["main"].defaultSourceSet {
                    def konanTargetFamily = target.konanTarget.family
                    if (konanTargetFamily == org.jetbrains.kotlin.konan.target.Family.OSX || konanTargetFamily == org.jetbrains.kotlin.konan.target.Family.IOS) {
                        dependsOn(darwinMain)
                    } else if (konanTargetFamily == org.jetbrains.kotlin.konan.target.Family.LINUX) {
                        dependsOn(linuxMain)
                    } else {
                        throw new GradleException("unknown native target ${target}")
                    }
                }
                target.compilations["test"].defaultSourceSet {
                    def konanTargetFamily = target.konanTarget.family
                    if (konanTargetFamily == org.jetbrains.kotlin.konan.target.Family.OSX || konanTargetFamily == org.jetbrains.kotlin.konan.target.Family.IOS) {
                        dependsOn(darwinTest)
                    } else if (konanTargetFamily == org.jetbrains.kotlin.konan.target.Family.LINUX) {
                        dependsOn(linuxTest)
                    } else {
                        throw new GradleException("unknown native target ${target}")
                    }
                }
            }
        }
    }
}

androidx {
    name = "Lifecycle ViewModel Testing"
    type = LibraryType.PUBLISHED_TEST_LIBRARY
    inceptionYear = "2024"
    description = "Testing utilities for 'lifecycle-viewmodel' artifact"
    kotlinTarget = KotlinTarget.KOTLIN_1_9
}

