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

import eu.jonahbauer.wizard.client.cli.Client;
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) {
        client.println("Waiting for session list...");
        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);
        }
    }
}
