package eu.mhsl.minenet.minigames.api.routes.queueRoom;

import eu.mhsl.minenet.minigames.api.Controller;
import eu.mhsl.minenet.minigames.api.QueuedPlayerRooms;
import eu.mhsl.minenet.minigames.instance.room.Room;
import net.minestom.server.MinecraftServer;
import spark.Response;

import java.util.UUID;

record Req(UUID player, UUID room) {}
record Resp(String error) {}
public class QueueRoom extends Controller<Req, Resp> {
    @Override
    public Resp handle(Req request, Response response) {
        if(Room.getRoom(request.room()).isEmpty()) return new Resp("Raum nicht gefunden");
        if(MinecraftServer.getConnectionManager().getOnlinePlayers().size() >= Integer.parseInt(System.getProperty("minenet.playerlimit", "999"))) {
            return new Resp("Der Server hat eine Spielerzahllimitierung und ist bereits voll!");
        }

        QueuedPlayerRooms.queuePlayer(request.player(), request.room());
        return new Resp(null);
    }
}
