package buildinfo

import "strings"

var (
	Version = "dev"
	Commit  = "unknown"
	BuiltAt = "unknown"
)

type Info struct {
	Version string
	Commit  string
	BuiltAt string
}

func Current() Info {
	return Normalize(Version, Commit, BuiltAt)
}

func Normalize(version, commit, builtAt string) Info {
	return Info{
		Version: normalizedValue(version, "dev"),
		Commit:  normalizedValue(commit, "unknown"),
		BuiltAt: normalizedValue(builtAt, "unknown"),
	}
}

func normalizedValue(value, fallback string) string {
	if trimmed := strings.TrimSpace(value); trimmed != "" {
		return trimmed
	}
	return fallback
}
