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

export interface GroupAddRequest extends ProtocolRequest {
  // 0. 동료그룹이름
  groupName: string;
}

export interface GroupAddResponse extends ProtocolResponse {
  // 0: 동료그룹SEQ(n)
  groupSeq: number;
  // 1: 동료그룹이름(s)
  groupName: string;
}

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

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

  return bodyList;
};

export const decodeGroupAdd: ProtocolDecoder<GroupAddResponse> = (
  message: ProtocolMessage
) => {
  return {
    groupSeq: message.bodyList[0],
    groupName: message.bodyList[1]
  } as GroupAddResponse;
};
