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

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import eu.jonahbauer.wizard.common.messages.observer.ObserverMessage;
import eu.jonahbauer.wizard.common.util.SealedClassTypeAdapterFactory;
import lombok.EqualsAndHashCode;

@EqualsAndHashCode
public abstract sealed class ClientMessage permits CreateSessionMessage, InteractionMessage, JoinSessionMessage, LeaveSessionMessage, ReadyMessage {
    public static final Gson GSON = new GsonBuilder()
            .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ClientMessage.class, "Message"))
            .registerTypeAdapterFactory(SealedClassTypeAdapterFactory.of(ObserverMessage.class, "Message"))
            .create();

    @Override
    public String toString() {
        return GSON.toJson(this, ClientMessage.class);
    }
}
