package dev.carlosmartino.plugins

import com.android.build.api.dsl.LibraryExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.kotlin.dsl.get

internal fun Project.configureKotlinAndroid(
    extension: LibraryExtension,
) = extension.apply {
    val moduleName = path.split(":").drop(2).joinToString(".")
    namespace = if (moduleName.isNotEmpty()) "dev.carlosmartino.$moduleName" else "dev.carlosmartino.platform"

    compileSdk = libs.findVersion("android.compileSdk")
        .get()
        .requiredVersion
        .toInt()
    defaultConfig {
        minSdk = libs.findVersion("android.minSdk")
            .get()
            .requiredVersion
            .toInt()
        consumerProguardFiles("consumer-proguard-rules.pro")
    }

    sourceSets["main"].resources.srcDirs("src/commonMain/composeResources")

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_21
        targetCompatibility = JavaVersion.VERSION_21
    }
    packaging {
        resources {
            excludes += "/META-INF/{AL2.0,LGPL2.1}"
        }
    }
}
