package config

import "os"

type Config struct {
	HTTPAddr     string
	WSAddr       string
	MQTTHost     string
	MQTTUser     string
	MQTTPass     string
	MQTTClientID string
	DBPath       string
	KafkaURL     string
	RedisURL     string
}

// getEnv returns env var value or a default if not set.
func getEnv(key, def string) string {
	if v := os.Getenv(key); v != "" {
		return v
	}
	return def
}

func Load() *Config {
	return &Config{
		HTTPAddr:     getEnv("HTTP_HOST_PATH", "0.0.0.0:8080"),
		WSAddr:       getEnv("HTTPWS_HOST_PATH", "0.0.0.0:8088"),
		MQTTHost:     getEnv("MQTT_HOST", "127.0.0.1:11883"),
		MQTTUser:     getEnv("MQTT_USERNAME", "user"),
		MQTTPass:     getEnv("MQTT_PASSWORD", "pass"),
		MQTTClientID: getEnv("MQTT_CLIENT_ID", "presence-detector"),
		DBPath:       getEnv("DB_PATH", "/data/conf/presence/presence.db"),
		KafkaURL:     getEnv("KAFKA_URL", "127.0.0.1:9092"),
		RedisURL:     getEnv("REDIS_URL", "127.0.0.1:6379"),
	}
}
