package eu.jonahbauer.wizard.client.libgdx.state;

import eu.jonahbauer.wizard.client.libgdx.Client;
import eu.jonahbauer.wizard.client.libgdx.screens.LoadingScreen;
import eu.jonahbauer.wizard.common.messages.server.ServerMessage;
import eu.jonahbauer.wizard.common.messages.server.SessionListMessage;

import java.util.Optional;

public final class AwaitingJoinLobby extends Awaiting {
    
    @Override
    public Optional<ClientState> onEnter(Client client) {
        System.out.println("Waiting for session list...");
        client.getGame().setScreen(new LoadingScreen(client.getGame()));
        return super.onEnter(client);
    }
    
    @Override
    public Optional<ClientState> onMessage(Client client, ServerMessage message) {
        if (message instanceof SessionListMessage list) {
            return Optional.of(new Lobby(list));
        } else {
            return super.onMessage(client, message);
        }
    }
}
