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

export interface CheckUserInfoExRequest extends APIRequest {
  userId: string;
  companyCode: string;
  userSession: string;
}

export interface CheckUserInfoExResponse extends APIResponse {
  userId?: string;
}

const checkUserInfoExEncodeMap = {
  userId: 'p_user_id',
  companyCode: 'p_comp_code',
  userSession: 'p_user_session'
};

export const encodeCheckUserInfoEx: APIEncoder<CheckUserInfoExRequest> = (
  req: CheckUserInfoExRequest
) => {
  return ParameterUtil.encode(checkUserInfoExEncodeMap, req);
};

export const decodeCheckUserInfoEx: APIDecoder<CheckUserInfoExResponse> = (
  res: any
) => {
  return {
    statusCode: res.StatusCode,
    errorMessage: res.ErrorMessage,
    userId: res.UserID
  } as CheckUserInfoExResponse;
};
