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

export interface DelRequest extends ProtocolRequest {
  // 대화방SEQ(s)
  roomSeq: string;
  // 이벤트SEQ(n)
  eventSeq: number;
}
export interface DelResponse extends ProtocolResponse {
  // 대화방SEQ(s)
  roomSeq: string;
  // 이벤트SEQ(n)
  eventSeq: number;
}
export interface DelNotification extends ProtocolNotification {
  // 대화방SEQ(s)
  roomSeq: string;
  // 이벤트SEQ(n)
  eventSeq: number;
}

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

  bodyList.push(
    { type: PacketBodyValue.String, value: req.roomSeq },
    { type: PacketBodyValue.Integer, value: req.eventSeq }
  );
  return bodyList;
};
export const decodeDel: ProtocolDecoder<DelResponse> = (
  message: ProtocolMessage
) => {
  return decodeProtocolMessage(message, {
    roomSeq: message.bodyList[0],
    eventSeq: message.bodyList[1]
  } as DelResponse);
};
export const decodeDelNotification: ProtocolDecoder<DelNotification> = (
  message: ProtocolMessage
) => {
  return decodeProtocolMessage(message, {
    roomSeq: message.bodyList[0],
    eventSeq: message.bodyList[1]
  } as DelNotification);
};
