/*
 * COPYRIGHT (c) 2018 All rights reserved by HANWHA LIFE.
 */
package kr.co.zumo.app.lifeplus.network.api;

import android.util.Log;

import io.reactivex.Single;
import kr.co.zumo.app.lifeplus.bean.api.AuthConfirmRequestBean;
import kr.co.zumo.app.lifeplus.bean.api.AuthRequestBean;
import kr.co.zumo.app.lifeplus.bean.api.FAQResultBean;
import kr.co.zumo.app.lifeplus.bean.api.LifeplusAPIBean;
import kr.co.zumo.app.lifeplus.bean.api.LoginResultBean;
import kr.co.zumo.app.lifeplus.bean.api.MemberJoinRequestBean;
import kr.co.zumo.app.lifeplus.bean.api.MemberJoinResultBean;
import kr.co.zumo.app.lifeplus.bean.api.PolicyConfirmRequestBean;
import kr.co.zumo.app.lifeplus.bean.api.PolicyResultBean;
import kr.co.zumo.app.lifeplus.bean.api.RequestBean;
import kr.co.zumo.app.lifeplus.bean.api.UserNoBean;
import kr.co.zumo.app.lifeplus.model.SuperModel;
import kr.co.zumo.app.lifeplus.util.AppUtil;

/**
 * LifeplusAPIRepository
 * - cache 를 활용할 수 있는 api 는 저장해둔다.
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018-10-06]   [최초 작성]
 * @since 2018-10-06
 */
public class LifeplusAPIRepository implements LifeplusAPI {

  private void mapBasicParameter(RequestBean bean) {
    SuperModel model = SuperModel.getInstance();
    bean.setAppVersion(AppUtil.getVersionName());
    bean.setSid(model.getUserId());
    bean.setDeviceId(model.getDeviceUuid());
    bean.setToken(model.getToken());

    Log.i("APP# LifeplusAPIRepository | mapBasicParameter", "|" + bean.toPrettyJson());
  }

  @Override
  public Single<LifeplusAPIBean> requestMobileAuth(AuthRequestBean bean) {
    mapBasicParameter(bean);
    return new LifeplusAPIService().requestMobileAuth(bean);
  }

  @Override
  public Single<LifeplusAPIBean> confirmMobileAuth(AuthConfirmRequestBean bean) {
    mapBasicParameter(bean);
    return new LifeplusAPIService().confirmMobileAuth(bean);
  }

  @Override
  public Single<PolicyResultBean> getPolicyList(RequestBean bean) {
    mapBasicParameter(bean);
    return new LifeplusAPIService().getPolicyList(bean);
  }

  @Override
  public Single<LifeplusAPIBean> confirmPolicy(PolicyConfirmRequestBean bean) {
    mapBasicParameter(bean);
    return new LifeplusAPIService().confirmPolicy(bean);
  }

  @Override
  public Single<MemberJoinResultBean> insertMember(MemberJoinRequestBean bean) {
    mapBasicParameter(bean);
    return new LifeplusAPIService().insertMember(bean);
  }

  @Override
  public Single<LifeplusAPIBean> deleteMember(UserNoBean bean) {
    mapBasicParameter(bean);
    return new LifeplusAPIService().deleteMember(bean);
  }

  @Override
  public Single<FAQResultBean> getFaqList(RequestBean bean) {
    mapBasicParameter(bean);
    return new LifeplusAPIService().getFaqList(bean);
  }

  @Override
  public Single<LoginResultBean> selectMember(UserNoBean bean) {
    mapBasicParameter(bean);
    return new LifeplusAPIService().selectMember(bean);
  }

  @Override
  public Single<LifeplusAPIBean> activeMember(RequestBean bean) {
    mapBasicParameter(bean);
    return new LifeplusAPIService().activeMember(bean);
  }

}
