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

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

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

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

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

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

  return bodyList;
};

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

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