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

import android.content.SharedPreferences;
import android.support.annotation.Nullable;

import java.util.Set;

/**
 * SharedPreferences 관리 기본 클래스
 * <pre>
 *
 * </pre>
 *
 * @author 민효동
 * @version 1.0
 * @history 민효동   [2018. 9. 5.]   [최초 작성]
 * @since 2018. 9. 5.
 */
public class BaseSharedPreferences {
  private SharedPreferences preferences;

  public BaseSharedPreferences(SharedPreferences preferences) {
    this.preferences = preferences;
  }

  protected void put(String key, String value) {
    preferences.edit().putString(key, value).apply();
  }

  protected String get(String key, String defaultValue) {
    return preferences.getString(key, defaultValue);
  }

  protected void put(String key, boolean value) {
    preferences.edit().putBoolean(key, value).apply();
  }

  protected boolean get(String key, boolean defaultValue) {
    return preferences.getBoolean(key, defaultValue);
  }

  protected void put(String key, int value) {
    preferences.edit().putInt(key, value).apply();
  }

  protected int get(String key, int defaultValue) {
    return preferences.getInt(key, defaultValue);
  }

  protected void put(String key, long value) {
    preferences.edit().putLong(key, value).apply();
  }

  protected long get(String key, long defaultValue) {
    return preferences.getLong(key, defaultValue);
  }

  protected void put(String key, float value) {
    preferences.edit().putFloat(key, value).apply();
  }

  protected float get(String key, float defaultValue) {
    return preferences.getFloat(key, defaultValue);
  }

  protected void put(String key, Set<String> value) {
    preferences.edit().putStringSet(key, value).apply();
  }

  protected Set<String> get(String key, @Nullable Set<String> defaultValue) {
    return preferences.getStringSet(key, defaultValue);
  }

  protected void remove(String key) {
    preferences.edit().remove(key).apply();
  }
}
