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 packet to send simple informational messages between the client and the server
 */
public class MessagePacket implements IClientToServerPacket.Void, IServerToClientPacket {

  /**
   * The informational message from the server that should be logged out outputted
   */
  public String message;

  @JsonIgnore
  public static MessagePacket create(String message) {
    MessagePacket packet = new MessagePacket();
    packet.message = message;
    return packet;
  }

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

  @JsonIgnore
  public void onHandle(WebSocket webSocket, SocketServer socketServer) {
    socketServer.log(webSocket, this.message);
  }

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