// SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc.
// SPDX-License-Identifier: Apache-2.0

//go:build windows

package process

import (
	"fmt"
	"os"
)

// KillProcess kills a process by its ID on Windows
func KillProcess(pid int) error {
	if pid <= 0 {
		return fmt.Errorf("invalid PID: %d", pid)
	}

	// Check if the process exists
	process, err := os.FindProcess(pid)
	if err != nil {
		return fmt.Errorf("failed to find process: %w", err)
	}

	// On Windows, os.Process.Kill() calls TerminateProcess with exit code 1
	if err := process.Kill(); err != nil {
		return fmt.Errorf("failed to terminate process: %w", err)
	}

	return nil
}
