package com.optix.android.domain.model

// ---------------------------------------------------------------------------
// Events emitted by tools during execution — collected by ViewModel via Flow
// ---------------------------------------------------------------------------

sealed class ToolEvent {
    data class Log(val message: String, val level: LogLevel = LogLevel.INFO) : ToolEvent()
    data class Result(val data: Any) : ToolEvent()
    data class Progress(val current: Int, val total: Int) : ToolEvent()
    data class Error(val message: String, val cause: Throwable? = null) : ToolEvent()
    /** Emitted when a required Termux binary is missing. UI should prompt for install consent. */
    data class InstallRequired(val toolName: String, val aptPackage: String) : ToolEvent()
    data class TermuxMissing(val toolName: String, val aptPackage: String) : ToolEvent()
    /**
     * Emitted by the execution engine when a tool's required capability
     * (root or Termux) is absent. Tools should refuse to run gracefully
     * instead of throwing, and the UI surfaces a friendly message.
     */
    data class CapabilityMissing(
        val toolName: String,
        val reason: String,
        val missingCapability: MissingCapability,
    ) : ToolEvent()

enum class MissingCapability { ROOT, TERMUX }
    /** Emitted to suggest a follow-up tool the UI or MockBrain may chain. */
    data class ChainSuggestion(val nextTool: String, val params: Map<String, Any>) : ToolEvent()
    data object Done : ToolEvent()
}

enum class LogLevel { DEBUG, INFO, WARN, ERROR }

// ---------------------------------------------------------------------------
// Typed result models — one per tool category / output shape
// ---------------------------------------------------------------------------

data class HostResult(
    val nodeId: String? = null,
    val ip: String,
    val hostname: String? = null,
    val status: String,             // "UP" | "DOWN"
    val openPorts: List<Int> = emptyList(),
    val latencyMs: Double = 0.0,
    val macAddress: String? = null,
    val deviceType: String? = null,
    val alias: String? = null,
    val transport: String = "lan",
    val security: String? = null,
    val signalLevelDbm: Int? = null,
    val note: String? = null,
    val firstSeenAt: Long = 0L,
    val lastSeenAt: Long = 0L,
    val seenCount: Int = 0,
)

data class PortResult(
    val port: Int,
    val protocol: String,           // "tcp" | "udp"
    val state: String,              // "open" | "closed" | "filtered"
    val service: String,
)

data class DnsRecord(
    val type: String,               // "A", "MX", "NS", "TXT", "CNAME"
    val name: String,
    val value: String,
    val ttl: Int,
)

data class OsintResult(
    val field: String,
    val value: String,
    val source: String,
)

data class VulnResult(
    val cveId: String,
    val description: String,
    val severity: String,
    val cvss: Double,
)

data class SubdomainResult(
    val subdomain: String,
    val ip: String? = null,
    val status: Int? = null,        // HTTP status if probed
)

data class DirectoryResult(
    val path: String,
    val status: Int,
    val size: Long = 0,
)

data class HashResult(
    val hash: String,
    val algorithm: String,
    val plaintext: String? = null,
)

data class SslResult(
    val field: String,
    val value: String,
)
