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

// tslint:disable-next-line: no-empty-interface
export interface CallViewRequest extends ProtocolRequest {}

export interface CallViewResponse extends ProtocolResponse {
  // 0 IPPhoneYN(s)
  useIpPhone?: boolean;
  // 1 CallerType(s)
  callerType?: CallerType;
  // 2 CallMode(s)
  callMode?: CallMode;
  // 3 PairingYN(s)
  usePairing?: boolean;
  // 4 CallAlarmYN(s)
  useCallAlarm?: boolean;
  // 5 CallAlarmType(s)
  callAlarmType?: CallAlarmType;
  // 6 CallForwardType(s)
  callForwardType?: CallForwardType;
  // 7 대표착신번호(s)
  representativeCalledNumber?: string;
  // 8 착신번호(s)1
  calledNumber1?: string;
  // 9 착신번호(s)2
  calledNumber2?: string;
  // 10 착신번호(s)3
  calledNumber3?: string;
}

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

  return bodyList;
};

export const decodeCallView: ProtocolDecoder<CallViewResponse> = (
  message: ProtocolMessage
) => {
  return decodeProtocolMessage(message, {
    useIpPhone: message.bodyList[0] === 'Y' ? true : false,
    callerType: message.bodyList[1] as CallerType,
    callMode: message.bodyList[2] as CallMode,
    usePairing: message.bodyList[3] === 'Y' ? true : false,
    useCallAlarm: message.bodyList[4] === 'Y' ? true : false,
    callAlarmType: message.bodyList[5] as CallAlarmType,
    callForwardType: message.bodyList[6] as CallForwardType,
    representativeCalledNumber: message.bodyList[7],
    calledNumber1: message.bodyList[8],
    calledNumber2: message.bodyList[9],
    calledNumber3: message.bodyList[10]
  } as CallViewResponse);
};
