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

import eu.jonahbauer.wizard.client.cli.Client;

import java.util.Optional;

public final class AwaitingConnection extends Awaiting {

    @Override
    public Optional<ClientState> onEnter(Client client) {
        client.println("Awaiting connection...");
        return super.onEnter(client);
    }

    @Override
    public Optional<ClientState> onOpen(Client client) {
        client.println("Connection established.");
        return Optional.of(new AwaitingJoinLobby());
    }

    @Override
    public Optional<ClientState> onClose(Client client, int code, String reason, boolean remote) {
        client.printfln("Connection could not be established. (code=%d, reason=%s)", code, reason);
        return Optional.of(new Menu());
    }
}
