package com.airson.alive.preference;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Shrikant on 9/11/2017.
 */

public class Preferences {
    private static Preferences theInstance = null;

    private final String	gPrefName			    = "PrefAlive";
    private final String	gPrefKeyIsLogin			= "gPrefKeyIsLogin";
    private final String	gPrefKeyUserName	    = "gPrefKeyUserName";
    private final String	gPrefKeyEmail		    = "gPrefKeyEmail";
    private final String	gPrefKeyMobile		    = "gPrefKeyMobile";
    private final String	gPrefKeyGender	        = "gPrefKeyGender";
    private final String	gPrefKeyAuthToken	    = "gPrefKeyAuthToken";
    private final String    gPrefKeyIsAddMedicalID  = "gPrefKeyIsAddMedicalID";

    private Preferences()
    {
    }

    public static Preferences getInstance()
    {
        if (theInstance == null)
            theInstance = new Preferences();

        return theInstance;
    }


    public boolean getIsLogin(Context context)
    {
        boolean bret = false;
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        if (prefs != null) {
            bret = prefs.getBoolean(gPrefKeyIsLogin, false);
        }

        return bret;
    }

    public void setIsAddMedicalID(Context context, boolean isLogin)
    {
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean(gPrefKeyIsAddMedicalID, isLogin);
        editor.commit();
    }

    public boolean getIsAddMedicalID(Context context)
    {
        boolean bret = false;
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        if (prefs != null) {
            bret = prefs.getBoolean(gPrefKeyIsAddMedicalID, false);
        }

        return bret;
    }

    public void setIsLogin(Context context, boolean isLogin)
    {
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putBoolean(gPrefKeyIsLogin, isLogin);
        editor.commit();
    }

    public String getUserName(Context context)
    {
        String bret = "";
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        if (prefs != null) {
            bret = prefs.getString(gPrefKeyUserName, "");
        }

        return bret;
    }

    public void setUserName(Context context, String name)
    {
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(gPrefKeyUserName, name);
        editor.commit();
    }


    public String getEmail(Context context)
    {
        String bret = "";
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        if (prefs != null) {
            bret = prefs.getString(gPrefKeyEmail, "");
        }

        return bret;
    }

    public void setEmail(Context context, String email)
    {
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(gPrefKeyEmail, email);
        editor.commit();
    }

    public String getGender(Context context)
    {
        String bret = "";
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        if (prefs != null) {
            bret = prefs.getString(gPrefKeyGender, "");
        }

        return bret;
    }

    public void setGender(Context context, String gender)
    {
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(gPrefKeyGender, gender);
        editor.commit();
    }

    public String getMobile(Context context)
    {
        String bret = "";
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        if (prefs != null) {
            bret = prefs.getString(gPrefKeyMobile, "");
        }

        return bret;
    }

    public void setMobile(Context context, String mobile)
    {
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(gPrefKeyMobile, mobile);
        editor.commit();
    }


    public String getAuthToken(Context context)
    {
        String bret = "";
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        if (prefs != null) {
            bret = prefs.getString(gPrefKeyAuthToken, "");
        }

        return bret;
    }

    public void setAuthToken(Context context, String auth)
    {
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putString(gPrefKeyAuthToken, auth);
        editor.commit();
    }


	public void logout(Context context){
        SharedPreferences prefs = context.getSharedPreferences(gPrefName, Activity.MODE_PRIVATE);
        SharedPreferences.Editor editor = prefs.edit();
        editor.clear();
//        editor.putBoolean(gPrefKeyIsWalkthrough, true);
        editor.commit();
    }


}
