package uprrp.tania;

import androidx.annotation.Nullable;

import java.util.Observable;

import uprrp.tania.models.UserStatusModel;

// TAKEN FROM https://stackoverflow.com/questions/21886768/is-there-any-method-i-can-listen-for-changes-to-global-variable-to-trigger-an-ev
public class GlobalValues extends Observable {

    private static GlobalValues mInstance = null;

    public static GlobalValues getInstance() {
        if(mInstance == null) {
            mInstance = new GlobalValues();
        }
        return mInstance;
    }

    // WHENEVER ADDING ANOTHER GLOBAL VARIABLE...
    // 1. ADD ITS NAME IN ValueName
    // 2. ADD A DECLARATION (AND INITIALIZATION; OPTIONAL)
    // 3. ADD A GETTER AND A SETTER (TAKE A GOOD LOOK AT THE SETTER)
    public enum ValueName {
        DEVICE_TOKEN,
        USER_STATUS,
    }

    public static class ValueKey {
        private final ValueName mValueName;
        public ValueKey(ValueName valueName) {
            mValueName = valueName;
        }
        public ValueName getKey() {
            return mValueName;
        }
    }

    // DEVICE TOKEN
    @Nullable
    private String mDeviceToken;
    public String getDeviceToken() {
        return mDeviceToken;
    }
    public void setDeviceToken(@Nullable String value) {
        mDeviceToken = value;
        this.setChanged();
        this.notifyObservers(new ValueKey(ValueName.DEVICE_TOKEN));
    }

    // USER STATUS
    @Nullable
    private UserStatusModel mUserStatus;
    public UserStatusModel getUserStatus() {
        return mUserStatus;
    }
    public void setUserStatus(UserStatusModel value) {
        mUserStatus = value;
        this.setChanged();
        this.notifyObservers(new ValueKey(ValueName.USER_STATUS));
    }

}
