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

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import kr.co.zumo.app.lifeplus.bean.api.RequestBean;
import kr.co.zumo.app.lifeplus.network.api.LifeplusAPIService;
import kr.co.zumo.app.lifeplus.view.Event;

/**
 * RestMemberModel
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 10. 8.]   [최초 작성]
 * @since 2018. 10. 8.
 */
public class RestMemberModel extends Model {

  Disposable disposable;

  @Override
  protected void destroyInternal() {
    if (null != disposable) {
      disposable.dispose();
      disposable = null;
    }
  }

  @Override
  protected void startInternal() {

  }

  @Override
  protected void stopInternal() {

  }

  @Override
  protected void resumeInternal() {

  }

  @Override
  protected void pauseInternal() {

  }

  /**
   * 회원 휴면 해제
   */
  public void activeMember() {
    disposable = new LifeplusAPIService().activeMember(new RequestBean())
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(resultBean -> {
        if (resultBean.isSuccess()) {
          SuperModel.getInstance().deleteMemberStatus(SuperModel.MEMBER_STATUS_BIT_REST);
          onResult(new Event.Builder(Event.SUCCESS).build());
        }
        else {
          onResult(new Event.Builder(Event.ERROR).string(resultBean.getReturnMessage()).build());
        }
      }, e -> {
        onResult(new Event.Builder(Event.ERROR).string(e.getLocalizedMessage()).build());
      });
  }
}
