package kz.com.aman.kassa.bank.managing;

import android.content.Context;
import android.content.SharedPreferences;

import static android.content.Context.MODE_PRIVATE;

public class PreferencesManager {
    public enum Field {
        LOGIN("Login"), PASSWORD("Password"), SERVER_URL("ServerUrl");

        private String code;

        Field(String code) {
            this.code = code;
        }

        public String getCode() {
            return code;
        }
    }

    public static void saveStringField(Context context, Field field, String value) {
        SharedPreferences preferences = context.getSharedPreferences("preferences", MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(field.getCode(), value).apply();
    }

    public static String loadStringField(Context context, Field field) {
        return loadStringField(context, field, null);
    }

    public static String loadStringField(Context context, Field field, String defaultValue) {
        SharedPreferences preferences = context.getSharedPreferences("preferences", MODE_PRIVATE);
        return preferences.getString(field.getCode(), defaultValue);
    }
}
