/*
 * Copyright (C) 2022 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.testing"
        withAndroidTestOnDeviceBuilder {
            it.compilationName = "instrumentedTest"
            it.defaultSourceSetName = "androidInstrumentedTest"
            it.sourceSetTreeName = "test"
        }
    }

    defaultPlatform(PlatformIdentifier.ANDROID)

    sourceSets {
        commonMain {
            dependencies {
                api(libs.kotlinStdlib)
                implementation(project(":paging:paging-common"))
            }
        }

        commonJvmMain {
            dependsOn(commonMain)
        }

        jvmMain {
            dependsOn(commonJvmMain)
        }

        androidMain {
            dependsOn(commonJvmMain)
        }

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

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

        jvmTest {
            dependsOn(commonJvmTest)
        }

        androidInstrumentedTest {
            dependsOn(commonJvmTest)
            dependencies {
                implementation(libs.testRunner)
            }
        }

        nativeMain {
            dependsOn(commonMain)
            dependencies {
                implementation(libs.atomicFu)
            }
        }
        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}")
                    }
                }
            }
        }
    }
}

androidx {
    name = "Paging Testing Extensions"
    type = LibraryType.PUBLISHED_TEST_LIBRARY
    inceptionYear = "2022"
    description = "Test artifact for Paging implementation"
    kotlinTarget = KotlinTarget.KOTLIN_1_9
}

