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

import eu.jonahbauer.wizard.client.cli.Client;
import eu.jonahbauer.wizard.common.messages.server.ServerMessage;
import lombok.SneakyThrows;
import picocli.CommandLine.Model.CommandSpec;

import java.util.Optional;

public abstract class Awaiting extends BaseState implements ClientState {
    private static final CommandSpec COMMAND_SPEC = CommandSpec.create();
    @Override
    public Optional<ClientState> onMessage(Client client, ServerMessage message) {
        return unexpectedMessage(client, message);
    }

    @Override
    @SneakyThrows
    public Optional<ClientState> onEnter(Client client) {
        client.waitForReady();
        client.timeout(this, 10_000);
        return Optional.empty();
    }

    @Override
    public Optional<ClientState> onTimeout(Client client) {
        client.println("Timed out. Returning to menu");
        return Optional.of(new Menu());
    }

    @Override
    public Object getCommand() {
        return COMMAND_SPEC;
    }
}
