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

package de.steamwar.sql;

import de.steamwar.core.Core;
import de.steamwar.data.GameModeConfigUtils;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class SQLWrapperImpl implements SQLWrapper<Material> {

    @Override
    public File getSchemTypesFolder() {
        return new File(Core.getInstance().getDataFolder().getParentFile(), "FightSystem");
    }

    @Override
    public GameModeConfig<Material, String> loadGameModeConfig(File file) {
        return new GameModeConfig<>(file, GameModeConfigUtils.ToMaterial, GameModeConfig.ToString, GameModeConfig.ToStaticWarGear, true);
    }

    @Override
    public List<Material> getMaterialWithGreaterBlastResistance(double maxBlastResistance) {
        return Arrays.stream(Material.values())
                .filter(material -> !material.isLegacy())
                .filter(Material::isBlock)
                .filter(material -> material.getBlastResistance() > maxBlastResistance)
                .collect(Collectors.toList());
    }

    private static final String SERVER_VERSION = Bukkit.getServer().getVersion();

    @Override
    public void additionalExceptionMetadata(StringBuilder builder) {
        builder.append("\nPlayers: ");
        for (Player player : Bukkit.getOnlinePlayers()) {
            builder.append(player.getName()).append(" ");
        }
        builder.append("\nWorlds: ");
        for (World world : Bukkit.getWorlds()) {
            builder.append(world.getName()).append(" ");
        }
        builder.append("\nServer: ").append(SERVER_VERSION);
    }
}
