import {
  ProtocolRequest,
  ProtocolEncoder,
  PacketBody,
  ProtocolDecoder,
  ProtocolMessage,
  PacketBodyValue
} from '@ucap-webmessenger/protocol';
import { EventType } from '../types/event.type';
import { PushClType } from '../types/push-cl.type';

export interface PushRequest extends ProtocolRequest {
  // 대화방SEQ(s)
  roomSeq: string;
  // 수신자SEQ(n)
  receiverSeq: number;
  // 푸시타입(s)
  type: PushClType;
  // 발생일시(s)
  sendDate: string;
  // 메시지(s)
  message: string;
  // 제목(s)
  title: string;
  // 이벤트타입(s)
  eventType: EventType;
}

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

  bodyList.push(
    { type: PacketBodyValue.String, value: req.roomSeq },
    { type: PacketBodyValue.Integer, value: req.receiverSeq },
    { type: PacketBodyValue.String, value: req.type },
    { type: PacketBodyValue.String, value: req.sendDate },
    { type: PacketBodyValue.String, value: req.message },
    { type: PacketBodyValue.String, value: req.title },
    { type: PacketBodyValue.String, value: req.eventType }
  );
  return bodyList;
};
