import {
  APIRequest,
  APIDecoder,
  APIEncoder,
  ParameterUtil
} from '@ucap-webmessenger/api';
import { DeviceType } from '@ucap-webmessenger/core';
import { PromptAPIResponse } from './api-prompt';

export interface CallRequest extends APIRequest {
  userSeq: number;
  deviceType: DeviceType;
  tokenKey: string;
  calleeNumber: string;
}

export interface CallResponse extends PromptAPIResponse {}

const callEncodeMap = {
  userSeq: 'userSeq',
  deviceType: 'deviceType',
  tokenKey: 'tokenKey',
  calleeNumber: 'calleeNumber'
};

export const encodeCall: APIEncoder<CallRequest> = (req: CallRequest) => {
  return ParameterUtil.encode(callEncodeMap, req);
};

export const decodeCall: APIDecoder<CallResponse> = (res: any) => {
  return {
    responseCode: res.responseCode,
    responseMsg: res.responseMsg
  } as CallResponse;
};
