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 {
  /** 0n. 사용자SEQ(n)... */
  userSeqs: number[];
}

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

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

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

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

  return bodyList;
};

export const decodeAdd: ProtocolDecoder<AddResponse> = (
  message: ProtocolMessage
) => {
  const userSeqArray: number[] = [...message.bodyList];
  return decodeProtocolMessage(message, {
    userSeqs: userSeqArray
  } as AddResponse);
};

export const decodeAddNotification: ProtocolDecoder<AddNotification> = (
  message: ProtocolMessage
) => {
  const userSeqArray: number[] = [...message.bodyList];
  return decodeProtocolMessage(message, {
    userSeqs: userSeqArray
  } as AddNotification);
};
