/*
 * Copyright (C) 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.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 {
    jvm()
    mac()
    linux()
    ios()
    watchos()
    tvos()
    androidLibrary {
        namespace = "androidx.paging.common"
        withAndroidTestOnDeviceBuilder {
            it.compilationName = "instrumentedTest"
            it.defaultSourceSetName = "androidInstrumentedTest"
            it.sourceSetTreeName = "test"
        }
    }

    defaultPlatform(PlatformIdentifier.JVM)

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

        commonJvmAndroidMain {
            dependsOn(commonMain)

            dependencies {
                api("androidx.arch.core:core-common:2.2.0")
            }
        }

        jvmMain {
            dependsOn(commonJvmAndroidMain)
        }

        androidMain {
            dependsOn(commonJvmAndroidMain)
        }

        commonTest {
            dependencies {
                implementation(libs.kotlinCoroutinesTest)
                implementation(libs.kotlinTest)
                implementation(project(":kruth:kruth"))
                implementation(project(":internal-testutils-paging"))
            }
        }

        commonJvmAndroidTest {
            dependsOn(commonTest)
            dependencies {
                implementation(libs.junit)
                implementation(libs.mockitoCore)
                implementation(libs.mockitoKotlin)
                implementation(project(":internal-testutils-common"))
                implementation(project(":internal-testutils-ktx"))
            }
        }

        jvmTest {
            dependsOn(commonJvmAndroidTest)
        }

        androidInstrumentedTest {
            dependsOn(commonJvmAndroidTest)
            dependencies {
                implementation(libs.testRunner)
                implementation(libs.mockitoAndroid5)
            }
        }

        nativeMain {
            dependsOn(commonMain)
            dependencies {
                implementation(libs.atomicFu)
            }
        }
        nativeTest {
            dependsOn(commonTest)
        }

        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 ||
                            konanTargetFamily == Family.WATCHOS ||
                            konanTargetFamily == Family.TVOS) {
                        dependsOn(darwinMain)
                    } else if (konanTargetFamily == Family.LINUX) {
                        dependsOn(linuxMain)
                    } else {
                        throw new GradleException("unknown native target ${target}")
                    }
                }
                target.compilations["test"].defaultSourceSet {
                    dependsOn(nativeTest)
                }
            }
        }
    }
}

androidx {
    name = "Paging-Common"
    type = LibraryType.PUBLISHED_LIBRARY
    inceptionYear = "2017"
    description = "Android Paging-Common"
    legacyDisableKotlinStrictApiMode = true
    kotlinTarget = KotlinTarget.KOTLIN_1_9
    samples(project(":paging:paging-samples"))
}
