/*
 * Copyright (C) 2021 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.
 */


import androidx.build.KotlinTarget
import androidx.build.PlatformIdentifier
import androidx.build.LibraryType
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType

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

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

    defaultPlatform(PlatformIdentifier.ANDROID)

    sourceSets {
        commonMain {
            dependencies {
                api(libs.kotlinStdlib)
                api("androidx.paging:paging-common:3.3.2")
                api(project(":room:room-runtime"))
            }
        }

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

        androidMain {
            dependsOn(commonMain)
        }

        jvmNativeMain {
            dependsOn(commonMain)
        }

        jvmMain {
            dependsOn(jvmNativeMain)
        }

        nativeMain {
            dependsOn(jvmNativeMain)
            dependencies {
                implementation(libs.atomicFu)
            }
        }

        androidInstrumentedTest {
            dependsOn(commonTest)
            dependencies {
                implementation(libs.junit)
                implementation(project(":internal-testutils-common"))
                implementation(libs.kotlinTestJunit)
                implementation(libs.testExtJunit)
                implementation(libs.testCore)
                implementation(libs.testRunner)
                implementation("androidx.arch.core:core-testing:2.2.0")
                implementation("androidx.paging:paging-testing:3.3.2")
            }
        }
        targets.configureEach { target ->
            if (target.platformType == KotlinPlatformType.native) {
                target.compilations["main"].defaultSourceSet {
                    dependsOn(nativeMain)
                }
            }
        }
    }
}

android {
    namespace = "androidx.room.paging"
}

dependencies {
    add("kspAndroidAndroidTest", project(":room:room-compiler"))
}

androidx {
    name = "Room Paging"
    type = LibraryType.PUBLISHED_LIBRARY
    inceptionYear = "2021"
    description = "Room Paging integration"
    kotlinTarget = KotlinTarget.KOTLIN_2_0
}

ksp {
    useKsp2 = true
}
