package com.optix.android.tools.web

import com.optix.android.domain.model.ParamType
import com.optix.android.domain.model.ToolCategory
import com.optix.android.domain.model.ToolEvent
import com.optix.android.domain.model.ToolMetadata
import com.optix.android.domain.model.ToolParam
import com.optix.android.tools.registry.BaseTool
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class Enum4LinuxTool : BaseTool() {
    override val metadata = ToolMetadata(
        name = "enum4linux_termux",
        displayName = "Enum4Linux (Termux)",
        description = "Windows/Samba enumeration — users, shares, groups, password policy via SMB/RPC. Requires Termux.",
        category = ToolCategory.NETWORK_SCANNING,
        requiresRoot = false,
        parameters = listOf(
            ToolParam("target", ParamType.STRING, "Target IP"),
            ToolParam("options", ParamType.ENUM, "Enumeration options", required = false, defaultValue = "-a", enumValues = listOf("-a", "-U", "-S", "-G", "-P")),
        ),
        chainSuggestions = listOf("netbios_scanner", "smbclient_termux", "hydra_termux"),
    )
    override suspend fun execute(params: Map<String, Any>, emit: suspend (ToolEvent) -> Unit) {
        val target = paramRequired(params, "target")
        val options = param(params, "options") ?: "-a"
        emit(ToolEvent.Log("[Enum4Linux] Enumerating $target ($options)..."))
        withContext(Dispatchers.IO) {
            shellExecutor?.executeTermuxAsRoot("enum4linux", listOf(options, target), "samba", emit)
        }
        emit(ToolEvent.Done)
    }
}
