package config

import (
	"os"
)

type Config struct {
	ServerAddr       string
	DatabaseURL      string
	OIDCIssuerURL    string
	OIDCRedirectURL  string
	OIDCClientID     string
	OIDCClientSecret string
	JWTSecret        string
}

func Load() *Config {
	return &Config{
		ServerAddr:       getEnv("SERVER_ADDR", ":8080"),
		DatabaseURL:      os.Getenv("DATABASE_URL"),
		OIDCIssuerURL:    os.Getenv("OIDC_ISSUER_URL"),
		OIDCRedirectURL:  os.Getenv("OIDC_REDIRECT_URL"),
		OIDCClientID:     os.Getenv("OIDC_CLIENT_ID"),
		OIDCClientSecret: os.Getenv("OIDC_CLIENT_SECRET"),
		JWTSecret:        os.Getenv("JWT_SECRET"),
	}
}

func getEnv(key, defaultVal string) string {
	if val := os.Getenv(key); val != "" {
		return val
	}
	return defaultVal
}
