package config

import (
	"fmt"
	"os"

	"github.com/joho/godotenv"
)

var Cfg Config

type Config struct {
	Debug                 bool
	ColorizedOutput       bool
	Host                  string
	Port                  string
	FolderPaths           FolderPaths
	MariaDB               MariaDB
	LogLanguageGroupTasks string
	LogLanguageSystem     string
}

type FolderPaths struct {
	GroupTasksGroups       string
	GroupTasksRunningTasks string
	LogsGroupTasks         string
	LogsSystem             string
	PublicStatic           string
}

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"),
		FolderPaths: FolderPaths{
			GroupTasksGroups:       os.Getenv("FOLDER_GROUPTASKS_GROUPS"),
			GroupTasksRunningTasks: os.Getenv("FOLDER_GROUPTASKS_RUNNINGTASKS"),
			LogsGroupTasks:         os.Getenv("FOLDER_LOGS_GROUPTASKS"),
			LogsSystem:             os.Getenv("FOLDER_LOGS_SYSTEM"),
			PublicStatic:           os.Getenv("FOLDER_PUBLIC_STATIC"),
		},
		LogLanguageGroupTasks: os.Getenv("LOG_LANGUAGE_GROUPTASKS"),
		LogLanguageSystem:     os.Getenv("LOG_LANGUAGE_SYSTEM"),
		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")},
	}
}
