/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

import org.apache.tools.ant.taskdefs.condition.Os
import java.net.URI
import java.util.*

pluginManagement {
    plugins {
        kotlin("plugin.lombok") version "2.3.20"
    }
}

rootProject.name = "SteamWar"

private val isInCi by lazy { Os.isFamily(Os.FAMILY_UNIX) && ProcessBuilder("hostname").start().inputStream.bufferedReader().readText().startsWith("steamwar.de") }

dependencyResolutionManagement {
    repositories {
        maven {
            url = URI("https://m2.dv8tion.net/releases")
            content {
                includeGroup("net.dv8tion")
            }
        }

        maven {
            url = URI("https://maven.enginehub.org/repo")
            content {
                includeGroup("com.sk89q.worldedit")
                includeGroup("com.sk89q.worldedit.worldedit-libs")
            }
        }

        maven {
            if (isInCi) {
                url = URI("file:///var/www/maven/")
            } else {
                url = URI("https://maven.steamwar.de/")
                credentials {
                    val swProps = Properties()
                    swProps.load(rootDir.resolve("steamwar.properties").inputStream())

                    username = swProps.getProperty("maven.username")
                    password = swProps.getProperty("maven.password")
                }
            }

            content {
                includeGroup("de.steamwar")
            }
        }

        maven {
            url = URI("https://repo.codemc.io/repository/maven-snapshots/")
            content {
                includeGroup("net.wesjd")
            }
        }

        maven {
            url = URI("https://libraries.minecraft.net")
            content {
                includeGroup("com.mojang")
            }
        }

        maven {
            url = URI("https://repo.viaversion.com")
            content {
                includeGroup("com.viaversion")
            }
        }

        maven {
            url = URI("https://repo.papermc.io/repository/maven-public/")
            content {
                includeGroup("org.bukkit")
                includeGroup("org.spigotmc")
                includeGroup("io.papermc.paper")
                includeGroup("com.velocitypowered")
                includeGroup("net.md-5")
            }
        }
        mavenCentral()
    }

    versionCatalogs {
        create("libs") {
            plugin("shadow", "com.github.johnrengelman.shadow").version("8.1.1")

            library("lombok", "org.projectlombok:lombok:1.18.32")
            library("luaj", "org.luaj:luaj-jse:3.0.1")
            library("sqlite", "org.xerial:sqlite-jdbc:3.46.0.0")
            library("mysql", "mysql:mysql-connector-java:8.0.33")
            library("fastutil", "it.unimi.dsi:fastutil:8.5.6")
            library("netty", "io.netty:netty-all:4.1.68.Final")
            library("junit", "junit:junit:4.13.2")
            library("hamcrest", "org.hamcrest:hamcrest:2.2")
            library("classindex", "org.atteo.classindex:classindex:3.13")

            library("paperapi", "io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT")
            library("authlib", "com.mojang:authlib:6.0.58")
            library("datafixer", "com.mojang:datafixerupper:4.0.26")
            library("brigadier", "com.mojang:brigadier:1.0.18")
            library("anvilgui", "net.wesjd:anvilgui:1.10.6-SNAPSHOT")

            library("nms", "de.steamwar:spigot:1.21.6")

            library("axiom", "de.steamwar:axiompaper:RELEASE")
            library("fawe", "de.steamwar:fastasyncworldedit:1.21")

            library("velocity", "de.steamwar:velocity:RELEASE")
            library("velocityapi", "com.velocitypowered:velocity-api:3.5.0-SNAPSHOT")
            library("viaapi", "com.viaversion:viaversion-api:4.3.1")
            library("viavelocity", "com.viaversion:viaversion-velocity:4.3.1")
            library("jda", "net.dv8tion:JDA:5.5.1")
            library("msgpack", "org.msgpack:msgpack-core:0.9.8")

            library("logback", "ch.qos.logback:logback-classic:1.5.6")
            library("coroutinesCore", "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")

            val ktorVersion = "2.3.12"

            library("ktor", "io.ktor:ktor-server-core-jvm:$ktorVersion")
            library("ktorContentNegotiation", "io.ktor:ktor-server-content-negotiation-jvm:$ktorVersion")
            library("ktorCors", "io.ktor:ktor-server-cors-jvm:$ktorVersion")
            library("ktorSerialization", "io.ktor:ktor-serialization-kotlinx-json-jvm:$ktorVersion")
            library("ktorNetty", "io.ktor:ktor-server-netty-jvm:$ktorVersion")
            library("ktorHost", "io.ktor:ktor-server-host-common-jvm:$ktorVersion")
            library("ktorRequestValidation", "io.ktor:ktor-server-request-validation:$ktorVersion")
            library("ktorAuth", "io.ktor:ktor-server-auth:$ktorVersion")
            library("ktorAuthJvm", "io.ktor:ktor-server-auth-jvm:$ktorVersion")
            library("ktorAuthSession", "io.ktor:ktor-server-sessions:$ktorVersion")
            library("ktorClientCore", "io.ktor:ktor-client-core-jvm:$ktorVersion")
            library("ktorClientJava", "io.ktor:ktor-client-java:$ktorVersion")
            library("ktorClientContentNegotiation", "io.ktor:ktor-client-content-negotiation:$ktorVersion")
            library("ktorClientAuth", "io.ktor:ktor-client-auth:$ktorVersion")

            library("yamlconfig", "org.bspfsystems:yamlconfiguration:1.3.0")
            library("kotlinxSerializationCbor", "org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.4.1")
            library("ktorRateLimit", "io.ktor:ktor-server-rate-limit:$ktorVersion")

            library("nbt", "dev.dewy:nbt:1.5.1")

            val exposedVersion = "1.3.0"
            library("exposedCore", "org.jetbrains.exposed:exposed-core:$exposedVersion")
            library("exposedDao", "org.jetbrains.exposed:exposed-dao:$exposedVersion")
            library("exposedJdbc", "org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
            library("exposedTime", "org.jetbrains.exposed:exposed-java-time:$exposedVersion")
        }
    }
}

include(
    "AccessWidener"
)

include(
    "BauSystem",
    "BauSystem:BauSystem_Main",
    "BauSystem:BauSystem_RegionDynamic",
    "BauSystem:BauSystem_RegionFixed"
)

include("CommandFramework")

include("CLI")

include(
    "CommonCore",
    "CommonCore:Data",
    "CommonCore:SQL",
    "CommonCore:Network",
    "CommonCore:Linkage"
)

include(
    "FightSystem",
    "FightSystem:FightSystem_Core",
    "FightSystem:FightSystem_Standalone"
)

include("KotlinCore")

include("LobbySystem")

include("MissileWars")

include("Realtime")

include("SchematicSystem")

include(
    "SpigotCore",
    "SpigotCore:CRIUDummy",
    "SpigotCore:SpigotCore_Main"
)

include("Teamserver")

include("TowerRun")

include("TutorialSystem")

include(
    "VelocityCore",
    "VelocityCore:Dependencies",
    "VelocityCore:Persistent"
)

include("TNTLeague")
include("WebsiteBackend")
