package eu.mhsl.minenet.minigames.command.privileged;

import eu.mhsl.minenet.minigames.command.PrivilegedCommand;
import eu.mhsl.minenet.minigames.message.Icon;
import eu.mhsl.minenet.minigames.message.TranslatableMessage;
import eu.mhsl.minenet.minigames.message.type.ChatMessage;
import eu.mhsl.minenet.minigames.instance.room.Room;
import net.minestom.server.entity.Player;

import java.util.stream.Collectors;

public class RoomCommand extends PrivilegedCommand {
    public RoomCommand() {
        super("room");

        setDefaultExecutor((sender, context) -> {
            TranslatableMessage out = new ChatMessage(Icon.SCIENCE).appendStatic("Rooms:").newLine();

            Room.getAllRooms().forEach((roomInstance) -> out
                    .newLine()
                    .appendStatic("Owner: ").appendStatic(roomInstance.getOwner() != null ? roomInstance.getOwner().getUsername() : "none").newLine()
                    .appendStatic("Players: ").appendStatic(String.valueOf(roomInstance.getAllMembers().size())).newLine()
                    .list(roomInstance.getAllMembers().stream().map(Player::getUsername).collect(Collectors.toList())).newLine());

            out.send(sender);
        });
    }


}

