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

import android.util.Log;

import java.util.List;

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

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

  private CompositeDisposable disposable = new CompositeDisposable();
  private List<FAQBean> faqBeans;

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

  }

  /**
   * FAQ 불러오기;
   */
  public void loadFaq() {
    disposable.add(
      new LifeplusAPIRepository().getFaqList(new RequestBean())
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(resultBean -> {
          Log.i("APP# FAQModel | loadFaq", "| " + resultBean.toPrettyJson());
          faqBeans = resultBean.getData();
          onResult(new Event.Builder(Event.RESULT).build());
        }, e -> {
          onResult(new Event.Builder(Event.ERROR).string(e.getLocalizedMessage()).build());
        })
    );
  }

  /**
   * FAQ
   *
   * @return
   */
  public List<FAQBean> getFaqBeans() {
    return faqBeans;
  }
}
