import com.android.build.api.dsl.LibraryExtension
import dev.carlosmartino.plugins.configureKotlinAndroid
import dev.carlosmartino.plugins.configureKotlinMultiplatform
import dev.carlosmartino.plugins.libs
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

class KotlinMultiplatformConventionPlugin : Plugin<Project> {
    override fun apply(target: Project) =
        with(target) {
            with(pluginManager) {
                apply(libs.findPlugin("androidLibrary").get().get().pluginId)
                apply(libs.findPlugin("kotlinMultiplatform").get().get().pluginId)
                apply(libs.findPlugin("kotlinSerialization").get().get().pluginId)
            }

            extensions.configure<KotlinMultiplatformExtension>(::configureKotlinMultiplatform)
            extensions.configure<LibraryExtension>(::configureKotlinAndroid)
        }
}
