plugins {
    kotlin("jvm")
    kotlin("plugin.serialization")
    id("com.gradleup.shadow")
    id("xyz.jpenilla.run-paper")
    id("org.jetbrains.dokka")
}

repositories {
    maven("https://repo.papermc.io/repository/maven-public/") {
        name = "papermc-repo"
    }
}

dependencies {
    // Engine module (provides serialization, coroutines, ktor)
    api(project(":engine"))

    // Paper-specific dependencies
    compileOnly("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
    implementation("com.charleskorn.kaml:kaml:0.104.0") // YAML configuration
    implementation("org.jetbrains.kotlin:kotlin-reflect:2.3.10") // Annotation processing

    // Test dependencies
    testImplementation("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
    testImplementation("io.mockk:mockk:1.14.9")
    testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.10.2")
}

tasks {
    shadowJar {
        archiveClassifier.set("")
        archiveBaseName.set("LunaticChat")
    }

    jar {
        enabled = false
    }

    runServer {
        minecraftVersion("1.21")
    }

    processResources {
        val gitCommitHash =
            providers
                .exec {
                    commandLine("git", "rev-parse", "--short", "HEAD")
                }.standardOutput
                .asText
                .get()
                .trim()

        val props = mapOf("version" to project.version, "gitCommitHash" to gitCommitHash)
        inputs.properties(props)
        filteringCharset = "UTF-8"
        filesMatching("paper-plugin.yml") {
            expand(props)
        }
        filesMatching("build-info.properties") {
            expand(props)
        }
    }

    build {
        dependsOn(shadowJar)
    }
}
