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

export interface BuddyAddRequest extends ProtocolRequest {
  // 0n. 사용자SEQ(n)...
  userSeqs: number[];
}

export interface BuddyAddResponse extends ProtocolResponse {
  // 0n. 사용자SEQ(n)...
  userSeqs: number[];
}

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

  for (const userSeq of req.userSeqs) {
    bodyList.push({ type: PacketBodyValue.Integer, value: userSeq });
  }

  return bodyList;
};

export const decodeBuddyAdd: ProtocolDecoder<BuddyAddResponse> = (
  message: ProtocolMessage
) => {
  const userSeqArray: number[] = [...message.bodyList];
  return {
    userSeqs: userSeqArray
  } as BuddyAddResponse;
};
