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

import android.support.v7.app.ActionBar;

import java.util.ArrayList;

import kr.co.zumo.app.lifeplus.bean.api.BannerBean;
import kr.co.zumo.app.lifeplus.manager.ActionBarManager;
import kr.co.zumo.app.lifeplus.model.SignUpModel;
import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
import kr.co.zumo.app.lifeplus.view.Event;
import kr.co.zumo.app.lifeplus.view.command.ActivityChangeCommand;
import kr.co.zumo.app.lifeplus.view.command.FragmentChangeCommand;
import kr.co.zumo.app.lifeplus.view.presenter.Presenter;

/**
 * SignUpFragmentPresenter
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 28.]   [최초 작성]
 * @since 2018. 9. 28.
 */
public class SignUpStartPresenter extends Presenter<SignUpModel, ISignUpStartView> {

  protected boolean isLoaded = false;
  protected boolean isViewReady = false;

  public SignUpStartPresenter(SignUpModel model, ISignUpStartView view) {
    super(model, view);

    this.model.requestBanners();
  }

  @Override
  protected void startInternal() {
    ActionBarManager.getInstance().setProgress(8); // 26/360
  }

  @Override
  protected void stopInternal() {

  }

  @Override
  protected void resumeInternal() {

  }

  @Override
  protected void pauseInternal() {

  }

  @Override
  protected void destroyInternal() {
    model.stopBannerRequest();
  }

  @Override
  public void onResult(Event event) {
    switch (event.getEventId()) {
      case Event.RESULT:
        if (event.getInteger() == Event.BANNER_REQUEST) {
          isLoaded = true;
          renderAfterReady();
        }
        break;
      default:
        break;
    }
  }

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

  @Override
  protected void onEventInternal(Event event) {
    switch (event.getEventId()) {
      case Event.SUCCESS:
        onCommand(new FragmentChangeCommand(ScreenID.SIGN_UP_MOBILE_AUTHORIZATION, ScreenID.DIRECTION_NEXT));
        break;
      case Event.INIT:
        isViewReady = true;
        renderAfterReady();
        break;
      default:
        break;
    }
  }

  private ArrayList<BannerBean> getBannerItems() {
    return model.getBannerItems();
  }

  private void renderAfterReady() {
    if (isLoaded && isViewReady) {
      view.drawBanners(getBannerItems());
    }
  }

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

  }
}
