package solutions.tretter.githugandroid

private val VisualEditorCommands = setOf("vi", "vim", "nano", "emacs", "ed", "ex", "edit", "notepad")

data class VisualEditorInvocation(
    val editor: String,
    val path: String?,
    val command: String,
)

fun parseVisualEditorInvocation(command: String): VisualEditorInvocation? {
    val tokens = GitSandboxEngine.tokenizeCommand(command)
    val editor = tokens.firstOrNull()
        ?.takeIf { it.lowercase() in VisualEditorCommands }
        ?: return null
    return VisualEditorInvocation(
        editor = editor,
        path = tokens.drop(1).firstOrNull { !it.startsWith("-") },
        command = command,
    )
}
