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

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

import java.util.Optional;

public abstract class BaseState implements ClientState {
    
    @Override
    public Optional<ClientState> onEnter(Client context) {
        return ClientState.super.onEnter(context);
    }
    
    @Override
    public Optional<ClientState> onOpen(Client client) {
        throw new IllegalStateException();
    }
    
    @Override
    public Optional<ClientState> onClose(Client client, int code, String reason, boolean remote) {
        if (remote) {
            System.out.println("Lost connection " + code + " " + reason);
        } else {
            System.out.println("Connection closed " + code + " " + reason);
        }
        return Optional.of(new Menu());
    }
    
    protected static Optional<ClientState> unexpectedMessage(Client client, ServerMessage message) {
        // return to menu on unexpected message
        System.out.println("Fatal: Unexpected message " + message + ". Returning to menu.");
        return Optional.of(new Menu());
    }
}
