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

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

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

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

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

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

  return bodyList;
};

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

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