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

import android.support.v7.app.ActionBar;

import kr.co.zumo.app.lifeplus.model.FAQModel;
import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
import kr.co.zumo.app.lifeplus.view.Event;
import kr.co.zumo.app.lifeplus.view.IFAQView;
import kr.co.zumo.app.lifeplus.view.command.ActivityChangeCommand;
import kr.co.zumo.app.lifeplus.view.dialog.AlertDialog;
import kr.co.zumo.app.lifeplus.view.dialog.DialogBase;
import kr.co.zumo.app.lifeplus.view.dialog.DialogBuilder;
import kr.co.zumo.app.lifeplus.view.dialog.DialogID;
import kr.co.zumo.app.lifeplus.view.dialog.IAttribute;
import kr.co.zumo.app.lifeplus.view.dialog.IDialogResultListener;

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

  DialogBase alertDialog;

  public FAQPresenter(FAQModel model, IFAQView view) {
    super(model, view);

    model.loadFaq();
  }

  @Override
  public boolean onBackPressed() {
    onCommand(new ActivityChangeCommand(ScreenID.ACTIVITY_MAIN, ScreenID.DIRECTION_BACK));
    return true;
  }

  @Override
  protected void onEventInternal(Event event) {

  }

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

  @Override
  protected void startInternal() {

  }

  @Override
  protected void stopInternal() {

  }

  @Override
  protected void resumeInternal() {

  }

  @Override
  protected void pauseInternal() {

  }

  @Override
  public void onResult(Event event) {
    switch (event.getEventId()) {
      case Event.ERROR:
        showAlert(event.getString());
        break;
      case Event.RESULT:
        view.drawList(model.getFaqBeans());
        break;
      default:
        break;
    }
  }

  private void showAlert(String str) {
    alertDialog = DialogBuilder.create(DialogID.ALERT)
      .listener(new IDialogResultListener() {
        @Override
        public void onDialogResult(DialogBase dialog, Event event) {
          if (event.getEventId() == Event.CONFIRM) {
            alertDialog = null;
            dialog.dispose();
          }
        }

        @Override
        public void onDialogCanceled(DialogBase dialog) {
          alertDialog = null;
        }
      })
      .attribute((IAttribute<AlertDialog>) dialog -> {
        dialog.setText(str);
      })
      .show();
  }

  @Override
  public void onClickTitle(ActionBar actionBar) {

  }

  @Override
  public void onClickSearch(ActionBar actionBar) {

  }

  @Override
  public void onClickMenu(ActionBar actionBar) {

  }

  @Override
  public void onClickLike(ActionBar actionBar) {

  }

  @Override
  public void onClickBookmark(ActionBar actionBar) {

  }

  @Override
  public void onClickShare(ActionBar actionBar) {

  }
}
