//go:build windows

package proc

import (
	"fmt"
	"os/exec"
	"time"
)

// ConfigureProcessGroup is a no-op on Windows, where Unix process groups are
// unavailable.
func ConfigureProcessGroup(_ *exec.Cmd) {}

func terminateProcess(pid int, done <-chan struct{}, stopTimeout time.Duration) {
	if pid <= 0 {
		return
	}
	if stopTimeout == 0 {
		stopTimeout = DefaultStopTimeout
	}
	// taskkill /T applies the same descendant-tree ownership used on Unix.
	// Windows has no SIGTERM equivalent for arbitrary console processes, so
	// forceful tree termination is the only reliable cross-process primitive.
	_ = exec.Command("taskkill", "/PID", fmt.Sprintf("%d", pid), "/T", "/F").Run()
	waitDone(done, stopTimeout)
}

func forceKillProcess(pid int) {
	if pid <= 0 {
		return
	}
	// Windows terminateProcess already uses /F (force), so the immediate and
	// graceful paths collapse to the same primitive. Call it with a short
	// timeout so the caller does not stall during a force-exit.
	terminateProcess(pid, nil, time.Second)
}
