package config

import (
	"log"
	"os"

	"github.com/joho/godotenv"
)

type Config struct {
	Port                string
	DBName              string
	DjangoBaseURL       string
	DjangoMasterUser    string
	DjangoMasterPassword string
}

var AppConfig *Config

func LoadConfig() {
	err := godotenv.Load()
	if err != nil {
		log.Println("No .env file found, using defaults")
	}

	AppConfig = &Config{
		Port:                 getEnv("PORT", "8080"),
		DBName:               getEnv("DB_NAME", "rrbec.db"),
		DjangoBaseURL:        getEnv("DJANGO_BASE_URL", ""),
		DjangoMasterUser:     getEnv("DJANGO_MASTER_USER", ""),
		DjangoMasterPassword: getEnv("DJANGO_MASTER_PASSWORD", ""),
	}
}

func getEnv(key, fallback string) string {
	if value, ok := os.LookupEnv(key); ok {
		return value
	}
	return fallback
}
