package config

import (
	"os"

	"github.com/joho/godotenv"
	"github.com/labstack/gommon/log"
)

type Config map[string]string

var DefaultConfig = Config{
	"PORT":  "8000",
	"DEBUG": "false",
}

func NewConfig() func(string) string {
	_ = godotenv.Load()
	log.Info("loaded env variables")

	return func(key string) string {
		if value := os.Getenv(key); value != "" {
			return value
		} else {
			log.Warnf("no value found for %s using defaults", key)
			return DefaultConfig[key]
		}
	}
}
