package ai.pai.lensman.db;

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

public class Preferences {

    private Context context;
    private SharedPreferences mPrefs;
    private static Preferences instance;
    private static final String NullStr = "";

    private Preferences(Context context) {
        this.context = context.getApplicationContext();
        mPrefs = this.context.getSharedPreferences("prefs", Context.MODE_PRIVATE);
    }

    public static synchronized Preferences getInstance(Context context) {

        if (instance == null) {
            instance = new Preferences(context);
        }
        return instance;
    }


    public void setLastRunDate(String date) {
        mPrefs.edit().putString("lastRunDate", date).commit();
    }

    public String getLastRunDate() {
        return mPrefs.getString("lastRunDate", "1970-01-01");
    }

    public void setUserName(String userName){
        mPrefs.edit().putString("userName",userName).commit();
    }

    public String getUserName(){
        return mPrefs.getString("userName",NullStr);
    }

    public void setLensManId(String lensManId){
        mPrefs.edit().putString("lensManId",lensManId).commit();
    }

    public String getLensManId(){
        return mPrefs.getString("lensManId",NullStr);
    }

    public void clearPrefs(){
        mPrefs.edit().clear().commit();
    }
}
