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

import com.velocitypowered.api.command.SimpleCommand;
import de.steamwar.command.SWCommand;
import de.steamwar.linkage.EventMode;
import de.steamwar.linkage.Linked;
import de.steamwar.messages.Chatter;
import de.steamwar.persistent.Storage;
import de.steamwar.sql.SteamwarUser;
import de.steamwar.sql.UserPerm;

@Linked
@EventMode(false)
public class StreamingCommand extends SWCommand {

    public static boolean isNotStreaming(Chatter sender) {
        return isNotStreaming(sender.user());
    }

    public static boolean isNotStreaming(SteamwarUser user) {
        return !Storage.streamingPlayers.contains(user.getId());
    }

    public StreamingCommand() {
        super("streaming");
    }

    @Override
    protected boolean hasPermission(SimpleCommand.Invocation invocation) {
        SteamwarUser user = Chatter.of(invocation.source()).user();
        return user.hasPerm(UserPerm.TEAM) || user.hasPerm(UserPerm.PREFIX_YOUTUBER);
    }

    @Register
    public void toggleStreamingMode(Chatter sender) {
        int userId = sender.user().getId();
        if (Storage.streamingPlayers.contains(userId)) {
            Storage.streamingPlayers.remove(userId);
            sender.system("STREAMING_DISABLE");
        } else {
            Storage.streamingPlayers.add(userId);
            sender.system("STREAMING_ENABLE");
        }
    }
}
