package io.trustbuilder.mfa.android.demoapp.utils;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import java.util.Map;

public class PushNotificationReceiveService extends FirebaseMessagingService {
    private final String TAG = PushNotificationReceiveService.class.getSimpleName();

    private static final MutableLiveData<Map<String, String>> IN_APP_MESSAGE = new MutableLiveData<>();

    public static MutableLiveData<Map<String, String>> getInAppMessage() {
        return IN_APP_MESSAGE;
    }

    private static final MutableLiveData<String> TOKEN = new MutableLiveData<>();

    public static MutableLiveData<String> getNewToken() {
        return TOKEN;
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        Log.d(TAG, "onMessageReceived: " + remoteMessage.getData());
        handleMessage(remoteMessage);
    }

    @Override
    public void onNewToken(@NonNull String token) {
        super.onNewToken(token);
        TOKEN.postValue(token);
    }

    public void handleMessage(RemoteMessage message) {
        IN_APP_MESSAGE.postValue(message.getData());
    }
}