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

export interface CancelRequest extends ProtocolRequest {
  // 대화방SEQ(s)
  roomSeq: string;
  // 이벤트SEQ(n)
  eventSeq: number;
  // 단말타입(s)
  deviceType: DeviceType;
}
export interface CancelResponse extends ProtocolResponse {
  // 대화방SEQ(s)
  roomSeq: string;
  // 이벤트SEQ(n)
  eventSeq: number;
  // 단말타입(s)
  deviceType: DeviceType;
}
export interface CancelNotification extends ProtocolNotification {
  // 대화방SEQ(s)
  roomSeq: string;
  // 이벤트SEQ(n)
  eventSeq: number;
  // 단말타입(s)
  deviceType: DeviceType;
}

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

  bodyList.push(
    { type: PacketBodyValue.String, value: req.roomSeq },
    { type: PacketBodyValue.Integer, value: req.eventSeq },
    { type: PacketBodyValue.String, value: req.deviceType }
  );
  return bodyList;
};
export const decodeCancel: ProtocolDecoder<CancelResponse> = (
  message: ProtocolMessage
) => {
  return decodeProtocolMessage(message, {
    roomSeq: message.bodyList[0],
    eventSeq: message.bodyList[1],
    deviceType: message.bodyList[2] as DeviceType
  } as CancelResponse);
};
export const decodeCancelNotification: ProtocolDecoder<CancelNotification> = (
  message: ProtocolMessage
) => {
  return decodeProtocolMessage(message, {
    roomSeq: message.bodyList[0],
    eventSeq: message.bodyList[1],
    deviceType: message.bodyList[2] as DeviceType
  } as CancelNotification);
};
