package config

import "os"

type Config struct {
	HTTPAddress     string
	StatusStorePath string
	DatabaseURL     string
	UploadDir       string
}

func Load() Config {
	return Config{
		HTTPAddress:     getenv("MORZ_INFOBOARD_HTTP_ADDR", ":8080"),
		StatusStorePath: os.Getenv("MORZ_INFOBOARD_STATUS_STORE_PATH"),
		DatabaseURL:     getenv("MORZ_INFOBOARD_DATABASE_URL", "postgres://morz_infoboard:morz_infoboard@localhost:5432/morz_infoboard?sslmode=disable"),
		UploadDir:       getenv("MORZ_INFOBOARD_UPLOAD_DIR", "/tmp/morz-uploads"),
	}
}

func getenv(key, fallback string) string {
	value := os.Getenv(key)
	if value == "" {
		return fallback
	}

	return value
}
