// Package buildinfo names the running gateway build.
//
// Every log line, the health endpoint and the admin page carry it, because the first
// question about any reported behaviour is "which server is that?" — and the gateway is
// deployed from a working tree rather than a tagged artefact, so nothing else can answer.
package buildinfo

import (
	_ "embed"
	"os"
	"strings"
)

// version is the checked-in release name. It travels with the source that is deployed,
// so a container built from a tree always reports that tree's version — no build
// argument to remember and no way for the number to be right on one host and wrong on
// another.
//
//go:embed VERSION
var version string

// Version returns the running build's version. MEMBY_SERVER_VERSION overrides it, which
// is how a one-off build ("0.1.0+hotfix") can identify itself without editing the file.
func Version() string {
	if override := strings.TrimSpace(os.Getenv("MEMBY_SERVER_VERSION")); override != "" {
		return override
	}
	if trimmed := strings.TrimSpace(version); trimmed != "" {
		return trimmed
	}
	return "unknown"
}
