package de.dhbwstuttgart.server.packet.dataContainers.serialized;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;


/**
 * Use the following classes for an intermediate serialized tree structure
 */
@JsonTypeInfo(
  use = JsonTypeInfo.Id.NAME,
  include = JsonTypeInfo.As.PROPERTY,
  property = "_t"
)
@JsonSubTypes({
  @JsonSubTypes.Type(value = SerialMap.class, name = "m"),
  @JsonSubTypes.Type(value = SerialList.class, name = "l"),
  @JsonSubTypes.Type(value = SerialValue.class, name = "v"),
  @JsonSubTypes.Type(value = SerialUUID.class, name = "u")
})
public interface ISerialNode {

  default <T extends ISerialNode> T assertType(Class<T> type) {
    if (type.isInstance(this)) {
      return (T) this;
    }
    throw new RuntimeException("Expected ISerialNode to be of type " + type.getName()
      + " but found " + this.getClass().getName() + " instead");
  }

}
