package env

import (
	"os"
	"strconv"
)

// GetStringOrNull retrieves a string environment variable or returns the default value if not set
func GetString(name string, defaultValue string) string {
	value := os.Getenv(name)
	if value == "" {
		return defaultValue
	}
	return value
}

// GetIntOrNull retrieves an int environment variable or returns the default value if not set
func GetInt(name string, defaultValue int) int {
	value := os.Getenv(name)
	if value == "" {
		return defaultValue
	}
	intValue, err := strconv.Atoi(value)
	if err != nil {
		return defaultValue
	}
	return intValue
}

// GetBoolOrNull retrieves a bool environment variable or returns the default value if not set
func GetBool(name string, defaultValue bool) bool {
	value := os.Getenv(name)
	if value == "" {
		return defaultValue
	}
	boolValue, err := strconv.ParseBool(value)
	if err != nil {
		return defaultValue
	}
	return boolValue
}
