plugins {
    // Apply the shared build logic from a convention plugin.
    // The shared code is located in `buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts`.
    id("buildsrc.convention.kotlin-jvm")
    alias(libs.plugins.tempolin)
    id("app.cash.sqldelight") version "2.0.2"

    // Apply the Application plugin to add support for building an executable JVM application.
    application
}

dependencies {
    implementation("app.cash.sqldelight:sqlite-driver:2.0.2")
    // implementation("org.xerial:sqlite-jdbc:3.48.0.0")
    implementation("com.fasterxml.jackson.core:jackson-databind:2.18.2")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.+")
    implementation(libs.slf4jsimple)
    implementation(libs.javalin)
    implementation(libs.commonsText)
    implementation(project(":core"))
    testImplementation(kotlin("test"))
}

application {
    // Define the Fully Qualified Name for the application main class
    // (Note that Kotlin compiles `App.kt` to a class with FQN `com.example.app.AppKt`.)
    mainClass = "net.h34t.filemure.ServerKt"
}

sourceSets {
    main {
        kotlin {
            // include the generated source files
            srcDir("${layout.buildDirectory.get()}/generated-sources/tempolin")
        }
    }
}

tasks.getByName("compileKotlin") {
    dependsOn("tempolin")
}

tempolin {
    add {
        // place all templates in this directory
        // subdirectories become packages
        templateDirectory = "$projectDir/src/main/tpl"

        // output directory for the generated templates
        outputDirectory = "${layout.buildDirectory.get()}/generated-sources/tempolin"

        // currently, there's only the "kotlin" generator
        // optional, default is "kotlin"
        compilationTarget = "kotlin"

        // an optional input file filter
        fileFilter = { file -> file.extension == "html" }

        // set the name and package of the template interface
        // defaults to "net.h34t.TempolinTemplate"
        templateInterface = "net.h34t.filemure.Template"

    }
}

sqldelight {
    databases {
        create("Database") {
            packageName.set("net.h34t.filemure.db")
        }
    }
}