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

import kr.co.zumo.app.lifeplus.view.presenter.SignUpPresenter;

/**
 * SignUpStepBuilder
 * {@see SignUpStep} 객체는 다음 동작을 체인으로 연결하여 flow 를 진행한다.
 * 객체 생성 및 연결을 편리하게 하기위한 빌더 클래스이다.
 *
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 17.]   [최초 작성]
 * @since 2018. 9. 17.
 */
public class SignUpStepBuilder {
  private SignUpPresenter model;
  private SignUpStep stepChain;
  private SignUpStep first;

  public SignUpStepBuilder(SignUpPresenter model) {
    this.model = model;
  }

  /**
   * SignUpStepBuilder 를 생성한다.
   *
   * @param model SignUpFragmentPresenter
   * @return SignUpStepBuilder 객체
   */
  public static SignUpStepBuilder create(SignUpPresenter model) {
    return new SignUpStepBuilder(model);
  }

  private void setChain(SignUpStep step) {
    if (null == this.stepChain) {
      this.stepChain = step;
      this.first = step;
    }
    else {
      this.stepChain.setNext(step);
      stepChain = step;
    }
  }

  /**
   * 인사말 스텝
   *
   * @return SignUpStepBuilder
   */
  public SignUpStepBuilder hello() {
    setChain(new SignUpStepHello(model));
    return this;
  }

  /**
   * 혜택
   *
   * @return SignUpStepBuilder
   */
  public SignUpStepBuilder benefit() {
    setChain(new SignUpStepBenefit(model));
    return this;
  }

  /**
   * 본인 인증
   *
   * @return SignUpStepBuilder
   */
  public SignUpStepBuilder confirm() {
    setChain(new SignUpStepAuthorization(model));
    return this;
  }

  /**
   * 핀 입력
   *
   * @return SignUpStepBuilder
   */
  public SignUpStepBuilder pin() {
    setChain(new SignUpStepPin(model));
    return this;
  }

  /**
   * 약관 동의
   *
   * @return SignUpStepBuilder
   */
  public SignUpStepBuilder agree() {
    setChain(new SignUpStepAgree(model));
    return this;
  }

  /**
   * 인사말 스텝
   *
   * @return SignUpStepBuilder
   */
  public SignUpStepBuilder complete() {
    setChain(new SignUpStepComplete(model));
    return this;
  }

  /**
   * 연결된 객체들을 반환한다.
   * - 첫 객체를 반환한다.
   *
   * @return 만들어진 SignUpStep
   */
  public SignUpStep build() {
    return first;
  }
}
