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

import com.velocitypowered.api.proxy.Player;
import de.steamwar.messages.Chatter;
import de.steamwar.messages.Message;
import de.steamwar.network.packets.server.StartingServerPacket;
import de.steamwar.persistent.Subserver;
import de.steamwar.sql.IgnoreSystem;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.velocitycore.network.NetworkSender;
import de.steamwar.velocitycore.network.handlers.FightInfoHandler;
import net.kyori.adventure.text.event.ClickEvent;

import java.util.UUID;

public class SubserverSystem {
    private SubserverSystem() {
    }

    public static void deleteFolder(Node node, String worldName) {
        node.execute("rm", "-r", worldName);
    }

    public static void sendDeniedMessage(Chatter p, UUID owner) {
        if (IgnoreSystem.isIgnored(owner, p.user().getUUID())) {
            p.system("SERVER_IGNORED");
            return;
        }

        Chatter o = Chatter.of(owner);
        o.system("SERVER_ADD_MEMBER", p);
        o.prefixless("SERVER_ADD_MESSAGE", new Message("SERVER_ADD_MESSAGE_HOVER", p.user().getUserName()), ClickEvent.runCommand("/bau addmember " + p.user().getUserName()));
    }

    public static void sendPlayer(Subserver subserver, Player player) {
        subserver.sendPlayer(player);
        if (!subserver.isStarted() && FightInfoHandler.onLobby(player)) {
            NetworkSender.send(player, new StartingServerPacket(SteamwarUser.get(player.getUniqueId()).getId()));
        }
    }
}
