package de.dhbwstuttgart.server.packet;

import com.fasterxml.jackson.annotation.JsonIgnore;
import de.dhbwstuttgart.server.SocketClient;
import de.dhbwstuttgart.server.SocketFuture;
import de.dhbwstuttgart.server.SocketServer;
import org.java_websocket.WebSocket;

/**
 * A fallback packet that is generated if the received JSON could not be mapped to an existing package
 */
public class InvalidPacket implements IClientToServerPacket.Void, IServerToClientPacket {

  /**
   * If available, the error that caused this package to appear
   */
  public String error = "<unknown error>";


  @JsonIgnore
  public void onHandle(WebSocket webSocket, SocketClient socketClient) {
    SocketClient.logger.error("InvalidPacket: " + this.error);
  }

  @JsonIgnore
  public void onHandle(WebSocket webSocket, SocketServer socketServer) {
    socketServer.log(webSocket, "InvalidPacket: " + this.error);
  }

  @JsonIgnore
  public SocketFuture<IServerToClientPacket> getFuture() {
    return SocketFuture.completedFuture();
  }

}
