package com.optix.android.tools.network

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 DnsEnumTool : BaseTool() {
    override val metadata = ToolMetadata(
        name = "dnsenum_termux",
        displayName = "DNSenum (Termux)",
        description = "DNS enumeration: zone transfers, brute-force subdomains, reverse lookups. Requires Termux.",
        category = ToolCategory.NETWORK_SCANNING,
        requiresRoot = false,
        parameters = listOf(
            ToolParam("domain", ParamType.STRING, "Target domain"),
            ToolParam("threads", ParamType.INT, "Threads", required = false, defaultValue = "5"),
        ),
        chainSuggestions = listOf("dns_recon", "subdomain_enum", "nmap_termux"),
    )
    override suspend fun execute(params: Map<String, Any>, emit: suspend (ToolEvent) -> Unit) {
        val domain = paramRequired(params, "domain")
        val threads = paramInt(params, "threads", 5)
        emit(ToolEvent.Log("[DNSenum] Enumerating DNS for $domain..."))
        withContext(Dispatchers.IO) {
            shellExecutor?.executeTermuxAsRoot("dnsenum", listOf("--threads", threads.toString(), domain), "dnsenum", emit)
        }
        emit(ToolEvent.Done)
    }
}
