/*
 * Copyright (C) 2016 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.dsl.ExplicitApiMode
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

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

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("androidx.lifecycle:lifecycle-common:2.9.0-alpha07")
                api("androidx.lifecycle:lifecycle-runtime:2.9.0-alpha07")
                api("androidx.lifecycle:lifecycle-viewmodel:2.9.0-alpha07")
                api("androidx.lifecycle:lifecycle-viewmodel-savedstate:2.9.0-alpha07")
                api("androidx.savedstate:savedstate:1.3.0-alpha05")
                api(libs.kotlinStdlib)
                implementation("androidx.collection:collection:1.4.2")
                implementation(libs.kotlinSerializationCore)
            }
        }
        commonTest {
            dependencies {
                implementation(libs.kotlinTest)
            }
        }

        nonAndroidMain {
            dependsOn(commonMain)
        }
        nonAndroidTest {
            dependsOn(commonTest)
        }
        jvmCommonMain {
            dependsOn(commonMain)
        }
        jvmCommonTest {
            dependsOn(commonTest)
        }
        desktopMain {
            dependsOn(jvmCommonMain)
            dependsOn(nonAndroidMain)
        }
        desktopTest {
            dependsOn(jvmCommonTest)
            dependsOn(nonAndroidTest)
        }
        androidMain {
            dependsOn(jvmCommonMain)
            dependencies {
                api("androidx.lifecycle:lifecycle-runtime-ktx:2.9.0-alpha07")
                api("androidx.lifecycle:lifecycle-viewmodel-ktx:2.9.0-alpha07")
                api("androidx.savedstate:savedstate-ktx:1.3.0-alpha05")
                implementation("androidx.core:core-ktx:1.1.0")
                implementation("androidx.profileinstaller:profileinstaller:1.4.0")
            }
        }

        androidUnitTest {
            dependsOn(commonTest)
            dependencies {
                implementation(project(":navigation:navigation-testing"))
                implementation("androidx.arch.core:core-testing:2.2.0")
                implementation(libs.junit)
                implementation(libs.mockitoCore4)
                implementation(libs.truth)
                implementation(libs.kotlinCoroutinesCore)
                implementation(libs.kotlinCoroutinesTest)
            }
        }

        androidInstrumentedTest {
            dependsOn(commonTest)
            dependencies {
                implementation(libs.junit)
                implementation(libs.testExtJunit)
                implementation(libs.testRunner)
                implementation(libs.truth)
                implementation(libs.mockitoCore)
                implementation(libs.dexmakerMockito)
            }
        }

        nonJvmCommonMain {
            dependsOn(nonAndroidMain)
        }

        nonJvmCommonTest {
            dependsOn(nonAndroidTest)
        }

        nativeMain {
            dependsOn(nonJvmCommonMain)
        }
        linuxMain.dependsOn(nativeMain)
        darwinMain.dependsOn(nativeMain)

        nativeTest {
            dependsOn(nonJvmCommonTest)
        }
        linuxTest.dependsOn(nativeTest)
        darwinTest.dependsOn(nativeTest)

        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 == org.jetbrains.kotlin.konan.target.Family.LINUX) {
                    target.compilations["main"].defaultSourceSet.dependsOn(linuxMain)
                    target.compilations["test"].defaultSourceSet.dependsOn(linuxTest)
                }
            }
        }
    }
}

android {
    buildTypes.configureEach {
        consumerProguardFiles "proguard-rules.pro"
    }
    namespace = "androidx.navigation.common"
}

dependencies {
    androidTestRuntimeOnly(libs.kotlinTestJunit)
    androidTestRuntimeOnly(libs.testCore)

    lintPublish(project(":navigation:navigation-common-lint"))
}

androidx {
    name = "Navigation Common"
    type = LibraryType.PUBLISHED_LIBRARY
    inceptionYear = "2017"
    description = "Android Navigation-Common"
    kotlinTarget = KotlinTarget.KOTLIN_1_9
}
