package config

import (
	"fmt"
	"os"
)

// Config carries runtime configuration for the HTTP server.
type Config struct {
	Host         string
	Port         string
	ProviderKind string
}

// Load reads configuration from environment variables with sensible defaults.
func Load() Config {
	cfg := Config{
		Host:         getenv("ALLAI_HTTP_HOST", "0.0.0.0"),
		Port:         getenv("ALLAI_HTTP_PORT", "8080"),
		ProviderKind: getenv("ALLAI_PROVIDER", "mock"),
	}

	return cfg
}

// Address returns the host:port string used by net/http.
func (c Config) Address() string {
	return fmt.Sprintf("%s:%s", c.Host, c.Port)
}

func getenv(key, fallback string) string {
	if value, ok := os.LookupEnv(key); ok && value != "" {
		return value
	}
	return fallback
}
