package eu.jonahbauer.wizard.server.machine;

import eu.jonahbauer.wizard.common.machine.State;
import eu.jonahbauer.wizard.common.messages.client.ClientMessage;
import eu.jonahbauer.wizard.common.messages.server.NackMessage;
import eu.jonahbauer.wizard.server.NackException;
import org.springframework.web.socket.CloseStatus;

import java.util.Optional;

public interface ClientState extends State<ClientState, Player> {
    default Optional<ClientState> onOpen(Player player) {
        throw new IllegalStateException();
    }

    default Optional<ClientState> onMessage(Player player, ClientMessage message) {
        throw new NackException(NackMessage.UNEXPECTED_MESSAGE, "Don't know what to do with " + message + ".");
    }

    Optional<ClientState> onClose(Player player, CloseStatus status);
}
