package com.nexlab.openclaw.node.service

import android.accessibilityservice.AccessibilityService
import android.content.Intent
import android.service.notification.NotificationListenerService
import android.service.notification.StatusBarNotification

/**
 * Service for mirroring notifications to the OpenClaw gateway
 */
class NotificationListener : NotificationListenerService() {

    companion object {
        var instance: NotificationListener? = null
        var onNotificationReceived: ((String, String, String) -> Unit)? = null
    }

    override fun onCreate() {
        super.onCreate()
        instance = this
    }

    override fun onDestroy() {
        super.onDestroy()
        instance = null
    }

    override fun onNotificationPosted(sbn: StatusBarNotification?) {
        sbn ?: return
        
        // Filter out our own notifications
        if (sbn.packageName == "com.nexlab.openclaw.node") {
            return
        }

        val extras = sbn.notification.extras
        val title = extras.getCharSequence("android.title")?.toString() ?: ""
        val text = extras.getCharSequence("android.text")?.toString() ?: ""

        onNotificationReceived?.invoke(sbn.packageName, title, text)
    }

    override fun onNotificationRemoved(sbn: StatusBarNotification?) {
        // Handle notification removal if needed
    }
}
