/*
 *   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.Properties

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://repo.lunarclient.dev")
            content {
                includeGroup("com.lunarclient")
            }
        }

        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("spigotapi", "org.spigotmc:spigot-api:1.20-R0.1-SNAPSHOT")
            library("spigotannotations", "org.spigotmc:plugin-annotations:1.2.3-SNAPSHOT")
            library("paperapi", "io.papermc.paper:paper-api:1.19.2-R0.1-SNAPSHOT")
            library("paperapi21", "io.papermc.paper:paper-api:1.21.6-R0.1-SNAPSHOT")
            library("authlib", "com.mojang:authlib:1.5.25")
            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("nms8", "de.steamwar:spigot:1.8")
            library("nms9", "de.steamwar:spigot:1.9")
            library("nms10", "de.steamwar:spigot:1.10")
            library("nms12", "de.steamwar:spigot:1.12")
            library("nms14", "de.steamwar:spigot:1.14")
            library("nms15", "de.steamwar:spigot:1.15")
            library("nms18", "de.steamwar:spigot:1.18")
            library("nms19", "de.steamwar:spigot:1.19")
            library("nms20", "de.steamwar:spigot:1.20")
            library("nms21", "de.steamwar:spigot:1.21.6")

            library("axiom", "de.steamwar:axiompaper:RELEASE")
            library("worldedit12", "de.steamwar:worldedit:1.12")
            library("worldedit15", "de.steamwar:worldedit:1.15")
            library("fawe18", "de.steamwar:fastasyncworldedit:1.18")
            library("fawe21", "de.steamwar:fastasyncworldedit:1.21")

            library("velocity", "de.steamwar:velocity:RELEASE")
            library("velocityapi", "com.velocitypowered:velocity-api:3.3.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("apolloprotos", "com.lunarclient:apollo-protos:1.0-SNAPSHOT")

            library("logback", "ch.qos.logback:logback-classic:1.5.6")

            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("ktorAuthLdap", "io.ktor:ktor-server-auth-ldap-jvm:$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")
        }
    }
}

include(
    "BauSystem",
    "BauSystem:BauSystem_15",
    "BauSystem:BauSystem_18",
    "BauSystem:BauSystem_19",
    "BauSystem:BauSystem_20",
    "BauSystem:BauSystem_21",
    "BauSystem:BauSystem_Main",
    "BauSystem:BauSystem_RegionFixed"
)

include("CommandFramework")

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

include(
    "FightSystem",
    "FightSystem:FightSystem_8",
    "FightSystem:FightSystem_9",
    "FightSystem:FightSystem_10",
    "FightSystem:FightSystem_12",
    "FightSystem:FightSystem_14",
    "FightSystem:FightSystem_15",
    "FightSystem:FightSystem_18",
    "FightSystem:FightSystem_19",
    "FightSystem:FightSystem_20",
    "FightSystem:FightSystem_21",
    "FightSystem:FightSystem_Core",
    "FightSystem:FightSystem_Standalone"
)

include("KotlinCore")

include("LegacyBauSystem")

include("LobbySystem")

include("MissileWars")

include("Realtime")

include(
    "SchematicSystem",
    "SchematicSystem:SchematicSystem_8",
    "SchematicSystem:SchematicSystem_15",
    "SchematicSystem:SchematicSystem_19",
    "SchematicSystem:SchematicSystem_Core"
)

include(
    "SpigotCore",
    "SpigotCore:CRIUDummy",
    "SpigotCore:SpigotCore_8",
    "SpigotCore:SpigotCore_9",
    "SpigotCore:SpigotCore_10",
    "SpigotCore:SpigotCore_12",
    "SpigotCore:SpigotCore_14",
    "SpigotCore:SpigotCore_15",
    "SpigotCore:SpigotCore_18",
    "SpigotCore:SpigotCore_19",
    "SpigotCore:SpigotCore_20",
    "SpigotCore:SpigotCore_21",
    "SpigotCore:SpigotCore_Main"
)

include("Teamserver")

include("TowerRun")

include("TutorialSystem")

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

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