package config

import "os"

type Config struct {
	Port           string // SUPERVISOR_PORT, default 3200
	LiteLLMBaseURL string // LITELLM_BASE_URL, default http://iguana:4000
	LiteLLMAPIKey  string // LITELLM_API_KEY
	ConfigDir      string // SUPERVISOR_CONFIG_DIR, default ./config/supervisor
	ModelsFile     string // SUPERVISOR_MODELS_FILE, default <ConfigDir>/../models.yaml
}

func Load() (Config, error) {
	cfg := Config{
		Port:           envOr("SUPERVISOR_PORT", "3200"),
		LiteLLMBaseURL: envOr("LITELLM_BASE_URL", "http://iguana:4000"),
		LiteLLMAPIKey:  os.Getenv("LITELLM_API_KEY"),
		ConfigDir:      envOr("SUPERVISOR_CONFIG_DIR", "./config/supervisor"),
	}
	cfg.ModelsFile = envOr("SUPERVISOR_MODELS_FILE", cfg.ConfigDir+"/../models.yaml")
	return cfg, nil
}

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