package com.fusi24.rfid.data;

import android.content.SharedPreferences;

public class SessionManager {

    private static final String IS_LOGIN                = "is_login";
    private static final String USER_ID                 = "user_id";
    private static final String USER_NAME               = "user_name";
    private static final String EMPLOYEE_NAME           = "employee_name";
    private static final String USER_SID                = "user_sid";
    private static final String USER_EMAIL              = "user_email";
    private static final String USER_TELEPHONE          = "user_telephone";
    private static final String USER_RFID_NUMBER        = "user_rfid_number";
    private static final String GATE                    = "gate";

    private final SharedPreferences preferences;

    public SessionManager(SharedPreferences preferences) {
        this.preferences = preferences;
    }

    public Boolean isUserLogin() {
        return preferences.getBoolean(IS_LOGIN, false);
    }

    public void setUserLogin() {
        SharedPreferences.Editor editor = preferences.edit();
        editor.putBoolean(IS_LOGIN, true);
        editor.apply();
    }

    public Integer getUserId() {
        return preferences.getInt(USER_ID, 0);
    }

    public void setUserId(Integer userID) {
        SharedPreferences.Editor editor = preferences.edit();
        editor.putInt(USER_ID, userID);
        editor.apply();
    }

    public String getUserName() {
        return preferences.getString(USER_NAME, "");
    }

    public void setUserName(String userName) {
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(USER_NAME, userName);
        editor.apply();
    }

    public String getEmployeeName() {
        return preferences.getString(EMPLOYEE_NAME, "");
    }

    public void setEmployeeName(String employeeName) {
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(EMPLOYEE_NAME, employeeName);
        editor.apply();
    }

    public String getUserSid() {
        return preferences.getString(USER_SID, "");
    }

    public void setUserSid(String userSid) {
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(USER_SID, userSid);
        editor.apply();
    }

    public String getUserEmail() {
        return preferences.getString(USER_EMAIL, "");
    }

    public void setUserEmail(String userEmail) {
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(USER_EMAIL, userEmail);
        editor.apply();
    }

    public String getUserTelephone() {
        return preferences.getString(USER_TELEPHONE, "");
    }

    public void setUserTelephone(String userTelephone) {
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(USER_TELEPHONE, userTelephone);
        editor.apply();
    }

    public String getUserRfidNumber() {
        return preferences.getString(USER_RFID_NUMBER, "");
    }

    public void setUserRfidNumber(String userRfidNumber) {
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(USER_RFID_NUMBER, userRfidNumber);
        editor.apply();
    }

    public String getGate() {
        return preferences.getString(GATE, "");
    }

    public void setGate(String gate) {
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(GATE, gate);
        editor.apply();
    }

    public void clearData() {
        SharedPreferences.Editor editor = preferences.edit();
        editor.remove(IS_LOGIN);
        editor.remove(USER_ID);
        editor.remove(USER_NAME);
        editor.remove(EMPLOYEE_NAME);
        editor.remove(USER_SID);
        editor.remove(USER_EMAIL);
        editor.remove(USER_TELEPHONE);
        editor.remove(USER_RFID_NUMBER);
        editor.remove(GATE);
        editor.apply();
    }
}
