package infra

import (
	"fmt"
	"os"
	"strings"
)

// EnvRequireAll returns a map of all requested environment variables.
// All keys are checked even if some are missing. If any variable is unset or
// empty, a single error listing all missing variables is returned.
// On success, the returned map contains every key with its current value.
func EnvRequireAll(keys []string) (map[string]string, error) {
	result := make(map[string]string, len(keys))
	var missing []string

	for _, key := range keys {
		val := os.Getenv(key)
		if val == "" {
			missing = append(missing, key)
		} else {
			result[key] = val
		}
	}

	if len(missing) > 0 {
		return nil, fmt.Errorf("env_require_all: missing environment variables: %s", strings.Join(missing, ", "))
	}

	return result, nil
}
