package main

import (
	"fmt"
	"os/exec"
	"runtime"
	"strings"
)

func main() {
	fmt.Println("Checking Go environment...")
	fmt.Println()

	// Check Go version
	cmd := exec.Command("go", "version")
	output, err := cmd.Output()
	if err != nil {
		fmt.Println("❌ Go is not installed or not in PATH")
		fmt.Println("   Please install Go from https://go.dev/dl/")
		return
	}
	fmt.Printf("✓ Go version: %s", output)

	// Display runtime information
	fmt.Printf("✓ OS/Arch: %s/%s\n", runtime.GOOS, runtime.GOARCH)

	// Check if go modules work
	cmd = exec.Command("go", "env", "GOVERSION")
	output, err = cmd.Output()
	if err != nil {
		fmt.Println("❌ Unable to query Go environment")
		return
	}
	version := strings.TrimSpace(string(output))
	fmt.Printf("✓ GOVERSION: %s\n", version)

	// Check GOPATH/bin for installed tools
	cmd = exec.Command("go", "env", "GOPATH")
	output, err = cmd.Output()
	if err == nil {
		gopath := strings.TrimSpace(string(output))
		if gopath != "" {
			fmt.Printf("✓ GOPATH: %s\n", gopath)
			fmt.Printf("  (Tools installed via 'go install' go to %s/bin)\n", gopath)
		}
	}

	fmt.Println()
	fmt.Println("✓ Success! Your Go environment is ready.")
}
