package utils

import (
	"os"

	"github.com/sirupsen/logrus"
)

// 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 == "" {
		logrus.Errorf("Missing required environment variable %s", 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 == "" {
		logrus.Warnf("Missing optional environment variable %s", key)
	}
	return value
}
