package utils

import (
	"os"

	"github.com/sirupsen/logrus"
)

// enum of environment variables
type EnvVar string

const ()

// MustGetEnv returns the value of the environment variable with the given key.
// panics if the variable is not set.
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 the value of the environment variable with the given key.
// returns an empty string if the variable is not set.
func GetEnv(key string) string {
	value := os.Getenv(key)
	if value == "" {
		logrus.Warnf("Missing optional environment variable %s", key)
	}
	return value
}
