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

import android.app.Activity;

import kr.co.zumo.app.lifeplus.activity.factory.ActivityFactory;
import kr.co.zumo.app.lifeplus.model.Model;
import kr.co.zumo.app.lifeplus.supervisor.ActivityChanger;
import kr.co.zumo.app.lifeplus.supervisor.ScreenID;
import kr.co.zumo.app.lifeplus.view.IView;
import kr.co.zumo.app.lifeplus.view.presenter.Presenter;

/**
 * ActivityChangeCommand
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 21.]   [최초 작성]
 * @since 2018. 9. 21.
 */
public class ActivityChangeCommand extends Command<Model, IView, Presenter> {

  int activityId;
  int direction;

  public ActivityChangeCommand(@ScreenID.ActivityID int id, @ScreenID.Direction int direction) {
    this.activityId = id;
    this.direction = direction;
  }

  @Override
  public void preExecute(Model model, IView view, Presenter presenter) {

  }

  @Override
  public void execute(Model model, IView view, Presenter presenter) {
    Activity activity = view.getActivity();
    ActivityFactory factory = new ActivityFactory();
    ActivityChanger changer = new ActivityChanger(activity, factory);

    switch (direction) {
      case ScreenID.DIRECTION_NEXT:
        presenter.destroy();
        changer.changeToNext(activityId);
        break;
      case ScreenID.DIRECTION_BACK:
        presenter.destroy();
        changer.changeToBack(activityId);
        break;
      case ScreenID.DIRECTION_NONE:
        presenter.destroy();
        changer.changeTo(activityId);
        break;
      default:
        throw new RuntimeException("unsupported direction");
    }
  }

  @Override
  public void postExecute(Model model, IView view, Presenter presenter) {

  }

  @Override
  public void dispose() {
  }
}
