/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2024  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/>.
 */

package de.steamwar.velocitycore;

import lombok.Getter;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

@Getter
public enum ServerVersion {
    SPIGOT_12("spigot-1.12.2.jar", 12),
    SPIGOT_15("spigot-1.15.2.jar", 15),
    PAPER_19("paper-1.19.3.jar", 19),
    PAPER_20("paper-1.20.1.jar", 20);

    private static final Map<String, ServerVersion> chatMap = new HashMap<>();

    static {
        chatMap.put("20", ServerVersion.PAPER_20);
        chatMap.put("1.20", ServerVersion.PAPER_20);
        chatMap.put("1.20.1", ServerVersion.PAPER_20);
        chatMap.put("as", ServerVersion.PAPER_20);
        chatMap.put("airship", ServerVersion.PAPER_20);
        chatMap.put("wg", ServerVersion.PAPER_20);
        chatMap.put("wargear", ServerVersion.PAPER_20);
        chatMap.put("ws", ServerVersion.PAPER_20);
        chatMap.put("warship", ServerVersion.PAPER_20);
        chatMap.put("mwg", ServerVersion.PAPER_20);
        chatMap.put("miniwargear", ServerVersion.PAPER_20);

        chatMap.put("19", ServerVersion.PAPER_19);
        chatMap.put("1.19", ServerVersion.PAPER_19);
        chatMap.put("1.19.2", ServerVersion.PAPER_19);

        chatMap.put("15", ServerVersion.SPIGOT_15);
        chatMap.put("1.15", ServerVersion.SPIGOT_15);
        chatMap.put("1.15.2", ServerVersion.SPIGOT_15);

        chatMap.put("12", ServerVersion.SPIGOT_12);
        chatMap.put("1.12", ServerVersion.SPIGOT_12);
        chatMap.put("1.12.2", ServerVersion.SPIGOT_12);
    }

    public static ServerVersion get(String chat) {
        return chatMap.get(chat.toLowerCase());
    }

    public static Set<String> chatVersions() {
        return chatMap.keySet();
    }

    private final String serverJar;
    private final int versionSuffix;

    ServerVersion(String serverJar, int versionSuffix) {
        this.serverJar = serverJar;
        this.versionSuffix = versionSuffix;
    }

    public String getWorldFolder(String base) {
        return base + versionSuffix + "/";
    }

    public File getServerDirectory(String base) {
        return new File(ServerStarter.SERVER_PATH, base + versionSuffix);
    }
}
