package com.reactnativecustomnotification;

import static com.reactnativecustomnotification.CustomNotificationModule.reactContext;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;

import com.facebook.react.bridge.ReactApplicationContext;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import java.util.Map;

import javax.net.ssl.KeyManager;

public class MyFirebaseMessagingService extends FirebaseMessagingService {


  @Override
  public void onMessageReceived(@NonNull RemoteMessage message) {
    String title = message.getNotification ().getTitle ();
    String text = message.getNotification ().getBody ();
    CustomNotificationModule customNotificationModule = new CustomNotificationModule (reactContext);
  //  customNotificationModule.CreateInformativeNotification (title,text, "https://i.stack.imgur.com/ILTQq.png","https://i.stack.imgur.com/ILTQq.png");
    Map<String, String> data = message.getData ();

    switch (data.get ("type")){
      case "1" :
        customNotificationModule.CreateInformativeNotification (title,text,data.get ("avatar"),data.get ("deepLink"));
        break;
      case "2" :
        customNotificationModule.CreateBigPictureNotification (title,text,data.get ("avatar"),data.get ("picture"),data.get ("deepLink"));
        break;
      case "3" :
        customNotificationModule.CreateProductNotification (title,text,data.get ("avatar"),data.get ("product_picture"),data.get ("product_title"),data.get ("product_description"),data.get ("deepLink"));
        break;
      case "4" :
        customNotificationModule.CreateNotificationUrl (title,text,data.get ("avatar"),data.get ("url"),data.get ("message"));
        break;
      case "5" :
        customNotificationModule.CreateAnimationNotification ();
        break;
    }

    super.onMessageReceived (message);
 }

  @Override
  public void onNewToken(@NonNull String token) {
    super.onNewToken (token);
    Log.e ("Token","onNewToken"+token);
  }
}

