package utils

import (
	"os"

	"github.com/flowy-live/llink/internal/utils/flog"
)

// EnvVar enumerates the env vars referenced via this package.
type EnvVar string

const ()

// MustGetEnv panics if the variable is unset.
func MustGetEnv[T string | EnvVar](key T) string {
	keyString := string(key)
	value := os.Getenv(keyString)
	if value == "" {
		flog.Error("missing required environment variable", "key", key)
		panic("Missing required environment variable")
	}

	return value
}

// GetEnv returns "" if the variable is unset (and logs a warning).
func GetEnv(key string) string {
	value := os.Getenv(key)
	if value == "" {
		flog.Warn("missing optional environment variable", "key", key)
	}
	return value
}
