package eu.jonahbauer.wizard.common.messages.observer;

import com.fasterxml.jackson.databind.ObjectMapper;
import eu.jonahbauer.wizard.common.messages.ParseException;
import eu.jonahbauer.wizard.common.messages.util.SerializationUtil;
import lombok.EqualsAndHashCode;
import lombok.SneakyThrows;

@EqualsAndHashCode
public abstract sealed class ObserverMessage permits CardMessage, HandMessage, PredictionMessage, ScoreMessage, StateMessage, TimeoutMessage, TrickMessage, TrumpMessage, UserInputMessage {
    private static final ObjectMapper MAPPER = SerializationUtil.newObjectMapper(ObserverMessage.class);

    public static ObserverMessage parse(String json) throws ParseException {
        return SerializationUtil.parse(json, MAPPER, ObserverMessage.class);
    }

    @Override
    @SneakyThrows
    public String toString() {
        return MAPPER.writeValueAsString(this);
    }
}