package flags

import (
	"os"
	"strings"
	"sync"
)

// Common feature flags
const (
	FeatureWebSocket    = "FEATURE_WEBSOCKET"
	FeatureDebugMode    = "FEATURE_DEBUG_MODE"
	FeatureTraceLogging = "FEATURE_TRACE_LOGGING"
)

var (
	cache   = make(map[string]bool)
	cacheMu sync.RWMutex
)

// IsEnabled checks if a feature flag is enabled via environment variable
// Returns true for "true", "1", "yes", "on" (case insensitive)
func IsEnabled(flag string) bool {
	cacheMu.RLock()
	if val, exists := cache[flag]; exists {
		cacheMu.RUnlock()
		return val
	}
	cacheMu.RUnlock()

	// Check environment
	value := strings.ToLower(os.Getenv(flag))
	enabled := value == "true" || value == "1" || value == "yes" || value == "on"

	// Cache result
	cacheMu.Lock()
	cache[flag] = enabled
	cacheMu.Unlock()

	return enabled
}

// IsDisabled checks if a feature flag is disabled
func IsDisabled(flag string) bool {
	return !IsEnabled(flag)
}

