using UnityEngine;

namespace DlserveSDK
{
    public class DlserveCallbackReceiver : MonoBehaviour
    {
        internal static DlserveCallbackReceiver Instance { get; private set; }

        internal static void EnsureExists()
        {
            if (Instance != null) return;
            var go = new GameObject("DlserveCallbackReceiver");
            Object.DontDestroyOnLoad(go);
            Instance = go.AddComponent<DlserveCallbackReceiver>();
        }

        public void OnNativeEvent(string json)
        {
            var evt = DlserveNotificationEvent.FromJson(json);
            Dlserve.RaiseOnNotification(evt);
        }
    }
}
