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

export interface UrlInfoRequest extends APIRequest {
  deviceType: DeviceType;
}

export interface UrlInfoResponse extends APIResponse {
  portCheckUrl?: string;
  messageUrl?: string;
  messageUrl2?: string;
  passwordUrl?: string;
  planUrl?: string;
  planUrl2?: string;
  vocUrl?: string;
  confUrl?: string;
  uprApiUrl?: string;
  uprSvcUrl?: string;
  uprDownloadUrl?: string;
  synapViewUrl?: string;
}

const urlInfoEncodeMap = {
  deviceType: 'p_device_type'
};

export const encodeUrlInfo: APIEncoder<UrlInfoRequest> = (
  req: UrlInfoRequest
) => {
  return ParameterUtil.encode(urlInfoEncodeMap, req);
};

export const decodeUrlInfo: APIDecoder<UrlInfoResponse> = (res: any) => {
  return {
    statusCode: res.StatusCode,
    errorMessage: res.ErrorMessage,
    portCheckUrl: res.PortCheckURL,
    messageUrl: res.MsgURL,
    messageUrl2: res.MsgURL2,
    passwordUrl: res.PasswordURL,
    planUrl: res.PlanURL,
    planUrl2: res.PlanURL2,
    vocUrl: res.VocURL,
    confUrl: res.ConfURL,
    uprApiUrl: res.UprApiURL,
    uprSvcUrl: res.UprSvcURL,
    uprDownloadUrl: res.UprDownloadURL,
    synapViewUrl: res.SynapViewURL
  } as UrlInfoResponse;
};
