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


import android.content.Context;
import android.support.v7.app.ActionBar;
import android.util.Log;

import kr.co.zumo.app.lifeplus.activity.ActivityStarter;
import kr.co.zumo.app.lifeplus.model.BlankModel;
import kr.co.zumo.app.lifeplus.model.SuperModel;
import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
import kr.co.zumo.app.lifeplus.view.Event;
import kr.co.zumo.app.lifeplus.view.IOnBoardingView;
import kr.co.zumo.app.lifeplus.view.command.ActivityChangeCommand;
import kr.co.zumo.app.lifeplus.view.fragment.onboarding.OnBoardingFromZumoPagerAdapter;
import kr.co.zumo.app.lifeplus.view.fragment.onboarding.OnBoardingPagerAdapter;

/**
 * OnBoardingPresenter
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 21.]   [최초 작성]
 * @since 2018. 9. 21.
 */
public class OnBoardingPresenter extends Presenter<BlankModel, IOnBoardingView> {
  ActivityStarter starter;

  public OnBoardingPresenter(BlankModel model, IOnBoardingView view) {
    super(model, view);
  }

  @Override
  protected void startInternal() {

  }

  @Override
  protected void stopInternal() {

  }

  @Override
  protected void resumeInternal() {

  }

  @Override
  protected void pauseInternal() {

  }

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

  @Override
  public void onResult(Event event) {

  }

  @Override
  public boolean onBackPressed() {
    Log.e("APP#  OnBoardingPresenter | onBackPressed", "|" + "onBackPressed");
    onCommand(new ActivityChangeCommand(ScreenID.ACTIVITY_MAIN, ScreenID.DIRECTION_BACK));
    return true;
  }

  @Override
  protected void onEventInternal(Event event) {
    if (model.isUpdateUser()) {
      switch (event.getEventId()) {
        case Event.TUTORIAL_LEFT:
          // 닫기
          SuperModel.getInstance().getPreferences().setTutorialDone(true);

          onCommand(new ActivityChangeCommand(ScreenID.ACTIVITY_MAIN, ScreenID.DIRECTION_NEXT));
          break;
        case Event.TUTORIAL_RIGHT:
          // 회원 전환
          SuperModel.getInstance().getPreferences().setTutorialDone(true);

          onCommand(new ActivityChangeCommand(ScreenID.ACTIVITY_SIGN_UP_FROM_ZUMO, ScreenID.DIRECTION_NEXT));
          break;

        default:
          break;
      }
    }
    else {
      switch (event.getEventId()) {
        case Event.TUTORIAL_LEFT:
          // 건너뛰기, tutorial 본 것으로 표시
          SuperModel.getInstance().getPreferences().setTutorialDone(true);

          starter = new ActivityStarter(view.getActivity());
          starter.launch(true);
          break;
        case Event.TUTORIAL_RIGHT:
          // 다음
          view.onNextButtonClick();
          break;
        case Event.TUTORIAL_END:
          // 시작하기, tutorial 본 것으로 표시
          SuperModel.getInstance().getPreferences().setTutorialDone(true);

          onCommand(new ActivityChangeCommand(ScreenID.ACTIVITY_SIGN_UP_FROM_ON_BOARDING, ScreenID.DIRECTION_NEXT));
          break;
        default:
          break;
      }
    }

  }

  public OnBoardingPagerAdapter getPagerAdapter(Context context) {
    OnBoardingPagerAdapter onBoardingPagerAdapter;
    if (model.isUpdateUser()) {
      onBoardingPagerAdapter = new OnBoardingFromZumoPagerAdapter(context);
    }
    else {
      onBoardingPagerAdapter = new OnBoardingPagerAdapter(context);
    }
    return onBoardingPagerAdapter;
  }

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

  }
}
