import com.android.build.api.dsl.ApplicationExtension
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.kotlin.dsl.configure

class AndroidApplicationConventionPlugin : Plugin<Project> {
    override fun apply(target: Project): Unit = with(target) {
        with(pluginManager) {
            apply("com.android.application")
            apply("org.jetbrains.kotlin.android")
        }

        extensions.configure<ApplicationExtension> {
            configureAndroidCommon(this)
            val libs = libs
            defaultConfig {
                targetSdk = libs.findVersion("targetSdk").get().toString().toInt()
                versionCode = libs.findVersion("versionCode").get().toString().toInt()
                versionName = libs.findVersion("versionName").get().toString()
            }
        }

        dependencies.add(
            "coreLibraryDesugaring",
            "com.android.tools:desugar_jdk_libs:2.1.3"
        )
    }
}
