package com.anand.geofence.reference;

import android.content.Context;
import android.content.SharedPreferences;

import com.anand.geofence.model.response.geoResponse.GeoVal;
import com.anand.geofence.model.response.geofence.GetGeoLocationResponse;
import com.google.gson.Gson;

import java.util.List;

public class AppSharedpreferences {

    private static AppSharedpreferences yourPreference;
    private SharedPreferences sharedPreferences;

    public static AppSharedpreferences getInstance(Context context) {
        if (yourPreference == null) {
            yourPreference = new AppSharedpreferences(context);
        }
        return yourPreference;
    }

    private AppSharedpreferences(Context context) {
            sharedPreferences = context.getSharedPreferences("com.anand.geofence", Context.MODE_PRIVATE);

    }

    // set String Values
    public void saveString(String key, String value) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putString(key, value);
        prefsEditor.apply();
    }
		
    public void registerPrefsListener(SharedPreferences.OnSharedPreferenceChangeListener listener) {
        sharedPreferences.registerOnSharedPreferenceChangeListener(listener);
    }

    public void unregisterPrefsListener(

            SharedPreferences.OnSharedPreferenceChangeListener listener) {
            sharedPreferences.unregisterOnSharedPreferenceChangeListener(listener);
    }

    // get String Values
    public String getString(String key) {
        if (sharedPreferences != null) {
            return sharedPreferences.getString(key, "");
        }
        return "";
    }

    public boolean getBoolean(String key) {
        if (sharedPreferences != null) {
            return sharedPreferences.getBoolean(key, false);
        }
        return false;
    }

    public void saveBoolean(String key, Boolean value) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putBoolean(key, value);
        prefsEditor.apply();
    }

    public void clearBoolean(String key, Boolean value) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putBoolean(key, value);
        prefsEditor.apply();
    }

    public void clearString(String key) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.remove(key);
        prefsEditor.apply();
    }
    public void saveInteger(String key, Integer value) {
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        prefsEditor.putInt(key, value);
        prefsEditor.apply();
    }
    public Integer getInteger(String key) {
        if (sharedPreferences != null) {
            return sharedPreferences.getInt(key, 0);
        }
        return 0;
    }

   /* public void saveData(String key, GeoMain modal){
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        Gson gson = new Gson();
        String jsonObject = gson.toJson(modal);
        prefsEditor.putString(key, jsonObject);
        prefsEditor.apply();
    }

    public GeoVal getData(String key){
        String json = sharedPreferences.getString(key, "");
        Gson gson=new Gson();
        GeoVal selectedUser=gson.fromJson(json, GeoVal.class);
        return  selectedUser;
    }*/

/*     public void saveData(String key, List<GetGeoLocationResponse> modal){
        SharedPreferences.Editor prefsEditor = sharedPreferences.edit();
        Gson gson = new Gson();
        String jsonObject = gson.toJson(modal);
        prefsEditor.putString(key, jsonObject);
        prefsEditor.apply();
    }

    public GeoVal getData(String key){
        String json = sharedPreferences.getString(key, "");
        Gson gson=new Gson();
        GeoVal selectedUser=gson.fromJson(json, GeoVal.class);
        return  selectedUser;
    }*/


}


