import com.android.build.gradle.LibraryPlugin
import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    alias libs.plugins.android.application apply false
    alias libs.plugins.android.library apply false
    alias libs.plugins.kotlin.android apply false
    alias libs.plugins.kotlin.compose apply false
    alias libs.plugins.ksp apply false
    alias libs.plugins.hilt apply false
    alias libs.plugins.detekt
    alias libs.plugins.dokka
    alias libs.plugins.sonarqube
    alias libs.plugins.jacoco
    alias libs.plugins.binary.compatibility.validator
    alias libs.plugins.resolve.dependencies
}

apply from: "config/gradle/sonarcloud.gradle"
apply from: "config/gradle/apiValidator.gradle"
apply from: "config/gradle/dependencyList.gradle"

ext {
    if (project.hasProperty("version-name")) {
        versionName = project.property("version-name")
    } else {
        versionName = "develop"
    }
    checkoutRedirectScheme = "adyencheckout"
}

subprojects {
    def javaVersion = 11

    plugins.withType(com.android.build.gradle.BasePlugin).configureEach {
        android {
            if (project.hasProperty("strip-resources") && project.property("strip-resources") == "true") {
                defaultConfig {
                    resConfigs "en", "xxhdpi"
                }

                buildTypes {
                    debug {
                        crunchPngs false
                    }
                }
            }

            compileOptions {
                sourceCompatibility = javaVersion
                targetCompatibility = javaVersion
            }

            packagingOptions {
                excludes += "/META-INF/{AL2.0,LGPL2.1}"
                merges += "META-INF/LICENSE.md"
                merges += "META-INF/LICENSE-notice.md"
            }
        }
    }

    plugins.withType(LibraryPlugin).configureEach {
        dependencies {
            lintChecks project(':lint')
        }
    }

    plugins.withType(KotlinAndroidPluginWrapper).configureEach {
        kotlin {
            jvmToolchain(javaVersion)
        }
    }

    tasks.withType(KotlinCompile).configureEach {
        kotlinOptions {
            freeCompilerArgs += [
                '-opt-in=kotlin.RequiresOptIn',
            ]
        }
    }

    tasks.withType(Test).configureEach {
        useJUnitPlatform()
    }
}

dependencies {
    dokka(project(':3ds2'))
    dokka(project(':ach'))
    dokka(project(':action'))
    dokka(project(':action-core'))
    dokka(project(':await'))
    dokka(project(':bacs'))
    dokka(project(':bcmc'))
    dokka(project(':blik'))
    dokka(project(':boleto'))
    dokka(project(':card'))
    dokka(project(':card-scanning'))
    dokka(project(':cashapppay'))
    dokka(project(':checkout-core'))
    dokka(project(':components-compose'))
    dokka(project(':components-core'))
    dokka(project(':convenience-stores-jp'))
    dokka(project(':core'))
    dokka(project(':cse'))
    dokka(project(':dotpay'))
    dokka(project(':drop-in'))
    dokka(project(':drop-in-compose'))
    dokka(project(':econtext'))
    dokka(project(':entercash'))
    dokka(project(':eps'))
    dokka(project(':giftcard'))
    dokka(project(':googlepay'))
    dokka(project(':ideal'))
    dokka(project(':instant'))
    dokka(project(':issuer-list'))
    dokka(project(':mbway'))
    dokka(project(':meal-voucher-fr'))
    dokka(project(':molpay'))
    dokka(project(':online-banking-core'))
    dokka(project(':online-banking-cz'))
    dokka(project(':online-banking-jp'))
    dokka(project(':online-banking-pl'))
    dokka(project(':online-banking-sk'))
    dokka(project(':openbanking'))
    dokka(project(':paybybank'))
    dokka(project(':paybybank-us'))
    dokka(project(':payeasy'))
    dokka(project(':payto'))
    dokka(project(':qr-code'))
    dokka(project(':redirect'))
    dokka(project(':seven-eleven'))
    dokka(project(':sepa'))
    dokka(project(':sessions-core'))
    dokka(project(':twint'))
    dokka(project(':twint-action'))
    dokka(project(':ui'))
    dokka(project(':ui-core'))
    dokka(project(':upi'))
    dokka(project(':voucher'))
    dokka(project(':wechatpay'))
}

apply from: file('config/gradle/dependencyGraph.gradle')
