import {
  ProtocolRequest,
  ProtocolResponse,
  ProtocolEncoder,
  PacketBody,
  ProtocolDecoder,
  ProtocolMessage,
  PacketBodyValue,
  decodeProtocolMessage
} from '@ucap-webmessenger/protocol';

export interface PingRequest extends ProtocolRequest {
  /** 상태코드(s) */
  statusCode: string;
}

// tslint:disable-next-line: no-empty-interface
export interface PingResponse extends ProtocolResponse {}

export const encodePing: ProtocolEncoder<PingRequest> = (req: PingRequest) => {
  const bodyList: PacketBody[] = [];

  bodyList.push({
    type: PacketBodyValue.String,
    value: req.statusCode
  });

  return bodyList;
};

export const decodePing: ProtocolDecoder<PingResponse> = (
  message: ProtocolMessage
) => {
  return decodeProtocolMessage(message, {} as PingResponse);
};
