package config

import "os"

type Config struct {
	UDPAddr       string
	DBPath        string
	HTTPAddr      string
	MQTTBroker    string
	MQTTTopicBase string
	DashboardDir  string // optionnel : sert le dashboard en dev sans Nginx
}

func Load() Config {
	return Config{
		UDPAddr:       getEnv("UDP_ADDR", "0.0.0.0:9999"),
		DBPath:        getEnv("DB_PATH", "/data/nanometrics.db"),
		HTTPAddr:      getEnv("HTTP_ADDR", "0.0.0.0:8080"),
		MQTTBroker:    getEnv("MQTT_BROKER", "tcp://10.0.0.3:1883"),
		MQTTTopicBase: getEnv("MQTT_TOPIC_BASE", "nanometrics/agents"),
		DashboardDir:  getEnv("DASHBOARD_DIR", ""),
	}
}

func getEnv(key, fallback string) string {
	if v := os.Getenv(key); v != "" {
		return v
	}
	return fallback
}

func Default() Config {
	return Config{
		UDPAddr:       "127.0.0.1:19999",
		DBPath:        ":memory:",
		HTTPAddr:      "127.0.0.1:18080",
		MQTTBroker:    "tcp://127.0.0.1:11883",
		MQTTTopicBase: "test/nanometrics",
	}
}
