package ai.pai.lensman.db;

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

import ai.pai.lensman.App;

public class Preferences {

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

    private Preferences() {
        mPrefs = App.getAppContext().getSharedPreferences("prefs", Context.MODE_PRIVATE);
    }

    public static synchronized Preferences getInstance() {

        if (instance == null) {
            instance = new Preferences();
        }
        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 String getWXCode(){
        return mPrefs.getString("wxcode", NullStr);
    }

    public void setWXCode(String wxCode){
        mPrefs.edit().putString("wxcode",wxCode).commit();
    }

    public boolean isCameraLibExist(){
        return mPrefs.getBoolean("CameraLibExist",false);
    }

    public void setCameraLibExist(boolean CameraLibExist){
        mPrefs.edit().putBoolean("CameraLibExist",CameraLibExist).commit();
    }
    public String getCurrentSession(){
        return mPrefs.getString("currentSession", NullStr);
    }

    public void setCurrentSession(String currentSession){
        mPrefs.edit().putString("currentSession",currentSession).commit();
    }


    public void setPatchUrl(String patchUrl){
        mPrefs.edit().putString("patchUrl",patchUrl).commit();
    }

    public String getPatchUrl(){
        return mPrefs.getString("patchUrl",NullStr);
    }

    public void setUploadDelay(int delay){
        mPrefs.edit().putInt("delay",delay).commit();
    }

    public int getUploadDelay(){
        return mPrefs.getInt("delay",10);
    }


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