package com.webengage.we_notificationinbox_rn import com.facebook.react.bridge.Callback import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.ReactContextBaseJavaModule import com.facebook.react.bridge.ReactMethod import com.facebook.react.bridge.ReadableArray import com.facebook.react.bridge.ReadableMap import com.webengage.sdk.android.Logger class WEInboxModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaModule(reactContext) { private val weInboxModuleImpl: WEInboxModuleImpl? = try { WEInboxModuleImpl(reactContext) } catch (e: Exception) { Logger.e("WEInboxModule", "Failed to initialize WEInboxModuleImpl", e) null } init { Logger.d("WebEngage", "oldArch: WEInboxModule (Legacy) initialized") } private fun safeExecute(action: (WEInboxModuleImpl) -> Unit) { try { weInboxModuleImpl?.let(action) ?: Logger.e("WEInboxModule", "Module not initialized") } catch (e: Exception) { Logger.e("WEInboxModule", "Error executing action: ${e.message}", e) } } override fun getName(): String { return "WEInboxReact" } @ReactMethod fun initWENotificationInbox() { safeExecute { it.initWENotificationInbox() } } @ReactMethod fun getNotificationList(offset: String?, callback: Callback?) { if (callback == null) { Logger.e("WEInboxModule", "Callback is null in getNotificationList") return } Logger.d("WebEngage", "oldArch: getNotificationList called via Legacy Module") safeExecute { it.getNotificationList(offset, callback) } } @ReactMethod fun getNotificationCount(callback: Callback?) { if (callback == null) { Logger.e("WEInboxModule", "Callback is null in getNotificationCount") return } safeExecute { it.getNotificationCount(callback) } } @ReactMethod fun markRead(notificationItem: ReadableMap?) { if (notificationItem == null) { Logger.w("WEInboxModule", "Notification item is null in markRead") return } safeExecute { it.markRead(notificationItem) } } @ReactMethod fun markUnread(notificationItem: ReadableMap?) { if (notificationItem == null) { Logger.w("WEInboxModule", "Notification item is null in markUnread") return } safeExecute { it.markUnread(notificationItem) } } @ReactMethod fun trackClick(notificationItem: ReadableMap?) { if (notificationItem == null) { Logger.w("WEInboxModule", "Notification item is null in trackClick") return } safeExecute { it.trackClick(notificationItem) } } @ReactMethod fun trackView(notificationItem: ReadableMap?) { if (notificationItem == null) { Logger.w("WEInboxModule", "Notification item is null in trackView") return } safeExecute { it.trackView(notificationItem) } } @ReactMethod fun markDelete(notificationItem: ReadableMap?) { if (notificationItem == null) { Logger.w("WEInboxModule", "Notification item is null in markDelete") return } safeExecute { it.markDelete(notificationItem) } } @ReactMethod fun readAll(notificationList: ReadableArray?) { if (notificationList == null) { Logger.w("WEInboxModule", "Notification list is null in readAll") return } safeExecute { it.readAll(notificationList) } } @ReactMethod fun unReadAll(notificationList: ReadableArray?) { if (notificationList == null) { Logger.w("WEInboxModule", "Notification list is null in unReadAll") return } safeExecute { it.unReadAll(notificationList) } } @ReactMethod fun deleteAll(notificationList: ReadableArray?) { if (notificationList == null) { Logger.w("WEInboxModule", "Notification list is null in deleteAll") return } safeExecute { it.deleteAll(notificationList) } } @ReactMethod fun onNotificationIconClick() { safeExecute { it.onNotificationIconClick() } } }