// Copyright (C) 2026 Jason M. Schwefel. All Rights Reserved.
plugins {
    alias(libs.plugins.kotlin.multiplatform)
    alias(libs.plugins.android.library)
    alias(libs.plugins.kotlin.serialization)
}

kotlin {
    androidTarget {
        compilations.all {
            kotlinOptions {
                jvmTarget = "17"
            }
        }
    }

    jvm {
        compilations.all {
            kotlinOptions {
                jvmTarget = "17"
            }
        }
    }

    sourceSets {
        commonMain.dependencies {
            implementation(libs.kotlin.stdlib)
        }
        commonTest.dependencies {
            implementation(libs.kotlin.test)
        }
        jvmTest.dependencies {
            implementation(libs.kotlin.test.junit)
            implementation(libs.kotlinx.serialization.json)
        }
    }
}

android {
    namespace  = "com.coldboreballisticsllc.scopedope.ballistics"
    compileSdk = 35

    defaultConfig {
        minSdk = 31
    }

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

// ── Ballistics validation test configuration ──────────────────────────────────

// Resolve test data relative to this module's parent (scopedope-shared root),
// regardless of whether it is built from scopedope-android or standalone.
val testDataDir: String = projectDir.parentFile.resolve("ballistics-test-data/test_cases").absolutePath
// Reports are written to the module's persistent reports/ dir (scopedope-shared/ballistics/reports),
// not build/, so timestamped runs survive `gradle clean`.
val reportDir:   String = projectDir.resolve("reports").absolutePath

tasks.named<Test>("jvmTest") {
    systemProperty("ballistics.testdata.dir", testDataDir)
    systemProperty("ballistics.report.dir",   reportDir)

    // Always execute: this is a validation+report task. Never let Gradle skip it as
    // UP-TO-DATE or restore it from the build cache — it must run and emit a fresh
    // timestamped report on every invocation.
    outputs.upToDateWhen { false }
    outputs.cacheIf { false }

    doFirst {
        file(reportDir).mkdirs()
    }

    testLogging {
        events("passed", "failed", "skipped")
        showStandardStreams = true
    }
}

// Real-world fired DOPE is merged into the single test_cases/ dataset above. Each such
// case carries `realworld: true` and is scored against the wider field band per-case
// (see ExhaustiveCVRunner); there is no separate task or dataset.
