plugins {
    alias(libs.plugins.android.application)
    alias(libs.plugins.kotlin.serialization)
    alias(libs.plugins.kotlin.compose)
}

android {
    namespace = "de.ladkau.deckinadash"
    compileSdk = 36
    ndkVersion = "30.0.14904198"

    defaultConfig {
        applicationId = "de.ladkau.deckinadash"
        minSdk = 24
        targetSdk = 36
        versionCode = 1
        versionName = "0.0.0-dev"

        ndk {
            abiFilters += listOf("arm64-v8a", "x86_64")
        }
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
        }
    }

    externalNativeBuild {
        cmake {
            path = file("src/main/jni/CMakeLists.txt")
            version = "3.22.1"
        }
    }

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_17
        targetCompatibility = JavaVersion.VERSION_17
    }

    buildFeatures {
        compose = true
    }
}

// Regenerates app/src/main/res/drawable-nodpi/<slug>.webp from
// ../../res/img/*.jpeg (see ../../scripts/gen_card_images.py) and syncs
// engine/i18n/*.lang into app/src/main/assets/i18n/ - both are gitignored
// generated output, so a fresh checkout needs them produced before any
// resource-merge/asset-packaging task runs. Mirrors watch/wscript's own
// "generate before the SDK tooling packs resources" fix - see that
// file's own comment for the ordering bug this exact pattern avoids.
val generateCardArt = tasks.register<Exec>("generateCardArt") {
    workingDir = rootDir
    commandLine("python3", "scripts/gen_card_images.py")
}

val generateLauncherIcon = tasks.register<Exec>("generateLauncherIcon") {
    workingDir = rootDir
    commandLine("python3", "scripts/gen_launcher_icon.py")
}

val syncI18n = tasks.register<Copy>("syncI18n") {
    from("${rootDir}/../engine/i18n")
    include("*.lang")
    into("src/main/assets/i18n")
}

tasks.named("preBuild") {
    dependsOn(generateCardArt, generateLauncherIcon, syncI18n)
}

dependencies {
    implementation(libs.androidx.core.ktx)
    implementation(libs.androidx.lifecycle.runtime.ktx)
    implementation(libs.androidx.lifecycle.viewmodel.compose)
    implementation(libs.androidx.activity.compose)
    implementation(platform(libs.androidx.compose.bom))
    implementation(libs.androidx.ui)
    implementation(libs.androidx.ui.graphics)
    implementation(libs.androidx.ui.tooling.preview)
    implementation(libs.androidx.material3)
    implementation(libs.androidx.material.icons.core)
    implementation(libs.androidx.navigation.compose)
    implementation(libs.androidx.datastore.preferences)
    implementation(libs.androidx.work.runtime.ktx)
    implementation(libs.kotlinx.serialization.json)
    implementation(libs.kotlinx.coroutines.android)
    debugImplementation(libs.androidx.ui.tooling)
}
