package runtimeconfig

import (
	"os/exec"
	"strings"
	"syscall"
)

func configureRuntimeCommandLine(cmd *exec.Cmd, t RuntimeType, command string, args []string) {
	if cmd == nil || !runtimeTypeUsesWindowsBatchShim(EffectiveRuntimeType(t)) || !strings.EqualFold(command, "cmd.exe") || len(args) != 4 {
		return
	}
	if cmd.SysProcAttr == nil {
		cmd.SysProcAttr = &syscall.SysProcAttr{}
	}
	// Go's generic Windows argv quoting escapes embedded quotes with
	// backslashes, which cmd.exe treats literally. Supply the cmd command line
	// verbatim so quoted npm-shim paths preserve spaces and stdio.
	cmd.SysProcAttr.CmdLine = "/d /s /c " + args[3]
}

func runtimeTypeUsesWindowsBatchShim(t RuntimeType) bool {
	switch t {
	case TypeCodex, TypeKimi:
		return true
	default:
		return false
	}
}
