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

import kr.co.zumo.app.lifeplus.util.StringUtil;

/**
 * 앱에 필요한 전반적인 데이터 저장
 * <pre>
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 5.]   [최초 작성]
 * @since 2018. 9. 5.
 */
public final class SuperModel {
  private static final SuperModel ourInstance = new SuperModel();

  public static SuperModel getInstance() {
    return ourInstance;
  }

  private String deviceUuid;
  private String UserId;
  private LifeplusPreferences preferences;

  private SuperModel() {
  }

  public void init(LifeplusPreferences preferences) {
    this.preferences = preferences;
  }

  /**
   * preferences 객체 반환
   *
   * @return LifeplusPreferences 객체
   */
  public LifeplusPreferences getPreferences() {
    return preferences;
  }

  /**
   * 저장된 장치 고유번호 반환
   * - 프리퍼런스에 저장되어있지만 편의를 위해 모델에도 저장해둠
   *
   * @return uuid
   */
  public String getDeviceUuid() {
    if (StringUtil.isFull(deviceUuid) == false) {
      deviceUuid = preferences.getDeviceUuid();
    }
    return deviceUuid;
  }

  /**
   * 장치 고유번호 저장;
   *
   * @param deviceUuid
   */
  public void setDeviceUuid(String deviceUuid) {
    this.deviceUuid = deviceUuid;
    preferences.setDeviceUuid(deviceUuid);
  }

  /**
   * 저장된 장치 User ID 반환
   * - 프리퍼런스에 저장되어있지만 편의를 위해 모델에도 저장해둠
   *
   * @return user id
   */
  public String getUserId() {
    if (StringUtil.isFull(UserId) == false) {
      UserId = preferences.getUserId();
    }
    return UserId;
  }

  public void setUserId(String userId) {
    UserId = userId;
    preferences.setUserId(userId);
  }

  /**
   * dispose
   */
  public void dispose() {
  }

}
