package config

import (
	"os"
)

type Config struct {
	Env            string
	Port           string
	DBName         string
	DBUser         string
	DBPassword     string
	DBPort         string
	DBHost         string
	RedisHost      string
	RedisPort      string
	RedisUser      string
	RedisPassword  string
	JWTSecret      string
	NatsURL        string
	NatsUser       string
	NatsPassword   string
	AILayerBaseURL string // AI decision-engine service base URL (e.g. http://rider-api:8082)
	SMTPHost       string
	SMTPPort       string
	SMTPUser       string
	SMTPPassword   string
	SMTPFrom       string
}

func Load() *Config {
	return &Config{
		Env:            getEnv("ENV", "development"),
		Port:           getEnv("APP_PORT", "8081"),
		DBName:         getEnv("DB_NAME", "logistics"),
		DBUser:         getEnv("DB_USER", "admin"),
		DBPassword:     getEnv("DB_PASSWORD", "Package@321#"),
		DBPort:         getEnv("DB_PORT", "5433"),
		DBHost:         getEnv("DB_HOST", "127.0.0.1"),
		RedisHost:      getEnv("REDIS_HOST", "127.0.0.1"),
		RedisPort:      getEnv("REDIS_PORT", "6379"),
		RedisUser:      getEnv("REDIS_USER", ""),
		RedisPassword:  getEnv("REDIS_PASSWORD", ""),
		JWTSecret:      getEnv("JWT_SECRET_KEY", "DoormileSuperSecretJWTKey2026!"),
		NatsURL:        getEnv("NATS_URL", "nats://66.116.226.161:4223"),
		NatsUser:       getEnv("NATS_USER", "doormile"),
		NatsPassword:   getEnv("NATS_PASSWORD", "Package@321#"),
		AILayerBaseURL: getEnv("AI_LAYER_BASE_URL", "https://routemate.workolik.com"),
		SMTPHost:       getEnv("SMTP_HOST", ""),
		SMTPPort:       getEnv("SMTP_PORT", "465"),
		SMTPUser:       getEnv("SMTP_USER", ""),
		SMTPPassword:   getEnv("SMTP_PASSWORD", ""),
		SMTPFrom:       getEnv("SMTP_FROM", ""),
	}
}

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