package com.nexlab.openclaw.node.domain.model

/**
 * Represents a command received from the OpenClaw gateway
 */
sealed class NodeCommand {
    abstract val id: String
    
    data class Screenshot(override val id: String, val quality: Int = 80) : NodeCommand()
    data class Tap(override val id: String, val x: Int, val y: Int) : NodeCommand()
    data class Swipe(override val id: String, val x1: Int, val y1: Int, val x2: Int, val y2: Int, val duration: Int = 300) : NodeCommand()
    data class LongPress(override val id: String, val x: Int, val y: Int, val duration: Int = 500) : NodeCommand()
    data class LaunchApp(override val id: String, val packageName: String) : NodeCommand()
    data class Shell(override val id: String, val command: String) : NodeCommand()
    data class DeviceInfo(override val id: String) : NodeCommand()
    data class ListApps(override val id: String, val systemApps: Boolean = false) : NodeCommand()
    data class GetForegroundApp(override val id: String) : NodeCommand()
    data class NotificationListener(override val id: String, val enabled: Boolean) : NodeCommand()
    data class KeyEvent(override val id: String, val keyCode: Int) : NodeCommand()
    object Ping : NodeCommand() { override val id: String = "" }
}

/**
 * Response sent back to the gateway
 */
sealed class NodeResponse {
    abstract val id: String
    
    data class Success(override val id: String, val data: Map<String, Any> = emptyMap()) : NodeResponse()
    data class Error(override val id: String, val error: String) : NodeResponse()
    data class ScreenshotResponse(override val id: String, val base64Image: String) : NodeResponse()
}

/**
 * Events pushed to the gateway without request
 */
sealed class NodeEvent {
    data class Notification(val app: String, val title: String, val text: String, val timestamp: Long) : NodeEvent()
    data class Battery(val level: Int, val charging: Boolean) : NodeEvent()
    data class ForegroundAppChanged(val packageName: String, val appName: String) : NodeEvent()
    data class ConnectionStatus(val connected: Boolean, val nodeId: String) : NodeEvent()
}

/**
 * Node capabilities advertised during registration
 */
data class NodeCapabilities(
    val screenshot: Boolean = true,
    val touch: Boolean = true,
    val shell: Boolean = true,
    val notifications: Boolean = true,
    val appControl: Boolean = true,
    val sensors: Boolean = true
)

/**
 * Device information
 */
data class DeviceInfo(
    val model: String,
    val manufacturer: String,
    val androidVersion: String,
    val sdkInt: Int,
    val batteryLevel: Int,
    val charging: Boolean,
    val storage: StorageInfo,
    val network: NetworkInfo
)

data class StorageInfo(
    val total: Long,
    val available: Long
)

data class NetworkInfo(
    val connected: Boolean,
    val type: String, // wifi, mobile, ethernet
    val ip: String?
)
