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

export interface UserOptionResponse extends ProtocolResponse {
  // 타입(s)
  type: CallerType;
}

export const decodeUserOption: ProtocolDecoder<UserOptionResponse> = (
  message: ProtocolMessage
) => {
  return { type: message.bodyList[0] as CallerType } as UserOptionResponse;
};

export interface UserOptionUpdateRequest extends ProtocolRequest {
  // 타입(s)
  type: CallerType;
}

export interface UserOptionUpdateResponse extends ProtocolResponse {
  // 타입(s)
  type: CallerType;
}

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

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

export const decodeUserOptionUpdate: ProtocolDecoder<UserOptionUpdateResponse> = (
  message: ProtocolMessage
) => {
  return decodeProtocolMessage(message, {
    type: message.bodyList[0] as CallerType
  } as UserOptionUpdateResponse);
};
