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

plugins {
    id("AndroidXPlugin")
    id("com.android.library")
}

androidXMultiplatform {
    android()
    desktop()
    mac()
    linux()
    ios()

    defaultPlatform(PlatformIdentifier.ANDROID)

    sourceSets {
        configureEach {
            languageSettings.optIn("kotlin.contracts.ExperimentalContracts")
        }

        commonMain {
            dependencies {
                api("androidx.annotation:annotation:1.8.1")
                api(libs.kotlinStdlib)
                api(libs.kotlinCoroutinesCore)
            }
        }

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

        jvmCommonMain {
            dependsOn(commonMain)
        }

        jvmCommonTest {
            dependsOn(commonTest)
            dependencies {
                implementation(libs.junit)
            }
        }

        androidMain {
            dependsOn(jvmCommonMain)
            dependencies {
                api(libs.kotlinCoroutinesAndroid)
                implementation(projectOrArtifact(":core:core-viewtree"))
            }
        }

        androidUnitTest {
            dependsOn(jvmCommonTest)
            dependencies {
                implementation(libs.mockitoCore4)
            }
        }

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

        desktopMain.dependsOn(jvmCommonMain)
        nonJvmCommonMain.dependsOn(commonMain)
        nativeMain.dependsOn(nonJvmCommonMain)
        darwinMain.dependsOn(nativeMain)
        linuxMain.dependsOn(nativeMain)

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

android {
    buildTypes.configureEach {
        consumerProguardFiles "proguard-rules.pro"
    }
    namespace = "androidx.lifecycle.viewmodel"
}

androidx {
    name = "Lifecycle ViewModel"
    type = LibraryType.PUBLISHED_LIBRARY
    inceptionYear = "2017"
    description = "Android Lifecycle ViewModel"
    metalavaK2UastEnabled = false
}
