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

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 PlayerMessage permits ContinueMessage, JuggleMessage, PickTrumpMessage, PlayCardMessage, PredictMessage {
    private static final ObjectMapper MAPPER = SerializationUtil.newObjectMapper(PlayerMessage.class);

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

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