package ai.sirrus.reactnativesdk import org.json.JSONArray import org.json.JSONObject data class SirrusNotificationPayload( val title: String = "", val body: String = "", val subtitle: String? = null, val imageUrl: String? = null, val gifUrl: String? = null, val videoUrl: String? = null, val deeplinkUrl: String? = null, val campaignId: String? = null, val templateId: String? = null, val messageId: String? = null, val provider: String = "fcm", val channelId: String? = null, val categoryId: String? = null, val sound: String? = null, val actions: List = emptyList(), val rawData: Map = emptyMap() ) data class SirrusNotificationAction( val id: String, val title: String, val label: String? = null, val actionType: String? = null, val postback: String? = null, val deeplinkUrl: String? = null, val destructive: Boolean = false, val foreground: Boolean = true, val authenticationRequired: Boolean = false ) internal fun SirrusNotificationPayload.toEventJson(): JSONObject { val rawDataJson = JSONObject().apply { rawData.forEach { (key, value) -> put(key, value ?: JSONObject.NULL) } } return JSONObject().apply { put("title", title) put("body", body) put("subtitle", subtitle ?: "") put("imageUrl", imageUrl ?: "") put("gifUrl", gifUrl ?: "") put("videoUrl", videoUrl ?: "") put("deeplinkUrl", deeplinkUrl ?: "") put("campaignId", campaignId ?: "") put("templateId", templateId ?: "") put("messageId", messageId ?: "") put("provider", provider) put("channelId", channelId ?: "") put("categoryId", categoryId ?: "") put("sound", sound ?: "") put("data", rawDataJson) put("rawPayload", rawDataJson) put( "actions", JSONArray().apply { actions.forEach { action -> put(action.toEventJson()) } } ) } } internal fun SirrusNotificationAction.toEventJson(): JSONObject { return JSONObject().apply { put("id", id) put("title", title) put("label", label ?: title) put("actionType", actionType ?: "") put("postback", postback ?: "") put("deeplinkUrl", deeplinkUrl ?: "") put("foreground", foreground) put("destructive", destructive) put("authenticationRequired", authenticationRequired) } }