package version

import (
	"fmt"
	"runtime"
)

// Version information
var (
	// GitVersion is the git tag version
	GitVersion = "dev"
	// BuildMetadata is extra build time data
	BuildMetadata = ""
	// GitCommit is the git sha1
	GitCommit = ""
	// GitTreeState describes the state of the git tree
	GitTreeState = ""
)

// GetVersion returns the version string
func GetVersion() string {
	var version string
	if BuildMetadata != "" {
		version = fmt.Sprintf("%s+%s", GitVersion, BuildMetadata)
	} else {
		version = GitVersion
	}
	return version
}

// GetUserAgent returns the user agent string
func GetUserAgent() string {
	return fmt.Sprintf("mcp-kubernetes/%s (%s/%s)",
		GetVersion(),
		runtime.GOOS,
		runtime.GOARCH,
	)
}

// GetVersionInfo returns a map with all version information
func GetVersionInfo() map[string]string {
	return map[string]string{
		"version":      GetVersion(),
		"gitCommit":    GitCommit,
		"gitTreeState": GitTreeState,
		"goVersion":    runtime.Version(),
		"platform":     fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
	}
}

// PrintVersion prints version information in a human-readable format
func PrintVersion() {
	fmt.Printf("mcp-kubernetes version %s\n", GetVersion())
	fmt.Printf("Git commit: %s\n", GitCommit)
	fmt.Printf("Git tree state: %s\n", GitTreeState)
	fmt.Printf("Go version: %s\n", runtime.Version())
	fmt.Printf("Platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
}
