/*
 * 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.UserNoBean;
import kr.co.zumo.app.lifeplus.network.api.LifeplusAPIRepository;
import kr.co.zumo.app.lifeplus.view.Event;

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

  private Disposable disposable;

  public void deleteAccount() {
    disposable = new LifeplusAPIRepository().deleteMember(new UserNoBean(SuperModel.getInstance().getUserId()))
      .subscribeOn(Schedulers.io())
      .observeOn(AndroidSchedulers.mainThread())
      .subscribe(resultBean -> {
        if (resultBean.isSuccess()) {
          onResult(new Event.Builder(Event.COMPLETED).integer(Event.MEMBER_DELETE).build());
        }
        else {
          onResult(new Event.Builder(Event.ERROR).integer(Event.MEMBER_DELETE).string(resultBean.getReturnMessage()).build());
        }
      }, e -> {
        onResult(new Event.Builder(Event.ERROR).integer(Event.MEMBER_DELETE).string(e.getLocalizedMessage()).build());
      });
  }

  @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() {

  }
}
