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 FierceTool : BaseTool() {
    override val metadata = ToolMetadata(
        name = "fierce_termux",
        displayName = "Fierce (Termux)",
        description = "DNS reconnaissance and host discovery. Finds non-contiguous IP space and hostnames. Requires Termux.",
        category = ToolCategory.NETWORK_SCANNING,
        requiresRoot = false,
        parameters = listOf(
            ToolParam("domain", ParamType.STRING, "Target domain"),
        ),
        chainSuggestions = listOf("dns_recon", "nmap_termux", "subdomain_enum"),
    )
    override suspend fun execute(params: Map<String, Any>, emit: suspend (ToolEvent) -> Unit) {
        val domain = paramRequired(params, "domain")
        emit(ToolEvent.Log("[Fierce] Scanning $domain..."))
        withContext(Dispatchers.IO) {
            shellExecutor?.executeTermuxAsRoot("fierce", listOf("--domain", domain), "fierce", emit)
        }
        emit(ToolEvent.Done)
    }
}
