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

import { PIRequest, PIResponse } from './pi';

export interface Login2Request extends PIRequest {
  companyCode: string;
  loginId: string;
  loginPw: string;
}

export interface Login2Response extends PIResponse {
  status: string;
  version: string;
  passwordHc: string;
  personalInfoAgreeYn: string;
  companyCode: string;
  userId: string;
  userName: string;
  userSeq: number;
}

const login2EncodeMap = {
  companyCode: 'companyCd',
  loginId: 'loginId',
  loginPw: 'loginPw'
};

export const encodeLogin2: APIEncoder<Login2Request> = (req: Login2Request) => {
  return ParameterUtil.encode(login2EncodeMap, req);
};

export const decodeLogin2: APIDecoder<Login2Response> = (res: any) => {
  return {
    status: res.STATUS,
    version: res.VER,
    passwordHc: res.PWD_HC,
    personalInfoAgreeYn: res.PER_INFO_AGREE_YN,
    companyCode: res.COMPANY_CODE,
    userId: res.USER_ID,
    userName: res.USER_NAME,
    userSeq: res.USER_SEQ
  } as Login2Response;
};
