package config

import (
	"fmt"
	"os"

	"github.com/joho/godotenv"
)

var Cfg Config

type Config struct {
	Debug               bool
	ColorizedOutput     bool
	Host                string
	Port                string
	LogManagerServerUrl string
	SSEServerEnabled    bool
	MariaDB             MariaDB
}

type MariaDB struct {
	Hostname     string
	Port         string
	Username     string
	Password     string
	DatabaseName string
}

func LoadConfig() {
	// used to determine server was startet in docker or not
	if os.Getenv("DOCKER") == "" {
		fmt.Println("Load env from file")
		godotenv.Load(".env")
	} else {
		fmt.Println("Load env from system")
	}

	Cfg = Config{
		Debug:               os.Getenv("DEBUG") == "true",
		ColorizedOutput:     os.Getenv("COLORIZED_OUTPUT") == "true",
		Host:                os.Getenv("HOST"),
		Port:                os.Getenv("PORT"),
		LogManagerServerUrl: os.Getenv("LOG_MANAGER_SERVER_URL"),
		SSEServerEnabled:    os.Getenv("SSE_SERVER_ENABLED") == "true",
		MariaDB: MariaDB{
			Hostname:     os.Getenv("MARIADB_HOSTNAME"),
			Port:         os.Getenv("MARIADB_PORT"),
			Username:     os.Getenv("MARIADB_USERNAME"),
			Password:     os.Getenv("MARIADB_PASSWORD"),
			DatabaseName: os.Getenv("MARIADB_DATABASE_NAME"),
		},
	}
}
